MCPcopy Create free account
hub / github.com/cloudquery/cloudquery / TestDelete

Function TestDelete

plugins/destination/sqlite/client/delete_test.go:21–74  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19)
20
21func 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
76func countAllRows(ctx context.Context, client *Client, table *schema.Table) (int64, error) {
77 var err error

Callers

nothing calls this directly

Calls 9

RunMethod · 0.80
withPluginClientFunction · 0.70
createTestTableFunction · 0.70
createInsertMessagesFunction · 0.70
createDeleteMessagesFunction · 0.70
countAllRowsFunction · 0.70
MigrateTablesMethod · 0.65
WriteTableBatchMethod · 0.65
DeleteRecordMethod · 0.45

Tested by

no test coverage detected