|
| 1 | +package jobs |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/require" |
| 7 | + |
| 8 | + "github.com/smartcontractkit/chainlink-deployments-framework/engine/test/runtime" |
| 9 | +) |
| 10 | + |
| 11 | +func TestDeleteJobsChangeset(t *testing.T) { |
| 12 | + t.Parallel() |
| 13 | + |
| 14 | + t.Run("deletes eligible jobs", func(t *testing.T) { |
| 15 | + t.Parallel() |
| 16 | + |
| 17 | + rt, err := runtime.New(t.Context()) |
| 18 | + require.NoError(t, err) |
| 19 | + |
| 20 | + nodeID := registerTestNode(t, rt) |
| 21 | + jobID := proposeJob(t, rt, nodeID) |
| 22 | + |
| 23 | + _, err = runtime.ExecChangeset(rt, DeleteJobsChangeset{}, DeleteJobsInput{ |
| 24 | + JobIDs: []string{jobID}, |
| 25 | + }) |
| 26 | + require.NoError(t, err) |
| 27 | + }) |
| 28 | + |
| 29 | + t.Run("precondition — empty job list rejected", func(t *testing.T) { |
| 30 | + t.Parallel() |
| 31 | + |
| 32 | + rt, err := runtime.New(t.Context()) |
| 33 | + require.NoError(t, err) |
| 34 | + |
| 35 | + _, err = runtime.ExecChangeset(rt, DeleteJobsChangeset{}, DeleteJobsInput{}) |
| 36 | + require.ErrorContains(t, err, "no job_ids provided") |
| 37 | + }) |
| 38 | + |
| 39 | + t.Run("precondition — duplicate job id rejected", func(t *testing.T) { |
| 40 | + t.Parallel() |
| 41 | + |
| 42 | + rt, err := runtime.New(t.Context()) |
| 43 | + require.NoError(t, err) |
| 44 | + |
| 45 | + _, err = runtime.ExecChangeset(rt, DeleteJobsChangeset{}, DeleteJobsInput{ |
| 46 | + JobIDs: []string{"job_1", "job_1"}, |
| 47 | + }) |
| 48 | + require.ErrorContains(t, err, "duplicate job id") |
| 49 | + }) |
| 50 | + |
| 51 | + t.Run("precondition — non-existent job rejected", func(t *testing.T) { |
| 52 | + t.Parallel() |
| 53 | + |
| 54 | + rt, err := runtime.New(t.Context()) |
| 55 | + require.NoError(t, err) |
| 56 | + |
| 57 | + _, err = runtime.ExecChangeset(rt, DeleteJobsChangeset{}, DeleteJobsInput{ |
| 58 | + JobIDs: []string{"job_does_not_exist"}, |
| 59 | + }) |
| 60 | + require.Error(t, err) |
| 61 | + }) |
| 62 | + |
| 63 | + t.Run("precondition — already-deleted job rejected", func(t *testing.T) { |
| 64 | + t.Parallel() |
| 65 | + |
| 66 | + rt, err := runtime.New(t.Context()) |
| 67 | + require.NoError(t, err) |
| 68 | + |
| 69 | + nodeID := registerTestNode(t, rt) |
| 70 | + jobID := proposeJob(t, rt, nodeID) |
| 71 | + |
| 72 | + _, err = runtime.ExecChangeset(rt, DeleteJobsChangeset{}, DeleteJobsInput{ |
| 73 | + JobIDs: []string{jobID}, |
| 74 | + }) |
| 75 | + require.NoError(t, err) |
| 76 | + |
| 77 | + _, err = runtime.ExecChangeset(rt, DeleteJobsChangeset{}, DeleteJobsInput{ |
| 78 | + JobIDs: []string{jobID}, |
| 79 | + }) |
| 80 | + require.ErrorContains(t, err, "already deleted") |
| 81 | + }) |
| 82 | +} |
0 commit comments