MCPcopy Index your code
hub / github.com/coder/coder / TestLicensesAddFake

Function TestLicensesAddFake

enterprise/cli/licenses_test.go:33–114  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

31)
32
33func TestLicensesAddFake(t *testing.T) {
34 t.Parallel()
35 // We can't check a real license into the git repo, and can't patch out the keys from here,
36 // so instead we have to fake the HTTP interaction.
37 t.Run("LFlag", func(t *testing.T) {
38 t.Parallel()
39 inv := setupFakeLicenseServerTest(t, "licenses", "add", "-l", fakeLicenseJWT)
40 pty := attachPty(t, inv)
41 clitest.Start(t, inv)
42 pty.ExpectMatch("License with ID 1 added")
43 })
44 t.Run("Prompt", func(t *testing.T) {
45 t.Parallel()
46 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
47 defer cancel()
48 inv := setupFakeLicenseServerTest(t, "license", "add")
49 pty := attachPty(t, inv)
50 errC := make(chan error)
51 go func() {
52 errC <- inv.WithContext(ctx).Run()
53 }()
54 pty.ExpectMatch("Paste license:")
55 pty.WriteLine(fakeLicenseJWT)
56 require.NoError(t, <-errC)
57 pty.ExpectMatch("License with ID 1 added")
58 })
59 t.Run("File", func(t *testing.T) {
60 t.Parallel()
61 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
62 defer cancel()
63 dir := t.TempDir()
64 filename := filepath.Join(dir, "license.jwt")
65 err := os.WriteFile(filename, []byte(fakeLicenseJWT), 0o600)
66 require.NoError(t, err)
67 inv := setupFakeLicenseServerTest(t, "license", "add", "-f", filename)
68 pty := attachPty(t, inv)
69 errC := make(chan error)
70 go func() {
71 errC <- inv.WithContext(ctx).Run()
72 }()
73 require.NoError(t, <-errC)
74 pty.ExpectMatch("License with ID 1 added")
75 })
76 t.Run("StdIn", func(t *testing.T) {
77 t.Parallel()
78 inv := setupFakeLicenseServerTest(t, "license", "add", "-f", "-")
79 r, w := io.Pipe()
80 inv.Stdin = r
81 stdout := new(bytes.Buffer)
82 inv.Stdout = stdout
83 errC := make(chan error)
84 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
85 defer cancel()
86 go func() {
87 errC <- inv.WithContext(ctx).Run()
88 }()
89 _, err := w.Write([]byte(fakeLicenseJWT))
90 require.NoError(t, err)

Callers

nothing calls this directly

Calls 15

StartFunction · 0.92
attachPtyFunction · 0.85
WithContextMethod · 0.80
WriteLineMethod · 0.80
RunMethod · 0.65
TempDirMethod · 0.65
WriteFileMethod · 0.65
WriteMethod · 0.65
CloseMethod · 0.65
ExpectMatchMethod · 0.45
DoneMethod · 0.45

Tested by

no test coverage detected