Change connections storage from arr to map
This commit is contained in:
@@ -2,6 +2,7 @@ package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"local/dndex/storage/entity"
|
||||
"local/dndex/storage/operator"
|
||||
"os"
|
||||
@@ -34,7 +35,7 @@ func TestIntegration(t *testing.T) {
|
||||
randomOne(),
|
||||
randomOne(),
|
||||
}
|
||||
ones[0].Connections = []entity.One{entity.One{Name: ones[2].Name, Relationship: ":("}}
|
||||
ones[0].Connections = map[string]entity.One{ones[2].Name: entity.One{Name: ones[2].Name, Relationship: ":("}}
|
||||
|
||||
t.Run("graph.Insert(...)", func(t *testing.T) {
|
||||
for _, one := range ones {
|
||||
@@ -68,7 +69,7 @@ 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, []interface{}{}})
|
||||
err := graph.Update(ctx, ones[0].Query(), operator.Set{entity.Connections, map[string]interface{}{}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -90,8 +91,11 @@ func TestIntegration(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("graph.Update(foo, ++...); graph.Update(foo, --if :()", func(t *testing.T) {
|
||||
err := graph.Update(ctx, ones[0].Query(), operator.Set{entity.Connections, []entity.One{entity.One{Name: "hello", Relationship: ":("}}})
|
||||
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{
|
||||
"hello": entity.One{Name: "hello", Relationship: ":("},
|
||||
"world": entity.One{Name: "world", Relationship: ":("},
|
||||
}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -104,29 +108,24 @@ func TestIntegration(t *testing.T) {
|
||||
if len(some1) != 1 {
|
||||
t.Fatal(len(some1))
|
||||
}
|
||||
if len(some1[0].Peers()) != 1 {
|
||||
if len(some1[0].Peers()) != 2 {
|
||||
t.Fatal(some1[0].Peers())
|
||||
}
|
||||
|
||||
err = graph.Update(ctx, ones[0].Query(), operator.PopIf{entity.Connections, map[string]string{entity.Relationship: ":("}})
|
||||
err = graph.Update(ctx, 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)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Logf("sm2 = %+v", some2[0])
|
||||
|
||||
if len(some1) != len(some2) {
|
||||
if len(some2) != 1 {
|
||||
t.Fatal(len(some2))
|
||||
}
|
||||
if len(some1[0].Connections) == len(some2[0].Connections) {
|
||||
t.Fatal(len(some2[0].Connections))
|
||||
}
|
||||
if len(some2[0].Connections) == len(ones) {
|
||||
t.Fatal(len(some2[0].Connections))
|
||||
if len(some2[0].Peers()) != 1 {
|
||||
t.Fatal(some2[0].Peers())
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -139,6 +138,6 @@ func randomOne() entity.One {
|
||||
Image: "/path/to.jpg",
|
||||
Text: "tee hee xd",
|
||||
Modified: time.Now().UnixNano(),
|
||||
Connections: []entity.One{},
|
||||
Connections: map[string]entity.One{},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user