(t *testing.T)
| 1095 | } |
| 1096 | |
| 1097 | func TestWorkspaceBuildLogsFormat(t *testing.T) { |
| 1098 | t.Parallel() |
| 1099 | |
| 1100 | // Setup: Create workspace build with logs using dbfake. |
| 1101 | client, db := coderdtest.NewWithDatabase(t, nil) |
| 1102 | user := coderdtest.CreateFirstUser(t, client) |
| 1103 | |
| 1104 | r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{ |
| 1105 | OrganizationID: user.OrganizationID, |
| 1106 | OwnerID: user.UserID, |
| 1107 | }).Do() |
| 1108 | |
| 1109 | // Insert test log directly into database. |
| 1110 | jl := dbgen.ProvisionerJobLog(t, db, database.ProvisionerJobLog{ |
| 1111 | JobID: r.Build.JobID, |
| 1112 | Stage: "Planning", |
| 1113 | Source: database.LogSourceProvisioner, |
| 1114 | Level: database.LogLevelInfo, |
| 1115 | Output: "test log output", |
| 1116 | }) |
| 1117 | |
| 1118 | tests := []struct { |
| 1119 | name string |
| 1120 | queryParams string |
| 1121 | expectedStatus int |
| 1122 | expectedContentType string |
| 1123 | checkBody func(t *testing.T, body string) |
| 1124 | }{ |
| 1125 | { |
| 1126 | name: "JSON", |
| 1127 | queryParams: "", |
| 1128 | expectedStatus: http.StatusOK, |
| 1129 | expectedContentType: "application/json", |
| 1130 | checkBody: func(t *testing.T, body string) { |
| 1131 | require.NotEmpty(t, body) |
| 1132 | }, |
| 1133 | }, |
| 1134 | { |
| 1135 | name: "Text", |
| 1136 | queryParams: "?format=text", |
| 1137 | expectedStatus: http.StatusOK, |
| 1138 | expectedContentType: "text/plain", |
| 1139 | checkBody: func(t *testing.T, body string) { |
| 1140 | expected := db2sdk.ProvisionerJobLog(jl).Text() |
| 1141 | require.Contains(t, body, expected) |
| 1142 | }, |
| 1143 | }, |
| 1144 | { |
| 1145 | name: "InvalidFormat", |
| 1146 | queryParams: "?format=invalid", |
| 1147 | expectedStatus: http.StatusBadRequest, |
| 1148 | checkBody: func(t *testing.T, body string) { |
| 1149 | require.Contains(t, body, "Invalid format") |
| 1150 | }, |
| 1151 | }, |
| 1152 | { |
| 1153 | name: "TextWithFollowFails", |
| 1154 | queryParams: "?format=text&follow", |
nothing calls this directly
no test coverage detected