-
Notifications
You must be signed in to change notification settings - Fork 1
/
delete_test.go
70 lines (61 loc) · 1.41 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package vector
import (
"crypto/rand"
"encoding/base64"
"testing"
"github.com/stretchr/testify/require"
)
func randomString() string {
buf := make([]byte, 32)
rand.Read(buf)
return base64.StdEncoding.EncodeToString(buf)
}
func TestDelete(t *testing.T) {
for _, ns := range namespaces {
t.Run("namespace_"+ns, func(t *testing.T) {
client, err := newTestClientWithNamespace(ns)
require.NoError(t, err)
id := randomString()
err = client.Upsert(Upsert{
Id: id,
Vector: []float32{0, 1},
})
require.NoError(t, err)
t.Run("existing id", func(t *testing.T) {
ok, err := client.Delete(id)
require.NoError(t, err)
require.True(t, ok)
})
t.Run("non existing id", func(t *testing.T) {
ok, err := client.Delete(randomString())
require.NoError(t, err)
require.False(t, ok)
})
})
}
}
func TestDeleteMany(t *testing.T) {
for _, ns := range namespaces {
t.Run("namespace "+ns, func(t *testing.T) {
client, err := newTestClientWithNamespace(ns)
require.NoError(t, err)
id0 := randomString()
id1 := randomString()
id2 := randomString()
err = client.UpsertMany([]Upsert{
{
Id: id0,
Vector: []float32{0, 1},
},
{
Id: id1,
Vector: []float32{5, 10},
},
})
require.NoError(t, err)
count, err := client.DeleteMany([]string{id0, id1, id2})
require.NoError(t, err)
require.Equal(t, 2, count)
})
}
}