Update storage to new object format

This commit is contained in:
Bel LaPointe
2020-07-22 20:11:52 -06:00
parent 3b174e3d60
commit 4d667e7b11
11 changed files with 232 additions and 62 deletions

View File

@@ -2,12 +2,17 @@ package storage
import (
"context"
"local/whodunit/storage/entity"
"local/whodunit/storage/operator"
"os"
"testing"
"time"
"github.com/google/uuid"
)
func TestIntegration(t *testing.T) {
if len(os.Getenv("INTEGRATION")) > 0 {
if len(os.Getenv("INTEGRATION")) == 0 {
t.Logf("skipping because $INTEGRATION unset")
return
}
@@ -24,13 +29,12 @@ func TestIntegration(t *testing.T) {
clean()
defer clean()
ones := []One{
One{ID: "A", Relation: ":)"},
One{ID: "B", Relation: ":("},
One{ID: "C", Relation: ":/"},
ones := []entity.One{
randomOne(),
randomOne(),
randomOne(),
}
ones[0].Know = []One{ones[len(ones)-1]}
ones[0].Know[0].Relation = ":D"
ones[0].Connections = []entity.Peer{entity.Peer{Name: ones[2].Name, Relationship: ":("}}
t.Run("graph.Insert(...)", func(t *testing.T) {
for _, one := range ones {
@@ -48,12 +52,12 @@ func TestIntegration(t *testing.T) {
}
t.Logf("\nall = %+v", all)
if len(all) != 3 {
t.Fatalf("%+v: %+v", len(all), all)
t.Fatalf("%v: %+v", len(all), all)
}
})
t.Run("graph.List(foo => *)", func(t *testing.T) {
some, err := graph.List(ctx, ones[0].Knows()...)
some, err := graph.List(ctx, ones[0].Peers()...)
if err != nil {
t.Fatal(err)
}
@@ -64,12 +68,12 @@ func TestIntegration(t *testing.T) {
})
t.Run("graph.Update(foo, --bar)", func(t *testing.T) {
err := graph.Update(ctx, ones[0].Min(), Set{"know", []interface{}{}})
err := graph.Update(ctx, ones[0].Query(), operator.Set{entity.Connections, []interface{}{}})
if err != nil {
t.Fatal(err)
}
some, err := graph.List(ctx, ones[0].ID)
some, err := graph.List(ctx, ones[0].Name)
if err != nil {
t.Fatal(err)
}
@@ -78,21 +82,21 @@ func TestIntegration(t *testing.T) {
if len(some) != 1 {
t.Fatal(len(some))
}
if some[0].ID != ones[0].ID {
t.Fatal(some[0].ID)
if some[0].Name != ones[0].Name {
t.Fatal(some[0].Name)
}
if len(some[0].Knows()) > 0 {
t.Fatal(some[0].Knows())
if len(some[0].Peers()) > 0 {
t.Fatal(some[0].Peers())
}
})
t.Run("graph.Update(foo, ++...); graph.Update(foo, --if :()", func(t *testing.T) {
err := graph.Update(ctx, ones[0].Min(), Set{"know", ones})
err := graph.Update(ctx, ones[0].Query(), operator.Set{entity.Connections, []entity.Peer{entity.Peer{Name: "hello", Relationship: ":("}}})
if err != nil {
t.Fatal(err)
}
some1, err := graph.List(ctx, ones[0].ID)
some1, err := graph.List(ctx, ones[0].Name)
if err != nil {
t.Fatal(err)
}
@@ -100,16 +104,16 @@ func TestIntegration(t *testing.T) {
if len(some1) != 1 {
t.Fatal(len(some1))
}
if len(some1[0].Knows()) != len(ones) {
t.Fatal(some1[0].Knows())
if len(some1[0].Peers()) != 1 {
t.Fatal(some1[0].Peers())
}
err = graph.Update(ctx, ones[0].Min(), PopIf{"know", map[string]string{"relation": ":("}})
err = graph.Update(ctx, ones[0].Query(), operator.PopIf{entity.Connections, map[string]string{entity.Relationship: ":("}})
if err != nil {
t.Fatal(err)
}
some2, err := graph.List(ctx, ones[0].ID)
some2, err := graph.List(ctx, ones[0].Name)
if err != nil {
t.Fatal(err)
}
@@ -118,11 +122,23 @@ func TestIntegration(t *testing.T) {
if len(some1) != len(some2) {
t.Fatal(len(some2))
}
if len(some1[0].Knows()) == len(some2[0].Knows()) {
t.Fatal(len(some2[0].Knows()))
if len(some1[0].Connections) == len(some2[0].Connections) {
t.Fatal(len(some2[0].Connections))
}
if len(some2[0].Knows()) == len(ones) {
t.Fatal(len(some2[0].Knows()))
if len(some2[0].Connections) == len(ones) {
t.Fatal(len(some2[0].Connections))
}
})
}
func randomOne() entity.One {
return entity.One{
Name: uuid.New().String()[:5],
Type: "Humman",
Title: "Biggus",
Image: "/path/to.jpg",
Text: "tee hee xd",
Modified: time.Now().UnixNano(),
Connections: []entity.Peer{},
}
}