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

Function Test_TaskLogs_Golden

cli/task_logs_test.go:22–279  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

20)
21
22func Test_TaskLogs_Golden(t *testing.T) {
23 t.Parallel()
24
25 testMessages := []agentapisdk.Message{
26 {
27 Id: 0,
28 Role: agentapisdk.RoleUser,
29 Content: "What is 1 + 1?",
30 Time: time.Now().Add(-2 * time.Minute),
31 },
32 {
33 Id: 1,
34 Role: agentapisdk.RoleAgent,
35 Content: "2",
36 Time: time.Now().Add(-1 * time.Minute),
37 },
38 }
39
40 t.Run("ByTaskName_JSON", func(t *testing.T) {
41 t.Parallel()
42
43 setupCtx := testutil.Context(t, testutil.WaitLong)
44 setup := setupCLITaskTest(setupCtx, t, fakeAgentAPITaskLogsOK(testMessages))
45
46 inv, root := clitest.New(t, "task", "logs", setup.task.Name, "--output", "json")
47 output := clitest.Capture(inv)
48 clitest.SetupConfig(t, setup.userClient, root)
49
50 ctx := testutil.Context(t, testutil.WaitLong)
51 err := inv.WithContext(ctx).Run()
52 require.NoError(t, err)
53
54 // Verify JSON is valid.
55 var logs []codersdk.TaskLogEntry
56 err = json.NewDecoder(strings.NewReader(output.Stdout())).Decode(&logs)
57 require.NoError(t, err)
58
59 // Verify output format with golden file.
60 clitest.TestGoldenFile(t, t.Name(), output.Golden(), nil)
61 })
62
63 t.Run("ByTaskID_JSON", func(t *testing.T) {
64 t.Parallel()
65
66 setupCtx := testutil.Context(t, testutil.WaitLong)
67 setup := setupCLITaskTest(setupCtx, t, fakeAgentAPITaskLogsOK(testMessages))
68
69 inv, root := clitest.New(t, "task", "logs", setup.task.ID.String(), "--output", "json")
70 output := clitest.Capture(inv)
71 clitest.SetupConfig(t, setup.userClient, root)
72
73 ctx := testutil.Context(t, testutil.WaitLong)
74 err := inv.WithContext(ctx).Run()
75 require.NoError(t, err)
76
77 // Verify JSON is valid.
78 var logs []codersdk.TaskLogEntry
79 err = json.NewDecoder(strings.NewReader(output.Stdout())).Decode(&logs)

Callers

nothing calls this directly

Calls 15

ContextFunction · 0.92
NewFunction · 0.92
CaptureFunction · 0.92
SetupConfigFunction · 0.92
TestGoldenFileFunction · 0.92
NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
setupCLITaskTestFunction · 0.85
fakeAgentAPITaskLogsOKFunction · 0.85
fakeAgentAPITaskLogsErrFunction · 0.85

Tested by

no test coverage detected