diff options
Diffstat (limited to 'src/mongo/gotools/common/db/namespaces_test.go')
-rw-r--r-- | src/mongo/gotools/common/db/namespaces_test.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/mongo/gotools/common/db/namespaces_test.go b/src/mongo/gotools/common/db/namespaces_test.go new file mode 100644 index 00000000000..0e390a2f43c --- /dev/null +++ b/src/mongo/gotools/common/db/namespaces_test.go @@ -0,0 +1,52 @@ +package db + +import ( + "fmt" + "testing" + + . "github.com/smartystreets/goconvey/convey" +) + +type stripDBFromNamespaceTestCase struct { + inputNamespace string + inputDBName string + + outputNamespace string + outputError error +} + +func TestStripDBFromNamespace(t *testing.T) { + Convey("When testing StripDBFromNamespace with cases", t, func() { + testCases := []stripDBFromNamespaceTestCase{ + { + inputNamespace: "database.col", + inputDBName: "database", + + outputNamespace: "col", + outputError: nil, + }, + { + inputNamespace: "database2.col", + inputDBName: "database", + + outputNamespace: "", + outputError: fmt.Errorf("namespace 'database2.col' format is invalid - expected to start with 'database.'"), + }, + { + inputNamespace: "database.col", + inputDBName: "notAPrefix", + + outputNamespace: "", + outputError: fmt.Errorf("namespace 'database.col' format is invalid - expected to start with 'notAPrefix.'"), + }, + } + Convey("cases should match expected", func() { + for _, tc := range testCases { + resultNamespace, resultError := StripDBFromNamespace(tc.inputNamespace, tc.inputDBName) + So(resultError, ShouldResemble, tc.outputError) + So(resultNamespace, ShouldEqual, tc.outputNamespace) + } + }) + }) + +} |