-
Notifications
You must be signed in to change notification settings - Fork 0
/
mutation_delete_test.go
47 lines (39 loc) · 1.68 KB
/
mutation_delete_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package spnr
import (
"cloud.google.com/go/spanner"
"context"
"github.com/stretchr/testify/assert"
"testing"
)
func TestMutation_Delete(t *testing.T) {
ctx := context.Background()
_, err := testRepository.ApplyInsertOrUpdate(ctx, dataClient, testRecord3)
assert.Nil(t, err)
_, err = testRepository.ApplyDelete(ctx, dataClient, testRecord3)
assert.Nil(t, err)
var fetched Test
err = testRepository.Reader(ctx, dataClient.Single()).FindOne(spanner.Key{testRecord3.String, testRecord3.Int64}, &fetched)
assert.Equal(t, ErrNotFound, err)
}
func TestMutation_DeleteWithSlice(t *testing.T) {
ctx := context.Background()
_, err := testRepository.ApplyInsertOrUpdate(ctx, dataClient, &([]*Test{testRecord3, testRecord4}))
assert.Nil(t, err)
_, err = testRepository.ApplyDelete(ctx, dataClient, &([]Test{*testRecord3, *testRecord4}))
assert.Nil(t, err)
var fetched []Test
keySet := spanner.KeySetFromKeys(spanner.Key{testRecord3.String, testRecord3.Int64}, spanner.Key{testRecord4.String, testRecord4.Int64})
_ = testRepository.Reader(ctx, dataClient.Single()).FindAll(keySet, &fetched)
assert.Empty(t, fetched)
}
func TestMutation_DeleteWithSlicePointer(t *testing.T) {
ctx := context.Background()
_, err := testRepository.ApplyInsertOrUpdate(ctx, dataClient, &([]*Test{testRecord3, testRecord4}))
assert.Nil(t, err)
_, err = testRepository.ApplyDelete(ctx, dataClient, &([]*Test{testRecord3, testRecord4}))
assert.Nil(t, err)
var fetched []Test
keySet := spanner.KeySetFromKeys(spanner.Key{testRecord3.String, testRecord3.Int64}, spanner.Key{testRecord4.String, testRecord4.Int64})
_ = testRepository.Reader(ctx, dataClient.Single()).FindAll(keySet, &fetched)
assert.Empty(t, fetched)
}