(t *testing.T)
| 19 | ) |
| 20 | |
| 21 | func TestDelete(t *testing.T) { |
| 22 | testCases := []struct { |
| 23 | name string |
| 24 | insertValues []string |
| 25 | deleteValues []string |
| 26 | deleteAll bool |
| 27 | expectedCount int |
| 28 | }{ |
| 29 | { |
| 30 | name: "delete single record", |
| 31 | insertValues: []string{"foo", "bar"}, |
| 32 | deleteValues: []string{"foo"}, |
| 33 | expectedCount: 1, |
| 34 | }, |
| 35 | { |
| 36 | name: "delete both records", |
| 37 | insertValues: []string{"foo", "bar"}, |
| 38 | deleteValues: []string{"foo", "bar"}, |
| 39 | expectedCount: 0, |
| 40 | }, |
| 41 | { |
| 42 | name: "delete none", |
| 43 | insertValues: []string{"foo"}, |
| 44 | deleteValues: []string{"bar"}, |
| 45 | expectedCount: 1, |
| 46 | }, |
| 47 | { |
| 48 | name: "delete all records", |
| 49 | insertValues: []string{"foo", "bar"}, |
| 50 | deleteAll: true, |
| 51 | expectedCount: 0, |
| 52 | }, |
| 53 | } |
| 54 | for _, tc := range testCases { |
| 55 | t.Run(tc.name, func(t *testing.T) { |
| 56 | r := require.New(t) |
| 57 | ctx := context.Background() |
| 58 | client := withPluginClient(ctx, r) |
| 59 | |
| 60 | table := createTestTable() |
| 61 | r.NoError(client.MigrateTables(ctx, message.WriteMigrateTables{{Table: table}})) |
| 62 | |
| 63 | writeInserts := createInsertMessages(tc.insertValues, table) |
| 64 | r.NoError(client.WriteTableBatch(ctx, "", writeInserts)) |
| 65 | |
| 66 | writeDeletes := createDeleteMessages(tc.deleteAll, table, tc.deleteValues) |
| 67 | r.NoError(client.DeleteRecord(ctx, writeDeletes)) |
| 68 | |
| 69 | count, err := countAllRows(ctx, client, table) |
| 70 | r.NoError(err) |
| 71 | r.EqualValues(tc.expectedCount, count, "unexpected amount of items after delete with match") |
| 72 | }) |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | func countAllRows(ctx context.Context, client *Client, table *schema.Table) (int64, error) { |
| 77 | var err error |
nothing calls this directly
no test coverage detected