Skip to content

Commit

Permalink
move package to root and move tests to _test package
Browse files Browse the repository at this point in the history
  • Loading branch information
victorguarana committed May 3, 2024
1 parent 8adc9dd commit 477ce2a
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 198 deletions.
File renamed without changes.
166 changes: 84 additions & 82 deletions gomongo/collection_test.go → collection_test.go

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
101 changes: 101 additions & 0 deletions database_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package gomongo_test

import (
"context"
"time"

"github.com/testcontainers/testcontainers-go/modules/mongodb"
"github.com/victorguarana/gomongo"

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

var _ = Describe("NewDatabase", Ordered, func() {
var (
mongodbContainer *mongodb.MongoDBContainer
mongodbContainerURI string
connectionSettings gomongo.ConnectionSettings
)

BeforeAll(func() {
mongodbContainer, mongodbContainerURI = runMongoContainer(context.Background())
})

Context("when connection settings param is invalid", func() {
Context("when URI is empty", func() {
It("returns ErrInvalidSettings", func() {
connectionSettings := gomongo.ConnectionSettings{
DatabaseName: "test",
}

receivedDatabase, receivedErr := gomongo.NewDatabase(context.Background(), connectionSettings)
Expect(receivedErr).To(MatchError(gomongo.ErrInvalidSettings))
Expect(receivedErr).To(MatchError(ContainSubstring("URI can not be empty")))
Expect(receivedDatabase).To(Equal(gomongo.Database{}))
})
})

Context("when DatabaseName is empty", func() {
It("returns ErrInvalidSettings", func() {
connectionSettings := gomongo.ConnectionSettings{
URI: mongodbContainerURI,
}

receivedDatabase, receivedErr := gomongo.NewDatabase(context.Background(), connectionSettings)
Expect(receivedErr).To(MatchError(gomongo.ErrInvalidSettings))
Expect(receivedErr).To(MatchError(ContainSubstring("Database Name can not be empty")))
Expect(receivedDatabase).To(Equal(gomongo.Database{}))
})
})
})

Context("when connection settings param is valid", func() {
Context("when mongo is up", func() {
Context("when all settings are filled", func() {
It("returns nil", func() {
connectionSettings := gomongo.ConnectionSettings{
URI: mongodbContainerURI,
DatabaseName: "test",
ConnectionTimeout: 10 * time.Second,
}

receivedDatabase, receivedErr := gomongo.NewDatabase(context.Background(), connectionSettings)
Expect(receivedErr).NotTo(HaveOccurred())
Expect(receivedDatabase).NotTo(Equal(gomongo.Database{}))
})
})

Context("when timeout is empty", func() {
It("returns nil", func() {
connectionSettings := gomongo.ConnectionSettings{
URI: mongodbContainerURI,
DatabaseName: "test",
}

receivedDatabase, receivedErr := gomongo.NewDatabase(context.Background(), connectionSettings)
Expect(receivedErr).NotTo(HaveOccurred())
Expect(receivedDatabase).NotTo(Equal(gomongo.Database{}))
})
})
})

Context("when mongo is down", func() {
BeforeAll(func() {
terminateMongoContainer(mongodbContainer, context.Background())
})

It("returns error", func() {
connectionSettings = gomongo.ConnectionSettings{
URI: mongodbContainerURI,
DatabaseName: "test",
ConnectionTimeout: 1 * time.Second,
}

receivedDatabase, receivedErr := gomongo.NewDatabase(context.Background(), connectionSettings)
Expect(receivedErr).To(MatchError(gomongo.ErrGomongoCanNotConnect))
Expect(receivedDatabase).To(Equal(gomongo.Database{}))
})
})
})
})
63 changes: 0 additions & 63 deletions gomongo/connection_test.go

This file was deleted.

51 changes: 0 additions & 51 deletions gomongo/database_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion gomongo/gomongo_suite_test.go → gomongo_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gomongo
package gomongo_test

import (
"testing"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gomongo
package gomongo_test

import (
"context"
Expand Down

0 comments on commit 477ce2a

Please sign in to comment.