HEAD and PATCH to create peers and list all items
This commit is contained in:
@@ -21,13 +21,15 @@ import (
|
||||
|
||||
func TestWho(t *testing.T) {
|
||||
os.Args = os.Args[:1]
|
||||
f, err := ioutil.TempFile(os.TempDir(), "pattern*")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
if _, ok := os.LookupEnv("DBURI"); !ok {
|
||||
f, err := ioutil.TempFile(os.TempDir(), "pattern*")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f.Close()
|
||||
defer os.Remove(f.Name())
|
||||
os.Setenv("DBURI", f.Name())
|
||||
}
|
||||
f.Close()
|
||||
defer os.Remove(f.Name())
|
||||
os.Setenv("DBURI", f.Name())
|
||||
|
||||
t.Logf("config: %+v", config.New())
|
||||
|
||||
@@ -180,6 +182,76 @@ func TestWho(t *testing.T) {
|
||||
t.Fatalf("%d: %s", w.Code, w.Body.Bytes())
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("patch fake", func(t *testing.T) {
|
||||
r := httptest.NewRequest(http.MethodPatch, "/who/col?id=FAKER"+want.Name, nil)
|
||||
w := httptest.NewRecorder()
|
||||
handler.ServeHTTP(w, r)
|
||||
if w.Code == http.StatusOK {
|
||||
t.Fatalf("%d: %s", w.Code, w.Body.Bytes())
|
||||
}
|
||||
})
|
||||
|
||||
want = ones[2]
|
||||
t.Run("patch real", func(t *testing.T) {
|
||||
iwant := want
|
||||
iwant.Relationship = "spawn"
|
||||
iwant.Name = "child of " + want.Name
|
||||
b, err := json.Marshal(iwant)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r := httptest.NewRequest(http.MethodPatch, "/who/col?id="+want.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(entity.One{}) {
|
||||
t.Fatal(got)
|
||||
}
|
||||
iwant = want
|
||||
if len(got.Connections) != len(want.Connections)+1 {
|
||||
t.Fatal(len(got.Connections), len(want.Connections)+1)
|
||||
}
|
||||
got.Connections = want.Connections
|
||||
got.Modified = 0
|
||||
want.Modified = 0
|
||||
if fmt.Sprint(got) != fmt.Sprint(want) {
|
||||
t.Fatalf("withotu connections and modified, got != want: want \n %+v, got \n %+v", want, got)
|
||||
}
|
||||
t.Logf("%s", w.Body.Bytes())
|
||||
})
|
||||
|
||||
t.Run("head fake", func(t *testing.T) {
|
||||
r := httptest.NewRequest(http.MethodHead, "/who/notcol", nil)
|
||||
w := httptest.NewRecorder()
|
||||
handler.ServeHTTP(w, r)
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("%d: %s", w.Code, w.Body.Bytes())
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("head real", func(t *testing.T) {
|
||||
r := httptest.NewRequest(http.MethodHead, "/who/col", nil)
|
||||
w := httptest.NewRecorder()
|
||||
handler.ServeHTTP(w, r)
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("%d: %s", w.Code, w.Body.Bytes())
|
||||
}
|
||||
var v []string
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &v); err != nil {
|
||||
t.Fatalf("%v: %s", err, w.Body.Bytes())
|
||||
}
|
||||
if len(v) < 5 {
|
||||
t.Fatal(len(v))
|
||||
}
|
||||
t.Logf("%+v", v)
|
||||
})
|
||||
}
|
||||
|
||||
func fillDB(t *testing.T, g storage.Graph) []entity.One {
|
||||
|
||||
Reference in New Issue
Block a user