Skip to content

Commit

Permalink
fix(internal/database): fix unit tests for offline store
Browse files Browse the repository at this point in the history
  • Loading branch information
jinghancc committed Nov 11, 2021
1 parent c7dd3da commit 8a3c0f5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
6 changes: 3 additions & 3 deletions internal/database/offline/postgres/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/oom-ai/oomstore/internal/database/dbutil"
"github.com/oom-ai/oomstore/internal/database/offline"
"github.com/oom-ai/oomstore/pkg/oomstore/types"
"github.com/oom-ai/oomstore/pkg/oomstore/typesv2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -17,11 +17,11 @@ func TestExport(t *testing.T) {

// make test entities
ctx := context.Background()
entity := &types.Entity{
entity := &typesv2.Entity{
Name: "device",
Length: 10,
}
features := types.FeatureList{
features := typesv2.FeatureList{
{
Name: "model",
DBValueType: "VARCHAR(32)",
Expand Down
6 changes: 3 additions & 3 deletions internal/database/offline/postgres/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ import (
"strings"
"testing"

"github.com/oom-ai/oomstore/pkg/oomstore/typesv2"
"github.com/stretchr/testify/assert"

"github.com/oom-ai/oomstore/internal/database/offline"
"github.com/oom-ai/oomstore/pkg/oomstore/types"
)

func TestImport(t *testing.T) {
db := initAndOpenDB(t)
defer db.Close()

entity := types.Entity{
entity := typesv2.Entity{
Name: "device",
Length: 16,
}

opt := offline.ImportOpt{
GroupName: "device",
Entity: &entity,
Features: []*types.Feature{
Features: []*typesv2.Feature{
{
Name: "model",
DBValueType: "invalid-db-value-type"},
Expand Down
40 changes: 21 additions & 19 deletions internal/database/offline/postgres/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"testing"

"github.com/oom-ai/oomstore/internal/database/dbutil"
"github.com/oom-ai/oomstore/internal/database/metadatav2"
"github.com/oom-ai/oomstore/internal/database/offline"
"github.com/oom-ai/oomstore/internal/database/offline/postgres"
"github.com/oom-ai/oomstore/pkg/oomstore/types"
"github.com/oom-ai/oomstore/pkg/oomstore/typesv2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -20,7 +22,7 @@ func TestJoin(t *testing.T) {
ctx := context.Background()

// prepare test data
entity := &types.Entity{
entity := &typesv2.Entity{
Name: "device",
Length: 10,
}
Expand All @@ -36,7 +38,7 @@ func TestJoin(t *testing.T) {
{
description: "no features",
opt: offline.JoinOpt{
FeatureMap: make(map[string]types.FeatureList),
FeatureMap: make(map[string]typesv2.FeatureList),
},
expected: nil,
},
Expand Down Expand Up @@ -87,7 +89,7 @@ func TestJoin(t *testing.T) {
}
}

func prepareTestData(ctx context.Context, db *postgres.DB, t *testing.T, entity *types.Entity, oneGroupFeatures types.FeatureList, twoGroupFeatureMap map[string]types.FeatureList) {
func prepareTestData(ctx context.Context, db *postgres.DB, t *testing.T, entity *typesv2.Entity, oneGroupFeatures typesv2.FeatureList, twoGroupFeatureMap map[string]typesv2.FeatureList) {
schema := dbutil.BuildFeatureDataTableSchema("device_basic_1", entity, oneGroupFeatures)
_, err := db.ExecContext(ctx, schema)
require.NoError(t, err)
Expand Down Expand Up @@ -124,34 +126,34 @@ func insertTestDataToAdvanced(db *postgres.DB, ctx context.Context, tableName st
return err
}

func prepareFeatures(oneGroup bool) (types.FeatureList, map[string]types.FeatureList) {
price := &types.Feature{
func prepareFeatures(oneGroup bool) (typesv2.FeatureList, map[string]typesv2.FeatureList) {
price := &typesv2.Feature{
Name: "price",
DBValueType: "INT",
GroupName: "device_basic",
GroupID: 1,
}
model := &types.Feature{
model := &typesv2.Feature{
Name: "model",
DBValueType: "VARCHAR(32)",
GroupName: "device_basic",
GroupID: 1,
}
isActive := &types.Feature{
isActive := &typesv2.Feature{
Name: "is_active",
DBValueType: "boolean",
GroupName: "device_advanced",
GroupID: 2,
}

if oneGroup {
features := types.FeatureList{model, price}
featureMap := map[string]types.FeatureList{
features := typesv2.FeatureList{model, price}
featureMap := map[string]typesv2.FeatureList{
"device_basic": {
model, price,
},
}
return features, featureMap
} else {
features := types.FeatureList{model, price, isActive}
featureMap := map[string]types.FeatureList{
features := typesv2.FeatureList{model, price, isActive}
featureMap := map[string]typesv2.FeatureList{
"device_basic": {
model, price,
},
Expand All @@ -161,8 +163,8 @@ func prepareFeatures(oneGroup bool) (types.FeatureList, map[string]types.Feature
}
}

func prepareRevisionRanges(oneGroup bool) map[string][]*types.RevisionRange {
basic := []*types.RevisionRange{
func prepareRevisionRanges(oneGroup bool) map[string][]*metadatav2.RevisionRange {
basic := []*metadatav2.RevisionRange{
{
MinRevision: 1,
MaxRevision: 15,
Expand All @@ -174,19 +176,19 @@ func prepareRevisionRanges(oneGroup bool) map[string][]*types.RevisionRange {
DataTable: "device_basic_15",
},
}
advanced := []*types.RevisionRange{
advanced := []*metadatav2.RevisionRange{
{
MinRevision: 5,
MaxRevision: math.MaxInt64,
DataTable: "device_advanced_5",
},
}
if oneGroup {
return map[string][]*types.RevisionRange{
return map[string][]*metadatav2.RevisionRange{
"device_basic": basic,
}
}
return map[string][]*types.RevisionRange{
return map[string][]*metadatav2.RevisionRange{
"device_basic": basic,
"device_advanced": advanced,
}
Expand Down

0 comments on commit 8a3c0f5

Please sign in to comment.