@@ -50,7 +50,10 @@ const (
5050 testNamespace = "datastore-unittests"
5151)
5252
53- var defaultDatastoreConfig = config.DatastoreConfig {TXMaxAttempts : 1 }
53+ var (
54+ defaultDatastoreConfig = config.DatastoreConfig {TXMaxAttempts : 1 }
55+ datastoreConfigWithId = config.DatastoreConfig {TXMaxAttempts : 1 , DatabaseId : "database-id" }
56+ )
5457
5558func getTestProject () string {
5659 if testProject , ok := os .LookupEnv ("TEST_PROJECT_ID" ); ok {
@@ -91,6 +94,17 @@ func newMetaDB(ctx context.Context, t *testing.T) *m.MetaDB {
9194 return metaDB
9295}
9396
97+ func newMetaDBWithDatabaseConfig (ctx context.Context , t * testing.T ) * m.MetaDB {
98+ t .Helper ()
99+ metaDB , err := m .NewMetaDB (ctx , getTestProject (), datastoreConfigWithId )
100+ if err != nil {
101+ t .Fatalf ("Initializing MetaDB with DatabaseId: %v" , err )
102+ }
103+ metaDB .Namespace = testNamespace
104+ t .Cleanup (func () { metaDB .Disconnect (ctx ) })
105+ return metaDB
106+ }
107+
94108func newStoreKey () string {
95109 return uuid .NewString () + "_unittest_store"
96110}
@@ -226,6 +240,15 @@ func setupTestStoreRecordBlobSet(ctx context.Context, t *testing.T, metaDB *m.Me
226240 return store , record , blob
227241}
228242
243+ func TestMetaDB_WithDatabaseIDErrorGettingRecord (t * testing.T ) {
244+ ctx := context .Background ()
245+ metaDB := newMetaDBWithDatabaseConfig (ctx , t )
246+
247+ record , err := metaDB .GetRecord (ctx , newStoreKey (), newRecordKey ())
248+ assert .Nil (t , record , "GetRecord() should be nil" )
249+ assert .Error (t , err , "GetRecord() should return error when database is unknown" )
250+ }
251+
229252func TestMetaDB_Disconnect (t * testing.T ) {
230253 ctx := context .Background ()
231254 metaDB := newMetaDB (ctx , t )
@@ -762,7 +785,7 @@ func TestMetaDB_UpdateRecordWithExternalBlobs(t *testing.T) {
762785 }
763786
764787 recordKey := newRecordKey ()
765- expiresAt := time .Now ().UTC ().Add (3 * time .Hour ).Truncate (time .Hour )
788+ expiresAt := time .Now ().UTC ().Add (3 * time .Hour ).Truncate (time .Hour )
766789 origRecord := & record.Record {
767790 Key : recordKey ,
768791 Properties : make (record.PropertyMap ),
@@ -818,7 +841,7 @@ func TestMetaDB_UpdateRecordWithExternalBlobs(t *testing.T) {
818841 }
819842
820843 // Make sure ExpiresAt is updated in the BlobRef when updated in the Record.
821- newExpiresAt := time .Now ().UTC ().Add (6 * time .Hour ).Truncate (time .Hour )
844+ newExpiresAt := time .Now ().UTC ().Add (6 * time .Hour ).Truncate (time .Hour )
822845 newRecord , err = metaDB .UpdateRecord (ctx , storeKey , recordKey , func (record * record.Record ) (* record.Record , error ) {
823846 record .ExpiresAt = newExpiresAt
824847 return record , nil
@@ -890,7 +913,8 @@ func TestMetaDB_ListBlobsByStatus(t *testing.T) {
890913 blobref .StatusError ,
891914 blobref .StatusInitializing ,
892915 blobref .StatusPendingDeletion ,
893- blobref .StatusPendingDeletion }
916+ blobref .StatusPendingDeletion ,
917+ }
894918 for _ , s := range statuses {
895919 blob := & blobref.BlobRef {
896920 Key : uuid .New (),
@@ -1214,7 +1238,8 @@ func TestMetaDB_QueryRecords(t *testing.T) {
12141238 StoreKey : stores [0 ].Key ,
12151239 OwnerId : "abc" ,
12161240 },
1217- []* record.Record {records [0 ]}, codes .OK ,
1241+ []* record.Record {records [0 ]},
1242+ codes .OK ,
12181243 },
12191244 {
12201245 "Tags AND No Result" ,
@@ -1227,27 +1252,29 @@ func TestMetaDB_QueryRecords(t *testing.T) {
12271252 {
12281253 "Tags OR No Result" ,
12291254 & pb.QueryRecordsRequest {
1230- StoreKey : stores [1 ].Key ,
1231- Tags : []string {"non-existing-tag-1" , "non-existing-tag-2" },
1255+ StoreKey : stores [1 ].Key ,
1256+ Tags : []string {"non-existing-tag-1" , "non-existing-tag-2" },
12321257 TagFilterMode : pb .TagFilterMode_OR ,
12331258 },
12341259 nil , codes .OK ,
12351260 },
12361261 {
12371262 "Tags OR" ,
12381263 & pb.QueryRecordsRequest {
1239- StoreKey : stores [1 ].Key ,
1240- Tags : []string {tag1 , tag4 },
1264+ StoreKey : stores [1 ].Key ,
1265+ Tags : []string {tag1 , tag4 },
12411266 TagFilterMode : pb .TagFilterMode_OR ,
12421267 },
1243- []* record.Record {records [2 ]}, codes .OK ,
1268+ []* record.Record {records [2 ]},
1269+ codes .OK ,
12441270 },
12451271 {
12461272 "Tags Multiple Records" ,
12471273 & pb.QueryRecordsRequest {
12481274 Tags : []string {tag1 },
12491275 },
1250- []* record.Record {records [0 ], records [2 ]}, codes .OK ,
1276+ []* record.Record {records [0 ], records [2 ]},
1277+ codes .OK ,
12511278 },
12521279 {
12531280 "Limit" ,
@@ -1256,23 +1283,26 @@ func TestMetaDB_QueryRecords(t *testing.T) {
12561283 Tags : []string {tag1 },
12571284 Limit : 1 ,
12581285 },
1259- []* record.Record {records [0 ]}, codes .OK ,
1286+ []* record.Record {records [0 ]},
1287+ codes .OK ,
12601288 },
12611289 {
12621290 "Limit No Filtering" ,
12631291 & pb.QueryRecordsRequest {
12641292 StoreKey : stores [0 ].Key ,
12651293 Limit : 1 ,
12661294 },
1267- []* record.Record {records [0 ]}, codes .OK ,
1295+ []* record.Record {records [0 ]},
1296+ codes .OK ,
12681297 },
12691298 {
12701299 "Offset No Filtering" ,
12711300 & pb.QueryRecordsRequest {
12721301 StoreKey : stores [0 ].Key ,
12731302 Offset : 1 ,
12741303 },
1275- []* record.Record {records [1 ]}, codes .OK ,
1304+ []* record.Record {records [1 ]},
1305+ codes .OK ,
12761306 },
12771307 {
12781308 "Keys Only" ,
@@ -1282,7 +1312,8 @@ func TestMetaDB_QueryRecords(t *testing.T) {
12821312 Tags : []string {tag1 },
12831313 KeysOnly : true ,
12841314 },
1285- []* record.Record {{Key : records [0 ].Key , StoreKey : records [0 ].StoreKey }}, codes .OK ,
1315+ []* record.Record {{Key : records [0 ].Key , StoreKey : records [0 ].StoreKey }},
1316+ codes .OK ,
12861317 },
12871318 }
12881319 for _ , tc := range testCases {
0 commit comments