Skip to content

Commit

Permalink
test storage object OCC behavior with empty and non empty versions (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Gehorsam authored Sep 22, 2023
1 parent 81b4c7f commit db4f588
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions server/core_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2082,6 +2082,77 @@ func TestStorageListNoRepeats(t *testing.T) {
assert.Equal(t, "", values.Cursor, "cursor was not nil")
}

func TestStorageOverrwriteEmptyAndNonEmptyVersions(t *testing.T) {
db := NewDB(t)
defer db.Close()

uid := uuid.Must(uuid.NewV4())
InsertUser(t, db, uid)
collection := GenerateString()

ops := StorageOpWrites{
&StorageOpWrite{
OwnerID: uid.String(),
Object: &api.WriteStorageObject{
Collection: collection,
Key: "7",
Value: `{"testKey":"testValue1"}`,
PermissionRead: &wrapperspb.Int32Value{Value: 2},
PermissionWrite: &wrapperspb.Int32Value{Value: 1},
Version: "",
},
},
}

acks, code, err := StorageWriteObjects(context.Background(), logger, db, metrics, storageIdx, false, ops)

assert.Nil(t, err, "err was not nil")
assert.Equal(t, codes.OK, code, "code was not OK")
assert.NotNil(t, acks, "acks was nil")

ops = StorageOpWrites{
&StorageOpWrite{
OwnerID: uid.String(),
Object: &api.WriteStorageObject{
Collection: collection,
Key: "7",
Value: `{"testKey":"testValue2"}`,
PermissionRead: &wrapperspb.Int32Value{Value: 2},
PermissionWrite: &wrapperspb.Int32Value{Value: 1},
Version: "",
},
},
}

acks, code, err = StorageWriteObjects(context.Background(), logger, db, metrics, storageIdx, false, ops)

assert.Nil(t, err, "err was not nil")
assert.Equal(t, codes.OK, code, "code was not OK")
assert.NotNil(t, acks, "acks was nil")
assert.Len(t, acks.Acks, 1, "acks length was not 1")

ops = StorageOpWrites{
&StorageOpWrite{
OwnerID: uid.String(),
Object: &api.WriteStorageObject{
Collection: collection,
Key: "7",
Value: `{"testKey":"testValue3"}`,
PermissionRead: &wrapperspb.Int32Value{Value: 2},
PermissionWrite: &wrapperspb.Int32Value{Value: 1},
Version: acks.Acks[0].Version,
},
},
}

acks, code, err = StorageWriteObjects(context.Background(), logger, db, metrics, storageIdx, false, ops)

assert.Nil(t, err, "err was not nil")
assert.Equal(t, codes.OK, code, "code was not OK")
assert.NotNil(t, acks, "acks was nil")
assert.Len(t, acks.Acks, 1, "acks length was not 1")
}

// DB State and expected outcome when performing write op
type writeTestDBState struct {
write int
Expand Down

0 comments on commit db4f588

Please sign in to comment.