Add namespacing for users

This commit is contained in:
Bel LaPointe
2020-07-22 22:20:06 -06:00
parent 1a6973b02c
commit 660cd64262
5 changed files with 45 additions and 37 deletions

View File

@@ -21,11 +21,10 @@ func TestIntegration(t *testing.T) {
os.Args = os.Args[:1]
graph := NewGraph()
graph.mongo.db = "test-db"
graph.mongo.col = "test-col"
ctx, can := context.WithCancel(context.TODO())
defer can()
clean := func() {
graph.mongo.client.Database(graph.mongo.db).Collection(graph.mongo.col).DeleteMany(ctx, map[string]interface{}{})
graph.mongo.client.Database(graph.mongo.db).Collection("col").DeleteMany(ctx, map[string]interface{}{})
}
clean()
defer clean()
@@ -39,7 +38,7 @@ func TestIntegration(t *testing.T) {
t.Run("graph.Insert(...)", func(t *testing.T) {
for _, one := range ones {
err := graph.Insert(ctx, one)
err := graph.Insert(ctx, "col", one)
if err != nil {
t.Fatal(err)
}
@@ -47,7 +46,7 @@ func TestIntegration(t *testing.T) {
})
t.Run("graph.List", func(t *testing.T) {
all, err := graph.List(ctx)
all, err := graph.List(ctx, "col")
if err != nil {
t.Fatal(err)
}
@@ -58,7 +57,7 @@ func TestIntegration(t *testing.T) {
})
t.Run("graph.List(foo => *)", func(t *testing.T) {
some, err := graph.List(ctx, ones[0].Peers()...)
some, err := graph.List(ctx, "col", ones[0].Peers()...)
if err != nil {
t.Fatal(err)
}
@@ -69,12 +68,12 @@ func TestIntegration(t *testing.T) {
})
t.Run("graph.Update(foo, --bar)", func(t *testing.T) {
err := graph.Update(ctx, ones[0].Query(), operator.Set{entity.Connections, map[string]interface{}{}})
err := graph.Update(ctx, "col", ones[0].Query(), operator.Set{entity.Connections, map[string]interface{}{}})
if err != nil {
t.Fatal(err)
}
some, err := graph.List(ctx, ones[0].Name)
some, err := graph.List(ctx, "col", ones[0].Name)
if err != nil {
t.Fatal(err)
}
@@ -92,7 +91,7 @@ func TestIntegration(t *testing.T) {
})
t.Run("graph.Update(foo, +=2); graph.Update(foo, -=1)", func(t *testing.T) {
err := graph.Update(ctx, ones[0].Query(), operator.Set{entity.Connections, map[string]entity.One{
err := graph.Update(ctx, "col", ones[0].Query(), operator.Set{entity.Connections, map[string]entity.One{
"hello": entity.One{Name: "hello", Relationship: ":("},
"world": entity.One{Name: "world", Relationship: ":("},
}})
@@ -100,7 +99,7 @@ func TestIntegration(t *testing.T) {
t.Fatal(err)
}
some1, err := graph.List(ctx, ones[0].Name)
some1, err := graph.List(ctx, "col", ones[0].Name)
if err != nil {
t.Fatal(err)
}
@@ -112,11 +111,11 @@ func TestIntegration(t *testing.T) {
t.Fatal(some1[0].Peers())
}
err = graph.Update(ctx, ones[0].Query(), operator.Unset(fmt.Sprintf("%s.world", entity.Connections)))
err = graph.Update(ctx, "col", ones[0].Query(), operator.Unset(fmt.Sprintf("%s.world", entity.Connections)))
if err != nil {
t.Fatal(err)
}
some2, err := graph.List(ctx, ones[0].Name)
some2, err := graph.List(ctx, "col", ones[0].Name)
if err != nil {
t.Fatal(err)
}