Skip to content

Commit

Permalink
add update/insert fail tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Schmidt committed Aug 20, 2024
1 parent 4a75fbc commit c18a84f
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions integration_single_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ var (
barNamespace = "bar"
)

var keyStart = 100000

func getUniqueKey() string {
keyStart++
return fmt.Sprintf("key%d", keyStart)
}

type SingleNodeTestSuite struct {
ServerTestBaseSuite
}
Expand Down Expand Up @@ -150,6 +157,44 @@ func (suite *SingleNodeTestSuite) TestBasicUpsertGetDelete() {
}
}

func (suite *SingleNodeTestSuite) TestFailsToInsertAlreadyExists() {
ctx := context.Background()
key := getUniqueKey()

err := suite.AvsClient.Insert(ctx, "test", nil, key, map[string]any{"foo": "bar"}, false)
suite.NoError(err)

if err != nil {
return
}

err = suite.AvsClient.Insert(ctx, "test", nil, key, map[string]any{"foo": "bar"}, false)
suite.Error(err)
}

func (suite *SingleNodeTestSuite) TestFailsToUpdateRecordDNE() {
ctx := context.Background()
key := getUniqueKey()

err := suite.AvsClient.Update(ctx, "test", nil, key, map[string]any{"foo": "bar"}, false)
suite.Error(err)
}

func (suite *SingleNodeTestSuite) TestCanUpsertRecordTwice() {
ctx := context.Background()
key := getUniqueKey()

err := suite.AvsClient.Upsert(ctx, "test", nil, key, map[string]any{"foo": "bar"}, false)
suite.NoError(err)

if err != nil {
return
}

err = suite.AvsClient.Upsert(ctx, "test", nil, key, map[string]any{"foo": "bar"}, false)
suite.NoError(err)
}

func getVectorFloat32(length int, last float32) []float32 {
vector := make([]float32, length)
for i := 0; i < length-1; i++ {
Expand Down

0 comments on commit c18a84f

Please sign in to comment.