(t *testing.T)
| 385 | } |
| 386 | |
| 387 | func TestWorkspaceAgentLogsFormat(t *testing.T) { |
| 388 | t.Parallel() |
| 389 | client, db := coderdtest.NewWithDatabase(t, nil) |
| 390 | user := coderdtest.CreateFirstUser(t, client) |
| 391 | |
| 392 | r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{ |
| 393 | OrganizationID: user.OrganizationID, |
| 394 | OwnerID: user.UserID, |
| 395 | }).WithAgent().Do() |
| 396 | |
| 397 | workspaceAgent := r.Agents[0] |
| 398 | logSource := dbgen.WorkspaceAgentLogSource(t, db, database.WorkspaceAgentLogSource{ |
| 399 | WorkspaceAgentID: workspaceAgent.ID, |
| 400 | DisplayName: "startup_script", |
| 401 | }) |
| 402 | agentLog := dbgen.WorkspaceAgentLog(t, db, database.WorkspaceAgentLog{ |
| 403 | AgentID: workspaceAgent.ID, |
| 404 | LogSourceID: logSource.ID, |
| 405 | Output: "test log output", |
| 406 | Level: database.LogLevelInfo, |
| 407 | }) |
| 408 | |
| 409 | tests := []struct { |
| 410 | name string |
| 411 | queryParams string |
| 412 | expectedStatus int |
| 413 | expectedContentType string |
| 414 | checkBody func(string) |
| 415 | }{ |
| 416 | { |
| 417 | name: "JSON", |
| 418 | queryParams: "", |
| 419 | expectedStatus: http.StatusOK, |
| 420 | expectedContentType: "application/json", |
| 421 | checkBody: func(body string) { |
| 422 | assert.NotEmpty(t, body) |
| 423 | }, |
| 424 | }, |
| 425 | { |
| 426 | name: "Text", |
| 427 | queryParams: "?format=text", |
| 428 | expectedStatus: http.StatusOK, |
| 429 | expectedContentType: "text/plain", |
| 430 | checkBody: func(body string) { |
| 431 | expected := db2sdk.WorkspaceAgentLog(agentLog).Text(workspaceAgent.Name, logSource.DisplayName) |
| 432 | assert.Contains(t, body, expected) |
| 433 | }, |
| 434 | }, |
| 435 | { |
| 436 | name: "InvalidFormat", |
| 437 | queryParams: "?format=invalid", |
| 438 | expectedStatus: http.StatusBadRequest, |
| 439 | checkBody: func(body string) { |
| 440 | assert.Contains(t, body, "Invalid format") |
| 441 | }, |
| 442 | }, |
| 443 | { |
| 444 | name: "TextWithFollowFails", |
nothing calls this directly
no test coverage detected