Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make create/update methods return new resource #112

Merged
merged 2 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ require (
github.com/golang/protobuf v1.4.2
github.com/gomodule/redigo v1.8.2
github.com/google/uuid v1.1.1
github.com/grpc-ecosystem/grpc-gateway v1.14.6
github.com/sirupsen/logrus v1.6.0
github.com/stretchr/testify v1.6.1
gocloud.dev v0.20.0
golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7 // indirect
google.golang.org/api v0.29.0
google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f
google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f // indirect
google.golang.org/grpc v1.30.0
google.golang.org/protobuf v1.25.0
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
Expand Down
11 changes: 0 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/GoogleCloudPlatform/cloudsql-proxy v0.0.0-20191009163259-e802c2cb94ae/go.mod h1:mjwGPas4yKduTyubHvD1Atl9r1rUq8DfVy+gkVvZ+oo=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/aws/aws-sdk-go v1.15.27/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0=
github.com/aws/aws-sdk-go v1.19.18/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.31.13 h1:UeWMTRTL0XAKLR7vxDL4/u7KOtz/LtfJr+lXtxN4YEQ=
Expand All @@ -115,8 +114,6 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
Expand Down Expand Up @@ -194,8 +191,6 @@ github.com/googleapis/gax-go v2.0.2+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/grpc-ecosystem/grpc-gateway v1.14.6 h1:8ERzHx8aj1Sc47mu9n/AksaKCSWrMchFtkdrS4BIj5o=
github.com/grpc-ecosystem/grpc-gateway v1.14.6/go.mod h1:zdiPV4Yse/1gnckTHtghG4GkDEdKCRJduHpTxT3/jcw=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down Expand Up @@ -232,7 +227,6 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
Expand Down Expand Up @@ -314,8 +308,6 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191002035440-2ec189313ef0 h1:2mqDk8w/o6UmeUCu5Qiq2y7iMf6anbx+YA8d1JFoFrs=
golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191112182307-2180aed22343/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand Down Expand Up @@ -500,7 +492,6 @@ google.golang.org/genproto v0.0.0-20200325114520-5b2d0af7952b/go.mod h1:55QSHmfG
google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/genproto v0.0.0-20200603110839-e855014d5736/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA=
Expand Down Expand Up @@ -541,8 +532,6 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.3 h1:fvjTMHxHEw/mxHbtzPi3JCcKXQRAnQTBRo6YCJSVHKI=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
Expand Down
13 changes: 7 additions & 6 deletions internal/app/server/triton.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,25 @@ func (s *tritonServer) CreateStore(ctx context.Context, req *tritonpb.CreateStor
Tags: req.Store.Tags,
OwnerID: req.Store.OwnerId,
}
if err := s.metaDB.CreateStore(ctx, &store); err != nil {
newStore, err := s.metaDB.CreateStore(ctx, &store)
if err != nil {
log.Warnf("CreateStore failed for store (%s): %v", store.Key, err)
return nil, status.Convert(err).Err()
}
log.Infof("Created store: %+v", store)
return store.ToProto(), nil
return newStore.ToProto(), nil
}

func (s *tritonServer) CreateRecord(ctx context.Context, req *tritonpb.CreateRecordRequest) (*tritonpb.Record, error) {
record := metadb.NewRecordFromProto(req.Record)
err := s.metaDB.InsertRecord(ctx, req.StoreKey, record)
newRecord, err := s.metaDB.InsertRecord(ctx, req.StoreKey, record)
if err != nil {
log.Warnf("CreateRecord failed for store (%s), record (%s): %v",
req.GetStoreKey(), req.Record.GetKey(), err)
return nil, status.Convert(err).Err()
}
log.Infof("Created record: %+v", record)
return record.ToProto(), nil
return newRecord.ToProto(), nil
}

func (s *tritonServer) DeleteRecord(ctx context.Context, req *tritonpb.DeleteRecordRequest) (*empty.Empty, error) {
Expand Down Expand Up @@ -151,13 +152,13 @@ func (s *tritonServer) GetRecord(ctx context.Context, req *tritonpb.GetRecordReq

func (s *tritonServer) UpdateRecord(ctx context.Context, req *tritonpb.UpdateRecordRequest) (*tritonpb.Record, error) {
record := metadb.NewRecordFromProto(req.GetRecord())
err := s.metaDB.UpdateRecord(ctx, req.GetStoreKey(), record)
newRecord, err := s.metaDB.UpdateRecord(ctx, req.GetStoreKey(), record)
if err != nil {
log.Warnf("UpdateRecord failed for store(%s), record (%s): %v",
req.GetStoreKey(), req.GetRecord().GetKey(), err)
return nil, status.Convert(err).Err()
}
return record.ToProto(), nil
return newRecord.ToProto(), nil
}

func (s *tritonServer) QueryRecords(ctx context.Context, req *tritonpb.QueryRecordsRequest) (*tritonpb.QueryRecordsResponse, error) {
Expand Down
20 changes: 13 additions & 7 deletions internal/pkg/metadb/datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,13 @@ func (d *Driver) Disconnect(ctx context.Context) error {
}

// CreateStore creates a new store.
func (d *Driver) CreateStore(ctx context.Context, store *m.Store) error {
func (d *Driver) CreateStore(ctx context.Context, store *m.Store) (*m.Store, error) {
key := d.createStoreKey(store.Key)
mut := ds.NewInsert(key, store)
return d.mutateSingle(ctx, mut)
if err := d.mutateSingle(ctx, mut); err != nil {
return nil, err
}
return store, nil
}

// GetStore fetches a store based on the key provided.
Expand Down Expand Up @@ -162,7 +165,7 @@ func (d *Driver) DeleteStore(ctx context.Context, key string) error {

// InsertRecord creates a new Record in the store specified with storeKey.
// Returns error if there is already a record with the same key.
func (d *Driver) InsertRecord(ctx context.Context, storeKey string, record *m.Record) error {
func (d *Driver) InsertRecord(ctx context.Context, storeKey string, record *m.Record) (*m.Record, error) {
rkey := d.createRecordKey(storeKey, record.Key)
_, err := d.client.RunInTransaction(ctx, func(tx *ds.Transaction) error {
dskey := d.createStoreKey(storeKey)
Expand All @@ -178,17 +181,20 @@ func (d *Driver) InsertRecord(ctx context.Context, storeKey string, record *m.Re
return d.mutateSingleInTransaction(tx, mut)
})
if err != nil {
return datastoreErrToGRPCStatus(err)
return nil, datastoreErrToGRPCStatus(err)
}
return nil
return record, nil
}

// UpdateRecord updates the record in the store specified with storeKey.
// Returns error if the store doesn't have a record with the key provided.
func (d *Driver) UpdateRecord(ctx context.Context, storeKey string, record *m.Record) error {
func (d *Driver) UpdateRecord(ctx context.Context, storeKey string, record *m.Record) (*m.Record, error) {
rkey := d.createRecordKey(storeKey, record.Key)
mut := ds.NewUpdate(rkey, record)
return d.mutateSingle(ctx, mut)
if err := d.mutateSingle(ctx, mut); err != nil {
return nil, err
}
return record, nil
}

// GetRecord fetches and returns a record with key in store storeKey.
Expand Down
74 changes: 45 additions & 29 deletions internal/pkg/metadb/datastore/datastore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ func TestDriver_SimpleCreateGetDeleteStore(t *testing.T) {
Signature: uuid.MustParse("db94be80-e036-4ca8-a9c0-2259b8a67acc"),
},
}
if err := driver.CreateStore(ctx, store); err != nil {
createdStore, err := driver.CreateStore(ctx, store)
if err != nil {
t.Fatalf("Could not create a new store: %v", err)
}
assertEqualStore(t, store, createdStore, "CreateStore should return the created store.")

store2, err := driver.GetStore(ctx, storeKey)
if err != nil {
Expand All @@ -116,10 +118,11 @@ func TestDriver_SimpleCreateGetDeleteStore(t *testing.T) {
if err != nil {
t.Fatalf("Failed to delete a store (%s): %v", storeKey, err)
}
_, err = driver.GetStore(ctx, storeKey)
store4, err := driver.GetStore(ctx, storeKey)
if err == nil {
t.Fatalf("GetStore didn't return an error after deleting a store: %v", err)
}
assert.Nil(t, store4, "GetStore should return a nil store.")
}

func TestDriver_SimpleCreateGetDeleteRecord(t *testing.T) {
Expand All @@ -131,9 +134,12 @@ func TestDriver_SimpleCreateGetDeleteRecord(t *testing.T) {
Name: "SimpleCreateGetDeleteRecord",
OwnerID: "triton",
}
if err := driver.CreateStore(ctx, store); err != nil {
createdStore, err := driver.CreateStore(ctx, store)
if err != nil {
t.Fatalf("Could not create a new store: %v", err)
}
assertEqualStore(t, store, createdStore, "CreateStore should return the created store.")

recordKey := newRecordKey()
blob := []byte{0x54, 0x72, 0x69, 0x74, 0x6f, 0x6e}
createdAt := time.Date(1988, 4, 16, 8, 6, 5, int(1234*time.Microsecond), time.UTC)
Expand All @@ -154,29 +160,28 @@ func TestDriver_SimpleCreateGetDeleteRecord(t *testing.T) {
Signature: uuid.MustParse("89223949-0414-438e-8f5e-3fd9e2d11c1e"),
},
}
if err := driver.InsertRecord(ctx, storeKey, record); err != nil {
createdRecord, err := driver.InsertRecord(ctx, storeKey, record)
if err != nil {
t.Fatalf("Failed to create a new record (%s) in store (%s): %v", recordKey, storeKey, err)
}
assertEqualRecord(t, record, createdRecord, "InsertRecord should return the created record.")

record2, err := driver.GetRecord(ctx, storeKey, recordKey)
if err != nil {
t.Fatalf("Failed to get a record (%s) in store (%s): %v", recordKey, storeKey, err)
}
assertEqualRecord(t, record, record2, "GetRecord should return the exact same record.")

err = driver.InsertRecord(ctx, storeKey, record)
if err == nil {
t.Fatal("Insert should fail if a record with the same already exists.")
}
record3, err := driver.InsertRecord(ctx, storeKey, record)
assert.NotNil(t, err, "Insert should fail if a record with the same already exists.")
assert.Nil(t, record3, "Insert should fail and return nil.")

err = driver.DeleteRecord(ctx, storeKey, recordKey)
if err != nil {
t.Fatalf("Failed to delete a record (%s) in store (%s): %v", recordKey, storeKey, err)
}
_, err = driver.GetRecord(ctx, storeKey, recordKey)
if err == nil {
t.Fatalf("GetRecord didn't return an error after deleting a record (%s)", recordKey)
}
assert.Nilf(t, err, "Failed to delete a record (%s) in store (%s): %v", recordKey, storeKey, err)

record4, err := driver.GetRecord(ctx, storeKey, recordKey)
assert.NotNilf(t, err, "GetRecord didn't return an error after deleting a record (%s)", recordKey)
assert.Nil(t, record4, "GetRecord should return a nil with error")

err = driver.DeleteStore(ctx, storeKey)
if err != nil {
Expand All @@ -191,14 +196,15 @@ func TestDriver_InsertRecordShouldFailWithNonExistentStore(t *testing.T) {
record := &m.Record{
Key: newRecordKey(),
}
err := driver.InsertRecord(ctx, storeKey, record)
record1, err := driver.InsertRecord(ctx, storeKey, record)
if err == nil {
t.Error("InsertRecord should fail if the store doesn't exist.")
driver.DeleteRecord(ctx, storeKey, record.Key)
} else {
assert.Equalf(t, codes.FailedPrecondition, status.Code(err),
"InsertRecord should return FailedPrecondition if the store doesn't exist: %v", err)
}
assert.Nil(t, record1, "InsertRecord should return nil with error")
}

func TestDriver_DeleteStoreShouldFailWhenNotEmpty(t *testing.T) {
Expand All @@ -207,16 +213,21 @@ func TestDriver_DeleteStoreShouldFailWhenNotEmpty(t *testing.T) {
store := &m.Store{Key: newStoreKey()}
record := &m.Record{Key: newRecordKey(), Properties: make(m.PropertyMap)}

assert.NoError(t, driver.CreateStore(ctx, store))
createdStore, err := driver.CreateStore(ctx, store)
assert.NoError(t, err)
t.Cleanup(func() {
assert.NoError(t, driver.DeleteStore(ctx, store.Key))
})
assert.NoError(t, driver.InsertRecord(ctx, store.Key, record))
assertEqualStore(t, store, createdStore, "CreateStore should return the created store.")

createdRecord, err := driver.InsertRecord(ctx, store.Key, record)
assert.NoError(t, err)
t.Cleanup(func() {
assert.NoError(t, driver.DeleteRecord(ctx, store.Key, record.Key))
})
assertEqualRecord(t, record, createdRecord, "InsertRecord should return the created record.")

err := driver.DeleteStore(ctx, store.Key)
err = driver.DeleteStore(ctx, store.Key)
if err == nil {
t.Error("DeleteStore should fail if the store is not empty.")
} else {
Expand All @@ -234,9 +245,12 @@ func TestDriver_UpdateRecord(t *testing.T) {
Name: "UpdateRecord",
OwnerID: "triton",
}
if err := driver.CreateStore(ctx, store); err != nil {
createdStore, err := driver.CreateStore(ctx, store)
if err != nil {
t.Fatalf("Could not create a new store: %v", err)
}
assertEqualStore(t, store, createdStore, "CreateStore should return the created store.")

recordKey := newRecordKey()
blob := []byte{0x54, 0x72, 0x69, 0x74, 0x6f, 0x6e}
createdAt := time.Date(1988, 4, 16, 8, 6, 5, int(1234*time.Microsecond), time.UTC)
Expand All @@ -254,20 +268,22 @@ func TestDriver_UpdateRecord(t *testing.T) {
},
}

if err := driver.UpdateRecord(ctx, storeKey, record); err == nil {
t.Error("UpdateRecord should return an error if the specified record doesn't exist.")
}
updatedRecord, err := driver.UpdateRecord(ctx, storeKey, record)
assert.NotNil(t, err, "UpdateRecord should return an error if the specified record doesn't exist.")
assert.Nil(t, updatedRecord, "UpdateRecord should return nil with error")

insertedRecord, err := driver.InsertRecord(ctx, storeKey, record)
assert.Nilf(t, err, "Failed to create a new record (%s) in store (%s): %v", recordKey, storeKey, err)
assertEqualRecord(t, record, insertedRecord, "Inserted record is not the same as original.")

if err := driver.InsertRecord(ctx, storeKey, record); err != nil {
t.Fatalf("Failed to create a new record (%s) in store (%s): %v", recordKey, storeKey, err)
}
record.Tags = append(record.Tags, "ghi")
record.OwnerID = "NewOwner"
record.Timestamps.UpdatedAt = time.Date(1988, 5, 17, 5, 6, 8, int(4321*time.Microsecond), time.UTC)
record.Timestamps.Signature = uuid.MustParse("3c1dc762-8f22-4d85-b729-b90393f45ca6")
if err := driver.UpdateRecord(ctx, storeKey, record); err != nil {
t.Fatalf("Failed to update a record (%s) in store (%s): %v", recordKey, storeKey, err)
}

updatedRecord, err = driver.UpdateRecord(ctx, storeKey, record)
assert.Nilf(t, err, "Failed to update a record (%s) in store (%s): %v", recordKey, storeKey, err)
assertEqualRecord(t, record, updatedRecord, "Updated record is not the same as original.")

record2, err := driver.GetRecord(ctx, storeKey, recordKey)
if err != nil {
Expand Down
Loading