(t *testing.T)
| 520 | } |
| 521 | |
| 522 | func TestSessionWaitStreamsUntilStopped(t *testing.T) { |
| 523 | t.Parallel() |
| 524 | |
| 525 | getCalls := 0 |
| 526 | deps := newTestDeps(t, &stubClient{ |
| 527 | getSessionFn: func(context.Context, string) (SessionRecord, error) { |
| 528 | getCalls++ |
| 529 | state := session.StateActive |
| 530 | if getCalls > 1 { |
| 531 | state = session.StateStopped |
| 532 | } |
| 533 | return SessionRecord{ |
| 534 | ID: "sess-1", |
| 535 | AgentName: "coder", |
| 536 | WorkspaceID: "ws-1", |
| 537 | WorkspacePath: "/workspace/project", |
| 538 | State: state, |
| 539 | CreatedAt: fixedTestNow, |
| 540 | UpdatedAt: fixedTestNow, |
| 541 | }, nil |
| 542 | }, |
| 543 | streamSessionFn: func(_ context.Context, id string, _ SessionEventQuery, _ string, handler SSEHandler) error { |
| 544 | return handler(SSEEvent{ |
| 545 | ID: "2", |
| 546 | Event: session.EventTypeSessionStopped, |
| 547 | Data: mustJSON(t, SessionEventRecord{ |
| 548 | ID: "evt-2", |
| 549 | SessionID: id, |
| 550 | Sequence: 2, |
| 551 | Type: session.EventTypeSessionStopped, |
| 552 | AgentName: "coder", |
| 553 | Timestamp: fixedTestNow, |
| 554 | }), |
| 555 | }) |
| 556 | }, |
| 557 | }) |
| 558 | |
| 559 | stdout, _, err := executeRootCommand(t, deps, "session", "wait", "sess-1", "-o", "json") |
| 560 | if err != nil { |
| 561 | t.Fatalf("executeRootCommand() error = %v", err) |
| 562 | } |
| 563 | if getCalls != 2 { |
| 564 | t.Fatalf("GetSession() calls = %d, want 2", getCalls) |
| 565 | } |
| 566 | |
| 567 | var decoded SessionRecord |
| 568 | if err := json.Unmarshal([]byte(stdout), &decoded); err != nil { |
| 569 | t.Fatalf("json.Unmarshal() error = %v", err) |
| 570 | } |
| 571 | if decoded.State != session.StateStopped { |
| 572 | t.Fatalf("decoded.State = %q, want %q", decoded.State, session.StateStopped) |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | func TestSessionStopFetchesUpdatedSession(t *testing.T) { |
| 577 | t.Parallel() |
nothing calls this directly
no test coverage detected