From aebf14ec598d267eb0f90db02a37867dda0d9b51 Mon Sep 17 00:00:00 2001 From: Ravi Suhag Date: Tue, 22 Feb 2022 01:35:02 -0800 Subject: [PATCH] refactor: namespace data formats (#113) * refactor: nameespace data formats * refactor: rename storage to store * refactor: move formats package to root --- cmd/server.go | 2 +- {server => formats}/avro/provider.go | 0 {server => formats}/avro/schema.go | 0 {server => formats}/avro/schema_test.go | 2 +- {server => formats}/json/provider.go | 0 {server => formats}/json/provider_test.go | 2 +- {server => formats}/json/schema.go | 0 {server => formats}/protobuf/compatibility.go | 0 .../protobuf/compatibility_test.go | 2 +- {server => formats}/protobuf/error.go | 0 {server => formats}/protobuf/provider.go | 0 {server => formats}/protobuf/provider_test.go | 2 +- {server => formats}/protobuf/schema.go | 0 {server => formats}/protobuf/schema_test.go | 2 +- .../testdata/backward/current/1.proto | 0 .../testdata/backward/current/2.proto | 0 .../testdata/backward/previous/1.proto | 0 .../testdata/backward/previous/2.proto | 0 .../testdata/compatible/current/1.proto | 0 .../testdata/compatible/previous/1.proto | 0 .../protobuf/testdata/forward/current/1.proto | 0 .../testdata/forward/previous/1.proto | 0 .../protobuf/testdata/valid/1.proto | 0 {server => formats}/protobuf/utils.go | 0 server/schema/provider/provider.go | 6 +- server/schema/service.go | 4 +- server/schema/service_test.go | 8 +-- server/server.go | 2 +- {storage => store}/db_error.go | 2 +- .../000001_initialize_schema.down.sql | 0 .../000001_initialize_schema.up.sql | 0 .../000002_create_search_data_idx.down.sql | 0 .../000002_create_search_data_idx.up.sql | 0 {storage => store}/postgres/postgres.go | 0 {storage => store}/postgres/queries.go | 0 {storage => store}/postgres/repository.go | 8 +-- .../postgres/repository_test.go | 56 +++++++++---------- {storage => store}/store.go | 2 +- 38 files changed, 50 insertions(+), 50 deletions(-) rename {server => formats}/avro/provider.go (100%) rename {server => formats}/avro/schema.go (100%) rename {server => formats}/avro/schema_test.go (98%) rename {server => formats}/json/provider.go (100%) rename {server => formats}/json/provider_test.go (95%) rename {server => formats}/json/schema.go (100%) rename {server => formats}/protobuf/compatibility.go (100%) rename {server => formats}/protobuf/compatibility_test.go (99%) rename {server => formats}/protobuf/error.go (100%) rename {server => formats}/protobuf/provider.go (100%) rename {server => formats}/protobuf/provider_test.go (98%) rename {server => formats}/protobuf/schema.go (100%) rename {server => formats}/protobuf/schema_test.go (94%) rename {server => formats}/protobuf/testdata/backward/current/1.proto (100%) rename {server => formats}/protobuf/testdata/backward/current/2.proto (100%) rename {server => formats}/protobuf/testdata/backward/previous/1.proto (100%) rename {server => formats}/protobuf/testdata/backward/previous/2.proto (100%) rename {server => formats}/protobuf/testdata/compatible/current/1.proto (100%) rename {server => formats}/protobuf/testdata/compatible/previous/1.proto (100%) rename {server => formats}/protobuf/testdata/forward/current/1.proto (100%) rename {server => formats}/protobuf/testdata/forward/previous/1.proto (100%) rename {server => formats}/protobuf/testdata/valid/1.proto (100%) rename {server => formats}/protobuf/utils.go (100%) rename {storage => store}/db_error.go (98%) rename {storage => store}/postgres/migrations/000001_initialize_schema.down.sql (100%) rename {storage => store}/postgres/migrations/000001_initialize_schema.up.sql (100%) rename {storage => store}/postgres/migrations/000002_create_search_data_idx.down.sql (100%) rename {storage => store}/postgres/migrations/000002_create_search_data_idx.up.sql (100%) rename {storage => store}/postgres/postgres.go (100%) rename {storage => store}/postgres/queries.go (100%) rename {storage => store}/postgres/repository.go (95%) rename {storage => store}/postgres/repository_test.go (71%) rename {storage => store}/store.go (92%) diff --git a/cmd/server.go b/cmd/server.go index b4dca93c..9f2c7809 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -4,7 +4,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/odpf/stencil/config" "github.com/odpf/stencil/server" - "github.com/odpf/stencil/storage/postgres" + "github.com/odpf/stencil/store/postgres" "github.com/spf13/cobra" // Importing postgres driver diff --git a/server/avro/provider.go b/formats/avro/provider.go similarity index 100% rename from server/avro/provider.go rename to formats/avro/provider.go diff --git a/server/avro/schema.go b/formats/avro/schema.go similarity index 100% rename from server/avro/schema.go rename to formats/avro/schema.go diff --git a/server/avro/schema_test.go b/formats/avro/schema_test.go similarity index 98% rename from server/avro/schema_test.go rename to formats/avro/schema_test.go index dfd9279a..f5be8e1a 100644 --- a/server/avro/schema_test.go +++ b/formats/avro/schema_test.go @@ -3,7 +3,7 @@ package avro_test import ( "testing" - "github.com/odpf/stencil/server/avro" + "github.com/odpf/stencil/formats/avro" "github.com/stretchr/testify/assert" ) diff --git a/server/json/provider.go b/formats/json/provider.go similarity index 100% rename from server/json/provider.go rename to formats/json/provider.go diff --git a/server/json/provider_test.go b/formats/json/provider_test.go similarity index 95% rename from server/json/provider_test.go rename to formats/json/provider_test.go index b30eee2f..bff84b51 100644 --- a/server/json/provider_test.go +++ b/formats/json/provider_test.go @@ -3,7 +3,7 @@ package json_test import ( "testing" - "github.com/odpf/stencil/server/json" + "github.com/odpf/stencil/formats/json" "github.com/stretchr/testify/assert" ) diff --git a/server/json/schema.go b/formats/json/schema.go similarity index 100% rename from server/json/schema.go rename to formats/json/schema.go diff --git a/server/protobuf/compatibility.go b/formats/protobuf/compatibility.go similarity index 100% rename from server/protobuf/compatibility.go rename to formats/protobuf/compatibility.go diff --git a/server/protobuf/compatibility_test.go b/formats/protobuf/compatibility_test.go similarity index 99% rename from server/protobuf/compatibility_test.go rename to formats/protobuf/compatibility_test.go index 29eca184..23c3a99d 100644 --- a/server/protobuf/compatibility_test.go +++ b/formats/protobuf/compatibility_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/odpf/stencil/formats/protobuf" "github.com/odpf/stencil/mocks" - "github.com/odpf/stencil/server/protobuf" "github.com/odpf/stencil/server/schema" "github.com/stretchr/testify/assert" ) diff --git a/server/protobuf/error.go b/formats/protobuf/error.go similarity index 100% rename from server/protobuf/error.go rename to formats/protobuf/error.go diff --git a/server/protobuf/provider.go b/formats/protobuf/provider.go similarity index 100% rename from server/protobuf/provider.go rename to formats/protobuf/provider.go diff --git a/server/protobuf/provider_test.go b/formats/protobuf/provider_test.go similarity index 98% rename from server/protobuf/provider_test.go rename to formats/protobuf/provider_test.go index 844d7258..ed636a98 100644 --- a/server/protobuf/provider_test.go +++ b/formats/protobuf/provider_test.go @@ -11,7 +11,7 @@ import ( "path/filepath" "testing" - "github.com/odpf/stencil/server/protobuf" + "github.com/odpf/stencil/formats/protobuf" "github.com/stretchr/testify/assert" ) diff --git a/server/protobuf/schema.go b/formats/protobuf/schema.go similarity index 100% rename from server/protobuf/schema.go rename to formats/protobuf/schema.go diff --git a/server/protobuf/schema_test.go b/formats/protobuf/schema_test.go similarity index 94% rename from server/protobuf/schema_test.go rename to formats/protobuf/schema_test.go index 8d68b81d..01a60264 100644 --- a/server/protobuf/schema_test.go +++ b/formats/protobuf/schema_test.go @@ -3,7 +3,7 @@ package protobuf_test import ( "testing" - "github.com/odpf/stencil/server/protobuf" + "github.com/odpf/stencil/formats/protobuf" "github.com/odpf/stencil/server/schema" "github.com/stretchr/testify/assert" ) diff --git a/server/protobuf/testdata/backward/current/1.proto b/formats/protobuf/testdata/backward/current/1.proto similarity index 100% rename from server/protobuf/testdata/backward/current/1.proto rename to formats/protobuf/testdata/backward/current/1.proto diff --git a/server/protobuf/testdata/backward/current/2.proto b/formats/protobuf/testdata/backward/current/2.proto similarity index 100% rename from server/protobuf/testdata/backward/current/2.proto rename to formats/protobuf/testdata/backward/current/2.proto diff --git a/server/protobuf/testdata/backward/previous/1.proto b/formats/protobuf/testdata/backward/previous/1.proto similarity index 100% rename from server/protobuf/testdata/backward/previous/1.proto rename to formats/protobuf/testdata/backward/previous/1.proto diff --git a/server/protobuf/testdata/backward/previous/2.proto b/formats/protobuf/testdata/backward/previous/2.proto similarity index 100% rename from server/protobuf/testdata/backward/previous/2.proto rename to formats/protobuf/testdata/backward/previous/2.proto diff --git a/server/protobuf/testdata/compatible/current/1.proto b/formats/protobuf/testdata/compatible/current/1.proto similarity index 100% rename from server/protobuf/testdata/compatible/current/1.proto rename to formats/protobuf/testdata/compatible/current/1.proto diff --git a/server/protobuf/testdata/compatible/previous/1.proto b/formats/protobuf/testdata/compatible/previous/1.proto similarity index 100% rename from server/protobuf/testdata/compatible/previous/1.proto rename to formats/protobuf/testdata/compatible/previous/1.proto diff --git a/server/protobuf/testdata/forward/current/1.proto b/formats/protobuf/testdata/forward/current/1.proto similarity index 100% rename from server/protobuf/testdata/forward/current/1.proto rename to formats/protobuf/testdata/forward/current/1.proto diff --git a/server/protobuf/testdata/forward/previous/1.proto b/formats/protobuf/testdata/forward/previous/1.proto similarity index 100% rename from server/protobuf/testdata/forward/previous/1.proto rename to formats/protobuf/testdata/forward/previous/1.proto diff --git a/server/protobuf/testdata/valid/1.proto b/formats/protobuf/testdata/valid/1.proto similarity index 100% rename from server/protobuf/testdata/valid/1.proto rename to formats/protobuf/testdata/valid/1.proto diff --git a/server/protobuf/utils.go b/formats/protobuf/utils.go similarity index 100% rename from server/protobuf/utils.go rename to formats/protobuf/utils.go diff --git a/server/schema/provider/provider.go b/server/schema/provider/provider.go index 01e26ba5..ead74f3c 100644 --- a/server/schema/provider/provider.go +++ b/server/schema/provider/provider.go @@ -3,9 +3,9 @@ package provider import ( "errors" - "github.com/odpf/stencil/server/avro" - "github.com/odpf/stencil/server/json" - "github.com/odpf/stencil/server/protobuf" + "github.com/odpf/stencil/formats/avro" + "github.com/odpf/stencil/formats/json" + "github.com/odpf/stencil/formats/protobuf" "github.com/odpf/stencil/server/schema" ) diff --git a/server/schema/service.go b/server/schema/service.go index 3919cf5c..c9512fea 100644 --- a/server/schema/service.go +++ b/server/schema/service.go @@ -7,7 +7,7 @@ import ( "github.com/google/uuid" "github.com/odpf/stencil/server/domain" - "github.com/odpf/stencil/storage" + "github.com/odpf/stencil/store" ) func getNonEmpty(args ...string) string { @@ -68,7 +68,7 @@ func (s *Service) cachedGetSchema(ctx context.Context, nsName, schemaName string func (s *Service) CheckCompatibility(ctx context.Context, nsName, schemaName, format, compatibility string, current ParsedSchema) error { prevMeta, prevSchemaData, err := s.GetLatest(ctx, nsName, schemaName) if err != nil { - if errors.Is(err, storage.NoRowsErr) { + if errors.Is(err, store.NoRowsErr) { return nil } return err diff --git a/server/schema/service_test.go b/server/schema/service_test.go index fc372139..df7f67a6 100644 --- a/server/schema/service_test.go +++ b/server/schema/service_test.go @@ -8,7 +8,7 @@ import ( "github.com/odpf/stencil/mocks" "github.com/odpf/stencil/server/domain" "github.com/odpf/stencil/server/schema" - "github.com/odpf/stencil/storage" + "github.com/odpf/stencil/store" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -30,10 +30,10 @@ func TestSchemaCreate(t *testing.T) { t.Run("should return error if namespace not found", func(t *testing.T) { svc, nsService, _, _ := getSvc() nsName := "testNamespace" - nsService.On("Get", mock.Anything, nsName).Return(domain.Namespace{}, storage.NoRowsErr) + nsService.On("Get", mock.Anything, nsName).Return(domain.Namespace{}, store.NoRowsErr) _, err := svc.Create(ctx, nsName, "a", &domain.Metadata{}, []byte("")) assert.NotNil(t, err) - assert.ErrorIs(t, err, storage.NoRowsErr) + assert.ErrorIs(t, err, store.NoRowsErr) nsService.AssertExpectations(t) }) @@ -67,7 +67,7 @@ func TestSchemaCreate(t *testing.T) { data := []byte("data") nsService.On("Get", mock.Anything, nsName).Return(domain.Namespace{Format: "protobuf"}, nil) schemaProvider.On("ParseSchema", "protobuf", data).Return(parsedSchema, nil) - schemaRepo.On("GetLatestVersion", mock.Anything, nsName, "a").Return(int32(2), storage.NoRowsErr) + schemaRepo.On("GetLatestVersion", mock.Anything, nsName, "a").Return(int32(2), store.NoRowsErr) parsedSchema.On("GetCanonicalValue").Return(scFile) schemaRepo.On("CreateSchema", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(int32(1), nil) scInfo, err := svc.Create(ctx, nsName, "a", &domain.Metadata{}, data) diff --git a/server/server.go b/server/server.go index 8a6034e7..f3ad082f 100644 --- a/server/server.go +++ b/server/server.go @@ -11,7 +11,7 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" "github.com/newrelic/go-agent/v3/integrations/nrgrpc" "github.com/odpf/stencil/config" - "github.com/odpf/stencil/storage/postgres" + "github.com/odpf/stencil/store/postgres" grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" grpc_zap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap" diff --git a/storage/db_error.go b/store/db_error.go similarity index 98% rename from storage/db_error.go rename to store/db_error.go index b2b12e92..eda86035 100644 --- a/storage/db_error.go +++ b/store/db_error.go @@ -1,4 +1,4 @@ -package storage +package store import ( "fmt" diff --git a/storage/postgres/migrations/000001_initialize_schema.down.sql b/store/postgres/migrations/000001_initialize_schema.down.sql similarity index 100% rename from storage/postgres/migrations/000001_initialize_schema.down.sql rename to store/postgres/migrations/000001_initialize_schema.down.sql diff --git a/storage/postgres/migrations/000001_initialize_schema.up.sql b/store/postgres/migrations/000001_initialize_schema.up.sql similarity index 100% rename from storage/postgres/migrations/000001_initialize_schema.up.sql rename to store/postgres/migrations/000001_initialize_schema.up.sql diff --git a/storage/postgres/migrations/000002_create_search_data_idx.down.sql b/store/postgres/migrations/000002_create_search_data_idx.down.sql similarity index 100% rename from storage/postgres/migrations/000002_create_search_data_idx.down.sql rename to store/postgres/migrations/000002_create_search_data_idx.down.sql diff --git a/storage/postgres/migrations/000002_create_search_data_idx.up.sql b/store/postgres/migrations/000002_create_search_data_idx.up.sql similarity index 100% rename from storage/postgres/migrations/000002_create_search_data_idx.up.sql rename to store/postgres/migrations/000002_create_search_data_idx.up.sql diff --git a/storage/postgres/postgres.go b/store/postgres/postgres.go similarity index 100% rename from storage/postgres/postgres.go rename to store/postgres/postgres.go diff --git a/storage/postgres/queries.go b/store/postgres/queries.go similarity index 100% rename from storage/postgres/queries.go rename to store/postgres/queries.go diff --git a/storage/postgres/repository.go b/store/postgres/repository.go similarity index 95% rename from storage/postgres/repository.go rename to store/postgres/repository.go index 5df2f365..c0e179b9 100644 --- a/storage/postgres/repository.go +++ b/store/postgres/repository.go @@ -9,7 +9,7 @@ import ( "github.com/jackc/pgconn" "github.com/jackc/pgx/v4" "github.com/odpf/stencil/server/domain" - "github.com/odpf/stencil/storage" + "github.com/odpf/stencil/store" ) func wrapError(err error, format string, args ...interface{}) error { @@ -18,14 +18,14 @@ func wrapError(err error, format string, args ...interface{}) error { } var pgErr *pgconn.PgError if errors.Is(err, pgx.ErrNoRows) { - return storage.NoRowsErr.WithErr(err, fmt.Sprintf(format, args...)) + return store.NoRowsErr.WithErr(err, fmt.Sprintf(format, args...)) } if errors.As(err, &pgErr) { if pgErr.Code == "23505" { - return storage.ConflictErr.WithErr(err, fmt.Sprintf(format, args...)) + return store.ConflictErr.WithErr(err, fmt.Sprintf(format, args...)) } } - return storage.UnknownErr.WithErr(err, fmt.Sprintf(format, args...)) + return store.UnknownErr.WithErr(err, fmt.Sprintf(format, args...)) } type searchData struct { diff --git a/storage/postgres/repository_test.go b/store/postgres/repository_test.go similarity index 71% rename from storage/postgres/repository_test.go rename to store/postgres/repository_test.go index ded29cc5..b46e4164 100644 --- a/storage/postgres/repository_test.go +++ b/store/postgres/repository_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/odpf/stencil/server/domain" - "github.com/odpf/stencil/storage" - "github.com/odpf/stencil/storage/postgres" + "github.com/odpf/stencil/store" + "github.com/odpf/stencil/store/postgres" "github.com/stretchr/testify/assert" ) @@ -48,116 +48,116 @@ func assertNamespace(t *testing.T, expected, actual domain.Namespace) { func TestStorage(t *testing.T) { tearDown(t) - store := getStore(t) + db := getStore(t) ctx := context.Background() n := &domain.Namespace{ID: "test", Format: "protobuf", Compatibility: "FULL", Description: "testDesc"} t.Run("Namespace", func(t *testing.T) { t.Run("create: should create namespace", func(t *testing.T) { - ns, err := store.CreateNamespace(ctx, *n) + ns, err := db.CreateNamespace(ctx, *n) assert.Nil(t, err) assertNamespace(t, *n, ns) }) t.Run("create: should return error on duplicate namespace name", func(t *testing.T) { - _, err := store.CreateNamespace(ctx, *n) - assert.ErrorIs(t, err, storage.ConflictErr) + _, err := db.CreateNamespace(ctx, *n) + assert.ErrorIs(t, err, store.ConflictErr) }) t.Run("update: should update the namespace", func(t *testing.T) { n.Description = "newDescription" n.Format = "avro" - ns, err := store.UpdateNamespace(ctx, *n) + ns, err := db.UpdateNamespace(ctx, *n) assert.Nil(t, err) assertNamespace(t, *n, ns) }) t.Run("update: should return error if namespace not found", func(t *testing.T) { n.ID = "test2" - _, err := store.UpdateNamespace(ctx, *n) - assert.ErrorIs(t, err, storage.NoRowsErr) + _, err := db.UpdateNamespace(ctx, *n) + assert.ErrorIs(t, err, store.NoRowsErr) n.ID = "test" }) t.Run("get: should get the namespace", func(t *testing.T) { - ns, err := store.GetNamespace(ctx, "test") + ns, err := db.GetNamespace(ctx, "test") assert.Nil(t, err) assertNamespace(t, *n, ns) }) t.Run("get: should return the error if namespace not found", func(t *testing.T) { - _, err := store.GetNamespace(ctx, "test1") - assert.ErrorIs(t, err, storage.NoRowsErr) + _, err := db.GetNamespace(ctx, "test1") + assert.ErrorIs(t, err, store.NoRowsErr) }) t.Run("list: should list created namespaces", func(t *testing.T) { - ls, err := store.ListNamespaces(ctx) + ls, err := db.ListNamespaces(ctx) assert.Nil(t, err) assert.Equal(t, []string{"test"}, ls) }) t.Run("delete: should delete namespace", func(t *testing.T) { - err := store.DeleteNamespace(ctx, "test") + err := db.DeleteNamespace(ctx, "test") assert.Nil(t, err) }) }) t.Run("schema", func(t *testing.T) { n := &domain.Namespace{ID: "testschema", Format: "protobuf", Compatibility: "FULL", Description: "testDesc"} - _, err := store.CreateNamespace(ctx, *n) + _, err := db.CreateNamespace(ctx, *n) assert.Nil(t, err) meta := &domain.Metadata{ Format: "avro", } t.Run("create: should create schema", func(t *testing.T) { - versionNumber, err := store.CreateSchema(ctx, n.ID, "sName", meta, "uuid-1", &domain.SchemaFile{ID: "t1", Data: []byte("testdata")}) + versionNumber, err := db.CreateSchema(ctx, n.ID, "sName", meta, "uuid-1", &domain.SchemaFile{ID: "t1", Data: []byte("testdata")}) assert.Nil(t, err) assert.Equal(t, int32(1), versionNumber) }) t.Run("create: should increment version number on new schema", func(t *testing.T) { - versionNumber, err := store.CreateSchema(ctx, n.ID, "sName", meta, "uuid-2", &domain.SchemaFile{ID: "t2", Data: []byte("testdata-2")}) + versionNumber, err := db.CreateSchema(ctx, n.ID, "sName", meta, "uuid-2", &domain.SchemaFile{ID: "t2", Data: []byte("testdata-2")}) assert.Nil(t, err) assert.Equal(t, int32(2), versionNumber) }) t.Run("create: should return same version number if schema is same", func(t *testing.T) { - versionNumber, err := store.CreateSchema(ctx, n.ID, "sName", meta, "uuid-1", &domain.SchemaFile{ID: "t1", Data: []byte("testdata")}) + versionNumber, err := db.CreateSchema(ctx, n.ID, "sName", meta, "uuid-1", &domain.SchemaFile{ID: "t1", Data: []byte("testdata")}) assert.Nil(t, err) assert.Equal(t, int32(1), versionNumber) }) t.Run("list_schemas: should return schema", func(t *testing.T) { - schemaList, err := store.ListSchemas(ctx, "testschema") + schemaList, err := db.ListSchemas(ctx, "testschema") assert.Nil(t, err) assert.Equal(t, []string{"sName"}, schemaList) }) t.Run("list_versions: should return versions for specified schema", func(t *testing.T) { - schemaList, err := store.ListVersions(ctx, "testschema", "sName") + schemaList, err := db.ListVersions(ctx, "testschema", "sName") assert.Nil(t, err) assert.Equal(t, []int32{1, 2}, schemaList) }) t.Run("get: should return specified schema", func(t *testing.T) { - s, err := store.GetSchema(ctx, n.ID, "sName", 1) + s, err := db.GetSchema(ctx, n.ID, "sName", 1) assert.Nil(t, err) assert.Equal(t, []byte("testdata"), s) }) t.Run("getMetadata: should return metadata", func(t *testing.T) { - actual, err := store.GetSchemaMetadata(ctx, n.ID, "sName") + actual, err := db.GetSchemaMetadata(ctx, n.ID, "sName") assert.Nil(t, err) assert.Equal(t, meta.Format, actual.Format) }) t.Run("updateMetadata: should update metadata", func(t *testing.T) { - actual, err := store.UpdateSchemaMetadata(ctx, n.ID, "sName", &domain.Metadata{Compatibility: "FULL"}) + actual, err := db.UpdateSchemaMetadata(ctx, n.ID, "sName", &domain.Metadata{Compatibility: "FULL"}) assert.Nil(t, err) assert.Equal(t, "FULL", actual.Compatibility) }) t.Run("getLatestVersion: should return latest schema version", func(t *testing.T) { - s, err := store.GetLatestVersion(ctx, n.ID, "sName") + s, err := db.GetLatestVersion(ctx, n.ID, "sName") assert.Nil(t, err) assert.Equal(t, int32(2), s) }) t.Run("deleteVersion: should delete specified version schema", func(t *testing.T) { - err := store.DeleteVersion(ctx, n.ID, "sName", int32(2)) + err := db.DeleteVersion(ctx, n.ID, "sName", int32(2)) assert.Nil(t, err) - schemaList, err := store.ListVersions(ctx, "testschema", "sName") + schemaList, err := db.ListVersions(ctx, "testschema", "sName") assert.Nil(t, err) assert.Equal(t, []int32{1}, schemaList) }) t.Run("deleteSchema: should delete specified schema", func(t *testing.T) { - err := store.DeleteSchema(ctx, n.ID, "sName") + err := db.DeleteSchema(ctx, n.ID, "sName") assert.Nil(t, err) - schemaList, err := store.ListSchemas(ctx, "testschema") + schemaList, err := db.ListSchemas(ctx, "testschema") assert.Nil(t, err) assert.Equal(t, 0, len(schemaList)) }) diff --git a/storage/store.go b/store/store.go similarity index 92% rename from storage/store.go rename to store/store.go index 3be81cad..e0a31dda 100644 --- a/storage/store.go +++ b/store/store.go @@ -1,4 +1,4 @@ -package storage +package store import ( "github.com/odpf/stencil/server/domain"