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

Function TestBuilder

cli/clilog/clilog_test.go:19–147  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestBuilder(t *testing.T) {
20 t.Parallel()
21
22 t.Run("NoConfiguration", func(t *testing.T) {
23 t.Parallel()
24
25 cmd := &serpent.Command{
26 Use: "test",
27 Handler: testHandler(t),
28 }
29 err := cmd.Invoke().Run()
30 require.ErrorContains(t, err, "no loggers provided, use /dev/null to disable logging")
31 })
32
33 t.Run("Verbose", func(t *testing.T) {
34 t.Parallel()
35
36 tempFile := filepath.Join(t.TempDir(), "test.log")
37 cmd := &serpent.Command{
38 Use: "test",
39 Handler: testHandler(t,
40 clilog.WithHuman(tempFile),
41 clilog.WithVerbose(),
42 ),
43 }
44 err := cmd.Invoke().Run()
45 require.NoError(t, err)
46 assertLogs(t, tempFile, debugLog, infoLog, warnLog, filterLog)
47 })
48
49 t.Run("WithFilter", func(t *testing.T) {
50 t.Parallel()
51
52 tempFile := filepath.Join(t.TempDir(), "test.log")
53 cmd := &serpent.Command{
54 Use: "test",
55 Handler: testHandler(t,
56 clilog.WithHuman(tempFile),
57 // clilog.WithVerbose(), // implicit
58 clilog.WithFilter("important debug message"),
59 ),
60 }
61 err := cmd.Invoke().Run()
62 require.NoError(t, err)
63 assertLogs(t, tempFile, infoLog, warnLog, filterLog)
64 })
65
66 t.Run("WithHuman", func(t *testing.T) {
67 t.Parallel()
68
69 tempFile := filepath.Join(t.TempDir(), "test.log")
70 cmd := &serpent.Command{
71 Use: "test",
72 Handler: testHandler(t, clilog.WithHuman(tempFile)),
73 }
74 err := cmd.Invoke().Run()
75 require.NoError(t, err)
76 assertLogs(t, tempFile, infoLog, warnLog)

Callers

nothing calls this directly

Calls 15

WithHumanFunction · 0.92
WithVerboseFunction · 0.92
WithFilterFunction · 0.92
WithJSONFunction · 0.92
DeploymentValuesFunction · 0.92
FromDeploymentValuesFunction · 0.92
testHandlerFunction · 0.85
assertLogsFunction · 0.85
assertLogsJSONFunction · 0.85
RunMethod · 0.65
TempDirMethod · 0.65
CleanupMethod · 0.65

Tested by

no test coverage detected