patch to add existing as new connnection
parent
b2739b800c
commit
a616d4d1eb
|
|
@ -10,6 +10,7 @@ import (
|
|||
"local/dndex/storage/operator"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/buger/jsonparser"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
|
|
@ -174,7 +175,7 @@ func whoPatch(namespace string, g storage.Graph, w http.ResponseWriter, r *http.
|
|||
}
|
||||
relationship := one.Relationship
|
||||
one.Relationship = ""
|
||||
if err := g.Insert(r.Context(), namespace, one); err != nil {
|
||||
if err := g.Insert(r.Context(), namespace, one); err != nil && !strings.Contains(err.Error(), "ollision") {
|
||||
return err
|
||||
}
|
||||
one.Relationship = relationship
|
||||
|
|
|
|||
|
|
@ -193,6 +193,52 @@ func TestWho(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
want = ones[4]
|
||||
t.Run("patch real against existing", func(t *testing.T) {
|
||||
from := ones[4]
|
||||
push := ones[10].Peer()
|
||||
push.Relationship = "spawn"
|
||||
b, err := json.Marshal(push)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r := httptest.NewRequest(http.MethodPatch, "/who?namespace=col&id="+from.Name, bytes.NewReader(b))
|
||||
w := httptest.NewRecorder()
|
||||
handler.ServeHTTP(w, r)
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("%d: %s", w.Code, w.Body.Bytes())
|
||||
}
|
||||
got := entity.One{}
|
||||
if err := json.NewDecoder(w.Body).Decode(&got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if fmt.Sprint(got) == fmt.Sprint(from) {
|
||||
t.Fatal(got)
|
||||
}
|
||||
got.Modified = 0
|
||||
from.Modified = 0
|
||||
if len(got.Connections) != len(from.Connections)+1 {
|
||||
t.Fatal(len(got.Connections), len(from.Connections)+1)
|
||||
}
|
||||
gotPush, ok := got.Connections[push.Name]
|
||||
if !ok {
|
||||
t.Fatal("cant find pushed connection from remote")
|
||||
}
|
||||
got.Connections = nil
|
||||
from.Connections = nil
|
||||
if fmt.Sprint(got) != fmt.Sprint(from) {
|
||||
t.Fatalf("without connections and modified, got != want: want \n %+v, got \n %+v", from, got)
|
||||
}
|
||||
pushPeer := push.Peer()
|
||||
gotPush = gotPush.Peer()
|
||||
pushPeer.Modified = 0
|
||||
gotPush.Modified = 0
|
||||
if fmt.Sprint(gotPush) != fmt.Sprint(pushPeer) {
|
||||
t.Fatal("\n", gotPush, "\n", pushPeer)
|
||||
}
|
||||
t.Logf("%s", w.Body.Bytes())
|
||||
})
|
||||
|
||||
want = ones[2]
|
||||
t.Run("patch real", func(t *testing.T) {
|
||||
iwant := want
|
||||
|
|
@ -299,7 +345,7 @@ func TestWho(t *testing.T) {
|
|||
}
|
||||
|
||||
func fillDB(t *testing.T, g storage.Graph) []entity.One {
|
||||
ones := make([]entity.One, 5)
|
||||
ones := make([]entity.One, 25)
|
||||
for i := range ones {
|
||||
ones[i] = randomOne()
|
||||
if i > 0 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue