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

Function TestFailJob

coderd/provisionerdserver/provisionerdserver_test.go:1288–1506  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1286}
1287
1288func TestFailJob(t *testing.T) {
1289 t.Parallel()
1290 ctx := context.Background()
1291 t.Run("NotFound", func(t *testing.T) {
1292 t.Parallel()
1293 srv, _, _, _ := setup(t, false, nil)
1294 _, err := srv.FailJob(ctx, &proto.FailedJob{
1295 JobId: "hello",
1296 })
1297 require.ErrorContains(t, err, "invalid UUID")
1298
1299 _, err = srv.UpdateJob(ctx, &proto.UpdateJobRequest{
1300 JobId: uuid.NewString(),
1301 })
1302 require.ErrorContains(t, err, "no rows in result set")
1303 })
1304 // This test prevents runners from updating jobs they don't own!
1305 t.Run("NotOwner", func(t *testing.T) {
1306 t.Parallel()
1307 srv, db, _, pd := setup(t, false, nil)
1308 user := dbgen.User(t, db, database.User{})
1309 version := dbgen.TemplateVersion(t, db, database.TemplateVersion{
1310 CreatedBy: user.ID,
1311 OrganizationID: pd.OrganizationID,
1312 JobID: uuid.New(),
1313 })
1314 job, err := db.InsertProvisionerJob(ctx, database.InsertProvisionerJobParams{
1315 ID: version.JobID,
1316 Provisioner: database.ProvisionerTypeEcho,
1317 StorageMethod: database.ProvisionerStorageMethodFile,
1318 Type: database.ProvisionerJobTypeTemplateVersionImport,
1319 Input: must(json.Marshal(provisionerdserver.TemplateVersionImportJob{
1320 TemplateVersionID: version.ID,
1321 })),
1322 OrganizationID: pd.OrganizationID,
1323 Tags: pd.Tags,
1324 })
1325 require.NoError(t, err)
1326 _, err = db.AcquireProvisionerJob(ctx, database.AcquireProvisionerJobParams{
1327 WorkerID: uuid.NullUUID{
1328 UUID: uuid.New(),
1329 Valid: true,
1330 },
1331 Types: []database.ProvisionerType{database.ProvisionerTypeEcho},
1332 StartedAt: sql.NullTime{
1333 Time: dbtime.Now(),
1334 Valid: true,
1335 },
1336 OrganizationID: pd.OrganizationID,
1337 ProvisionerTags: must(json.Marshal(job.Tags)),
1338 })
1339 require.NoError(t, err)
1340 _, err = srv.FailJob(ctx, &proto.FailedJob{
1341 JobId: job.ID.String(),
1342 })
1343 require.ErrorContains(t, err, "you don't own this job")
1344 })
1345 t.Run("AlreadyCompleted", func(t *testing.T) {

Callers

nothing calls this directly

Calls 15

UserFunction · 0.92
TemplateVersionFunction · 0.92
NowFunction · 0.92
NewMockFunction · 0.92
OrganizationFunction · 0.92
TemplateFunction · 0.92
WorkspaceEventChannelFunction · 0.92
HandleWorkspaceEventFunction · 0.92
ResetLogsMethod · 0.80
setupFunction · 0.70
mustFunction · 0.70

Tested by

no test coverage detected