(t *testing.T)
| 38 | } |
| 39 | |
| 40 | func TestJSONOutputProducesValidJSON(t *testing.T) { |
| 41 | t.Parallel() |
| 42 | |
| 43 | t.Run("Should produce valid JSON", func(t *testing.T) { |
| 44 | t.Parallel() |
| 45 | |
| 46 | deps := newTestDeps(t, &stubClient{ |
| 47 | listSessionsFn: func(_ context.Context, _ SessionListQuery) ([]SessionRecord, error) { |
| 48 | return []SessionRecord{{ |
| 49 | ID: "sess-1", |
| 50 | Name: "demo", |
| 51 | AgentName: "coder", |
| 52 | WorkspaceID: "ws-1", |
| 53 | WorkspacePath: "/workspace/project", |
| 54 | State: "active", |
| 55 | CreatedAt: fixedTestNow.Add(-time.Minute), |
| 56 | UpdatedAt: fixedTestNow, |
| 57 | }}, nil |
| 58 | }, |
| 59 | }) |
| 60 | |
| 61 | stdout, _, err := executeRootCommand(t, deps, "session", "list", "-o", "json") |
| 62 | if err != nil { |
| 63 | t.Fatalf("executeRootCommand() error = %v", err) |
| 64 | } |
| 65 | |
| 66 | var decoded []SessionRecord |
| 67 | if err := json.Unmarshal([]byte(stdout), &decoded); err != nil { |
| 68 | t.Fatalf("json.Unmarshal() error = %v", err) |
| 69 | } |
| 70 | if len(decoded) != 1 || decoded[0].ID != "sess-1" { |
| 71 | t.Fatalf("decoded = %#v, want one session", decoded) |
| 72 | } |
| 73 | }) |
| 74 | } |
| 75 | |
| 76 | func TestToonOutputProducesToonDocument(t *testing.T) { |
| 77 | t.Parallel() |
nothing calls this directly
no test coverage detected