func setupTestStoreRecord(ctx context.Context, t *testing.T, metaDB *m.MetaDB, store *store.Store, r *record.Record) (*store.Store, *record.Record) {
	t.Helper()
	newStore, err := metaDB.CreateStore(ctx, store)
	if err != nil {
		t.Fatalf("Could not create a new store: %v", err)
	}
	t.Cleanup(func() {
		metaDB.DeleteStore(ctx, newStore.Key)
	})
	metadbtest.AssertEqualStore(t, store, newStore, "CreateStore should return the created store.")
	var newRecord *record.Record
	if r != nil {
		newRecord, err = metaDB.InsertRecord(ctx, newStore.Key, r)
		if err != nil {
			t.Fatalf("Could not create a new record: %v", err)
		}
		t.Cleanup(func() {
			metaDB.DeleteRecord(ctx, newStore.Key, newRecord.Key)
		})
		metadbtest.AssertEqualRecord(t, r, newRecord, "GetRecord should return the exact same record.")
	}
	return newStore, newRecord
}
setupTestStoreRecord creates a new store and inserts a record into it, then registers
cleanup functions to delete these test store and record.
Passing a nil to record will skip the record insertion.
package metadb_test
import (
	"context"
	"testing"
	"time"
	"cloud.google.com/go/datastore"
	"github.com/google/uuid"
	pb "github.com/googleforgames/open-saves/api"
	m "github.com/googleforgames/open-saves/internal/pkg/metadb"
	"github.com/googleforgames/open-saves/internal/pkg/metadb/blobref"
	"github.com/googleforgames/open-saves/internal/pkg/metadb/blobref/chunkref"
	"github.com/googleforgames/open-saves/internal/pkg/metadb/checksums/checksumstest"
	"github.com/googleforgames/open-saves/internal/pkg/metadb/metadbtest"
	"github.com/googleforgames/open-saves/internal/pkg/metadb/record"
	"github.com/googleforgames/open-saves/internal/pkg/metadb/store"
	"github.com/googleforgames/open-saves/internal/pkg/metadb/timestamps"
	"github.com/stretchr/testify/assert"
	"google.golang.org/api/iterator"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
)
const (
	storeKind          = "store"
	recordKind         = "record"
	blobKind           = "blob"
	chunkKind          = "chunk"
	timestampTestDelta = 5 * time.Second
	testProject        = "triton-for-games-dev"
	testNamespace      = "datastore-unittests"
)
func TestMetaDB_NewMetaDB(t *testing.T) {
	ctx := context.Background()
	metaDB, err := m.NewMetaDB(ctx, testProject)
	assert.NotNil(t, metaDB, "NewMetaDB() should return a non-nil instance.")
	assert.NoError(t, err, "NewMetaDB should succeed.")
}
const testTimestampThreshold = 30 * time.Second
func newDatastoreClient(ctx context.Context, t *testing.T) *datastore.Client {
	client, err := datastore.NewClient(ctx, testProject)
	if err != nil {
		t.Fatalf("datastore.NewClient failed: %v", err)
	}
	t.Cleanup(func() {
		client.Close()
	})
	return client
}
func newMetaDB(ctx context.Context, t *testing.T) *m.MetaDB {
	t.Helper()
	metaDB, err := m.NewMetaDB(ctx, testProject)
	if err != nil {
		t.Fatalf("Initializing MetaDB: %v", err)
	}
	metaDB.Namespace = testNamespace
	t.Cleanup(func() { metaDB.Disconnect(ctx) })
	return metaDB
}
func newStoreKey() string {
	return uuid.NewString() + "_unittest_store"
}
func newRecordKey() string {
	return uuid.NewString() + "_unittest_record"
}
func cloneRecord(r *record.Record) *record.Record {
	if r == nil {
		return nil
	}
	ret := *r
	ret.Blob = append([]byte{}, r.Blob...)
	ret.Properties = make(record.PropertyMap)
	for k, v := range r.Properties {
		ret.Properties[k] = v
	}
	ret.Tags = append([]string{}, r.Tags...)
	return &ret
}
func blobRefKey(key uuid.UUID) *datastore.Key {
	dsKey := datastore.NameKey(blobKind, key.String(), nil)
	dsKey.Namespace = testNamespace
	return dsKey
}
func chunkRefKey(blobKey, key uuid.UUID) *datastore.Key {
	dsKey := datastore.NameKey(chunkKind, key.String(), blobRefKey(blobKey))
	dsKey.Namespace = testNamespace
	return dsKey
}