-
Notifications
You must be signed in to change notification settings - Fork 19
/
namespace_test.go
43 lines (36 loc) · 1.17 KB
/
namespace_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package mongonet
import "testing"
func testNamespaceIsCommand(test *testing.T, ns string, correct bool) {
if NamespaceIsCommand(ns) != correct {
test.Errorf("wrong result for %s", ns)
}
}
func TestNamespaceIsCommand(test *testing.T) {
testNamespaceIsCommand(test, "foo", false)
testNamespaceIsCommand(test, "foo.bar", false)
testNamespaceIsCommand(test, "foo.$cmd", true)
}
func testNamespaceToDB(test *testing.T, ns string, db string) {
s := NamespaceToDB(ns)
if s != db {
test.Errorf("NamespaceToDB wrong %s %s %s", ns, db, s)
}
}
func TestNamespaceToDB(test *testing.T) {
testNamespaceToDB(test, "foo", "foo")
testNamespaceToDB(test, "", "")
testNamespaceToDB(test, "foo.bar", "foo")
testNamespaceToDB(test, "foo.bar.abc", "foo")
}
func testNamespaceToCollection(test *testing.T, ns string, db string) {
s := NamespaceToCollection(ns)
if s != db {
test.Errorf("NamespaceToCollection wrong %s %s %s", ns, db, s)
}
}
func TestNamespaceToCollection(test *testing.T) {
testNamespaceToCollection(test, "foo", "")
testNamespaceToCollection(test, "", "")
testNamespaceToCollection(test, "foo.bar", "bar")
testNamespaceToCollection(test, "foo.bar.abc", "bar.abc")
}