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

Function TestTemplateVersionLogsFormat

coderd/templateversions_test.go:1156–1251  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1154}
1155
1156func TestTemplateVersionLogsFormat(t *testing.T) {
1157 t.Parallel()
1158
1159 // Setup: Create template version with logs using dbfake.
1160 client, db := coderdtest.NewWithDatabase(t, nil)
1161 user := coderdtest.CreateFirstUser(t, client)
1162
1163 tv := dbfake.TemplateVersion(t, db).
1164 Seed(database.TemplateVersion{
1165 OrganizationID: user.OrganizationID,
1166 CreatedBy: user.UserID,
1167 }).
1168 Do()
1169
1170 // Insert test log directly into database.
1171 jl := dbgen.ProvisionerJobLog(t, db, database.ProvisionerJobLog{
1172 JobID: tv.TemplateVersion.JobID,
1173 Stage: "Planning",
1174 Source: database.LogSourceProvisioner,
1175 Level: database.LogLevelInfo,
1176 Output: "test log output",
1177 })
1178
1179 tests := []struct {
1180 name string
1181 queryParams string
1182 expectedStatus int
1183 expectedContentType string
1184 checkBody func(t *testing.T, body string)
1185 }{
1186 {
1187 name: "JSON",
1188 queryParams: "",
1189 expectedStatus: http.StatusOK,
1190 expectedContentType: "application/json",
1191 checkBody: func(t *testing.T, body string) {
1192 assert.NotEmpty(t, body) // This is checked more thoroughly in TestTemplateVersionLogs above.
1193 },
1194 },
1195 {
1196 name: "Text",
1197 queryParams: "?format=text",
1198 expectedStatus: http.StatusOK,
1199 expectedContentType: "text/plain",
1200 checkBody: func(t *testing.T, body string) {
1201 expected := db2sdk.ProvisionerJobLog(jl).Text()
1202 assert.Contains(t, body, expected)
1203 },
1204 },
1205 {
1206 name: "InvalidFormat",
1207 queryParams: "?format=invalid",
1208 expectedStatus: http.StatusBadRequest,
1209 checkBody: func(t *testing.T, body string) {
1210 t.Log(body)
1211 var sdkErr codersdk.Error
1212 assert.NoError(t, json.NewDecoder(strings.NewReader(body)).Decode(&sdkErr))
1213 assert.Equal(t, "Invalid format parameter.", sdkErr.Message)

Callers

nothing calls this directly

Calls 15

NewWithDatabaseFunction · 0.92
CreateFirstUserFunction · 0.92
TemplateVersionFunction · 0.92
ProvisionerJobLogFunction · 0.92
ProvisionerJobLogFunction · 0.92
ContextFunction · 0.92
NotEmptyMethod · 0.80
LogMethod · 0.80
DoMethod · 0.65
RunMethod · 0.65
CloseMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected