Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into tk-ehr-disable-sche…
Browse files Browse the repository at this point in the history
…duled-reports
  • Loading branch information
toddkazakov committed Oct 25, 2024
2 parents 2b21ec7 + 3a944d5 commit 4404cc9
Show file tree
Hide file tree
Showing 65 changed files with 1,206 additions and 1,481 deletions.
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ addons:
repo_token: 91ded9b66924acbe830541ab3593daf535f05f7c6db91b5cbd2d26dcf37da0b8

script:
- make ci-generate ci-build ci-test ci-deploy ci-docker
- make ci-generate ci-build ci-test ci-deploy ci-docker TIMING_CMD="time -p"
# Testing to see if go-ci-test catches the same failures as ci-test. If I
# understand how travis works, this means that go-ci-test will run even if
# ci-test fails, so we can see if they're catching the same
# things. Likewise, if go-ci-test fails, we can compare that to ci-test.
- make go-ci-test TIMING_CMD="time -p"
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ GINKGO_CI_FLAGS += $(GINKGO_CI_WATCH_FLAGS) --randomize-suites --keep-going
GOTEST_PKGS ?= ./...
GOTEST_FLAGS ?=

TIMING_CMD ?=

ifdef TRAVIS_BRANCH
ifdef TRAVIS_COMMIT
DOCKER:=true
Expand Down Expand Up @@ -212,7 +214,7 @@ test-watch: ginkgo

ci-test: ginkgo
@echo "ginkgo $(GINKGO_FLAGS) $(GINKGO_CI_FLAGS) $(TEST)"
@cd $(ROOT_DIRECTORY) && . ./env.test.sh && ginkgo $(GINKGO_FLAGS) $(GINKGO_CI_FLAGS) $(TEST)
@cd $(ROOT_DIRECTORY) && . ./env.test.sh && $(TIMING_CMD) ginkgo $(GINKGO_FLAGS) $(GINKGO_CI_FLAGS) $(TEST)

ci-test-until-failure: ginkgo
@echo "ginkgo $(GINKGO_FLAGS) $(GINKGO_CI_FLAGS) -untilItFails $(TEST)"
Expand All @@ -223,7 +225,11 @@ ci-test-watch: ginkgo
@cd $(ROOT_DIRECTORY) && . ./env.test.sh && ginkgo watch $(GINKGO_FLAGS) $(GINKGO_CI_WATCH_FLAGS) $(TEST)

go-test:
. ./env.test.sh && go test $(GOTEST_FLAGS) $(GOTEST_PKGS)
. ./env.test.sh && $(TIMING_CMD) go test $(GOTEST_FLAGS) $(GOTEST_PKGS)

go-ci-test: GOTEST_FLAGS += -count=1 -race -shuffle=on -cover
go-ci-test: GOTEST_PKGS = ./...
go-ci-test: go-test

deploy: clean-deploy deploy-services deploy-migrations deploy-tools

Expand Down
21 changes: 7 additions & 14 deletions blob/store/structured/mongo/blob_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import (
"github.com/tidepool-org/platform/pointer"
"github.com/tidepool-org/platform/request"
requestTest "github.com/tidepool-org/platform/request/test"
storeStructuredMongo "github.com/tidepool-org/platform/store/structured/mongo"
storeStructuredMongoTest "github.com/tidepool-org/platform/store/structured/mongo/test"
"github.com/tidepool-org/platform/test"
userTest "github.com/tidepool-org/platform/user/test"
)
Expand Down Expand Up @@ -75,32 +73,27 @@ func AsInterfaceArray(blobs blob.BlobArray) []interface{} {
}

var _ = Describe("Mongo", Label("mongodb", "slow", "integration"), func() {
var config *storeStructuredMongo.Config
var logger *logTest.Logger
var store *blobStoreStructuredMongo.Store

BeforeEach(func() {
config = storeStructuredMongoTest.NewConfig()
logger = logTest.NewLogger()
})

AfterEach(func() {
if store != nil {
store.Terminate(context.Background())
}
})

Context("with a new store", func() {
var blobsCollection *mongo.Collection

BeforeEach(func() {
var err error
store, err = blobStoreStructuredMongo.NewStore(config)
Expect(err).ToNot(HaveOccurred())
Expect(store).ToNot(BeNil())
store = GetSuiteStore()
blobsCollection = store.GetCollection("blobs")
})

AfterEach(func() {
if blobsCollection != nil {
blobsCollection.DeleteMany(context.Background(), bson.D{})
}
})

Context("NewBlobRepository", func() {
var repository blobStoreStructured.BlobRepository

Expand Down
21 changes: 7 additions & 14 deletions blob/store/structured/mongo/devicelogs_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,31 @@ import (
"github.com/tidepool-org/platform/pointer"
"github.com/tidepool-org/platform/request"
requestTest "github.com/tidepool-org/platform/request/test"
storeStructuredMongo "github.com/tidepool-org/platform/store/structured/mongo"
storeStructuredMongoTest "github.com/tidepool-org/platform/store/structured/mongo/test"
userTest "github.com/tidepool-org/platform/user/test"
)

var _ = Describe("Mongo", func() {
var config *storeStructuredMongo.Config
var logger *logTest.Logger
var store *blobStoreStructuredMongo.Store

BeforeEach(func() {
config = storeStructuredMongoTest.NewConfig()
logger = logTest.NewLogger()
})

AfterEach(func() {
if store != nil {
store.Terminate(context.Background())
}
})

Context("with a new store", func() {
var deviceLogsCollection *mongo.Collection

BeforeEach(func() {
var err error
store, err = blobStoreStructuredMongo.NewStore(config)
Expect(err).ToNot(HaveOccurred())
Expect(store).ToNot(BeNil())
store = GetSuiteStore()
deviceLogsCollection = store.GetCollection("deviceLogs")
})

AfterEach(func() {
if deviceLogsCollection != nil {
deviceLogsCollection.DeleteMany(context.Background(), bson.D{})
}
})

Context("NewDeviceLogsRepository", func() {
var deviceLogsRepository blobStoreStructured.DeviceLogsRepository

Expand Down
7 changes: 4 additions & 3 deletions blob/store/structured/mongo/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ func NewStore(config *storeStructuredMongo.Config) (*Store, error) {
if err != nil {
return nil, err
}
return NewStoreFromBase(store), nil
}

return &Store{
Store: store,
}, nil
func NewStoreFromBase(base *storeStructuredMongo.Store) *Store {
return &Store{Store: base}
}

func (s *Store) EnsureIndexes() error {
Expand Down
19 changes: 19 additions & 0 deletions blob/store/structured/mongo/mongo_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
package mongo_test

import (
"sync"
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

blobStoreStructuredMongo "github.com/tidepool-org/platform/blob/store/structured/mongo"
storeStructuredMongoTest "github.com/tidepool-org/platform/store/structured/mongo/test"
"github.com/tidepool-org/platform/test"
)

func TestSuite(t *testing.T) {
test.Test(t)
}

var suiteStore *blobStoreStructuredMongo.Store
var suiteStoreOnce sync.Once

func GetSuiteStore() *blobStoreStructuredMongo.Store {
GinkgoHelper()
suiteStoreOnce.Do(func() {
base := storeStructuredMongoTest.GetSuiteStore()
suiteStore = blobStoreStructuredMongo.NewStoreFromBase(base)
Expect(suiteStore.EnsureIndexes()).To(Succeed())
})
return suiteStore
}
182 changes: 90 additions & 92 deletions blob/store/structured/mongo/mongo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,123 +6,121 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"

blobStoreStructuredMongo "github.com/tidepool-org/platform/blob/store/structured/mongo"
"github.com/tidepool-org/platform/errors"
errorsTest "github.com/tidepool-org/platform/errors/test"
storeStructuredMongo "github.com/tidepool-org/platform/store/structured/mongo"
storeStructuredMongoTest "github.com/tidepool-org/platform/store/structured/mongo/test"
)

var _ = Describe("Mongo", func() {
var config *storeStructuredMongo.Config
var store *blobStoreStructuredMongo.Store

BeforeEach(func() {
config = storeStructuredMongoTest.NewConfig()
})
Context("NewStore", func() {
var createStore *blobStoreStructuredMongo.Store

AfterEach(func() {
if store != nil {
store.Terminate(context.Background())
}
})
AfterEach(func() {
if createStore != nil {
createStore.Terminate(context.Background())
}
})

Context("NewStore", func() {
It("returns an error when unsuccessful", func() {
var err error
store, err = blobStoreStructuredMongo.NewStore(nil)
createStore, err := blobStoreStructuredMongo.NewStore(nil)
errorsTest.ExpectEqual(err, errors.New("database config is empty"))
Expect(store).To(BeNil())
Expect(createStore).To(BeNil())
})

It("returns a new store and no error when successful", func() {
var err error
store, err = blobStoreStructuredMongo.NewStore(config)
config := storeStructuredMongoTest.NewConfig()
createStore, err := blobStoreStructuredMongo.NewStore(config)
Expect(err).ToNot(HaveOccurred())
Expect(store).ToNot(BeNil())
Expect(createStore).ToNot(BeNil())
})
})

Context("EnsureIndexes", func() {
Context("EnsureIndexes", func() {
var store *blobStoreStructuredMongo.Store
var deviceLogsCollection *mongo.Collection
var blobsCollection *mongo.Collection

var deviceLogsCollection *mongo.Collection
var blobsCollection *mongo.Collection
BeforeEach(func() {
store = GetSuiteStore()
deviceLogsCollection = store.GetCollection("deviceLogs")
blobsCollection = store.GetCollection("blobs")
})

BeforeEach(func() {
var err error
store, err = blobStoreStructuredMongo.NewStore(config)
Expect(err).ToNot(HaveOccurred())
Expect(store).ToNot(BeNil())
deviceLogsCollection = store.GetCollection("deviceLogs")
blobsCollection = store.GetCollection("blobs")
})
AfterEach(func() {
ctx := context.Background()
if deviceLogsCollection != nil {
deviceLogsCollection.DeleteMany(ctx, bson.D{})
}
if blobsCollection != nil {
blobsCollection.DeleteMany(ctx, bson.D{})
}
})

It("deviceLogs returns successfully", func() {
Expect(store.EnsureIndexes()).To(Succeed())
cursor, err := deviceLogsCollection.Indexes().List(context.Background())
Expect(err).ToNot(HaveOccurred())
Expect(cursor).ToNot(BeNil())
var indexes []storeStructuredMongoTest.MongoIndex
err = cursor.All(context.Background(), &indexes)
Expect(err).ToNot(HaveOccurred())
It("deviceLogs returns successfully", func() {
cursor, err := deviceLogsCollection.Indexes().List(context.Background())
Expect(err).ToNot(HaveOccurred())
Expect(cursor).ToNot(BeNil())
var indexes []storeStructuredMongoTest.MongoIndex
err = cursor.All(context.Background(), &indexes)
Expect(err).ToNot(HaveOccurred())

Expect(indexes).To(ConsistOf(
MatchFields(IgnoreExtras, Fields{
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("_id")),
}),
MatchFields(IgnoreExtras, Fields{
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("id")),
"Unique": Equal(true),
}),
MatchFields(IgnoreExtras, Fields{
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("userId", "startAtTime")),
}),
MatchFields(IgnoreExtras, Fields{
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("userId", "endAtTime")),
}),
MatchFields(IgnoreExtras, Fields{
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("startAtTime")),
}),
MatchFields(IgnoreExtras, Fields{
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("endAtTime")),
}),
))
})
Expect(indexes).To(ConsistOf(
MatchFields(IgnoreExtras, Fields{
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("_id")),
}),
MatchFields(IgnoreExtras, Fields{
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("id")),
"Unique": Equal(true),
}),
MatchFields(IgnoreExtras, Fields{
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("userId", "startAtTime")),
}),
MatchFields(IgnoreExtras, Fields{
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("userId", "endAtTime")),
}),
MatchFields(IgnoreExtras, Fields{
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("startAtTime")),
}),
MatchFields(IgnoreExtras, Fields{
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("endAtTime")),
}),
))
})

It("blobs returns successfully", func() {
Expect(store.EnsureIndexes()).To(Succeed())
cursor, err := blobsCollection.Indexes().List(context.Background())
Expect(err).ToNot(HaveOccurred())
Expect(cursor).ToNot(BeNil())
var indexes []storeStructuredMongoTest.MongoIndex
err = cursor.All(context.Background(), &indexes)
Expect(err).ToNot(HaveOccurred())
It("blobs returns successfully", func() {
cursor, err := blobsCollection.Indexes().List(context.Background())
Expect(err).ToNot(HaveOccurred())
Expect(cursor).ToNot(BeNil())
var indexes []storeStructuredMongoTest.MongoIndex
err = cursor.All(context.Background(), &indexes)
Expect(err).ToNot(HaveOccurred())

Expect(indexes).To(ConsistOf(
MatchFields(IgnoreExtras, Fields{
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("_id")),
}),
MatchFields(IgnoreExtras, Fields{
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("id")),
"Background": Equal(true),
"Unique": Equal(true),
}),
MatchFields(IgnoreExtras, Fields{
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("userId")),
"Background": Equal(true),
}),
MatchFields(IgnoreExtras, Fields{
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("mediaType")),
"Background": Equal(true),
}),
MatchFields(IgnoreExtras, Fields{
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("status")),
"Background": Equal(true),
}),
))
})
Expect(indexes).To(ConsistOf(
MatchFields(IgnoreExtras, Fields{
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("_id")),
}),
MatchFields(IgnoreExtras, Fields{
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("id")),
"Background": Equal(true),
"Unique": Equal(true),
}),
MatchFields(IgnoreExtras, Fields{
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("userId")),
"Background": Equal(true),
}),
MatchFields(IgnoreExtras, Fields{
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("mediaType")),
"Background": Equal(true),
}),
MatchFields(IgnoreExtras, Fields{
"Key": Equal(storeStructuredMongoTest.MakeKeySlice("status")),
"Background": Equal(true),
}),
))
})
})

})
Loading

0 comments on commit 4404cc9

Please sign in to comment.