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

Function TestWorkspaceAgentLogsFormat

coderd/workspaceagents_test.go:387–476  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

385}
386
387func 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",

Callers

nothing calls this directly

Calls 15

NewWithDatabaseFunction · 0.92
CreateFirstUserFunction · 0.92
WorkspaceBuildFunction · 0.92
WorkspaceAgentLogSourceFunction · 0.92
WorkspaceAgentLogFunction · 0.92
WorkspaceAgentLogFunction · 0.92
ContextFunction · 0.92
WithAgentMethod · 0.80
NotEmptyMethod · 0.80
DoMethod · 0.65
RunMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected