-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move package to root and move tests to _test package
- Loading branch information
1 parent
8adc9dd
commit 477ce2a
Showing
10 changed files
with
187 additions
and
198 deletions.
There are no files selected for viewing
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{})) | ||
}) | ||
}) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package gomongo | ||
package gomongo_test | ||
|
||
import ( | ||
"testing" | ||
|
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
gomongo/testcontainer_helper_test.go → testcontainer_helper_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package gomongo | ||
package gomongo_test | ||
|
||
import ( | ||
"context" | ||
|