Skip to content

Commit

Permalink
test(PUT /resource?merge): update subresource
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfrancismccann committed Feb 14, 2022
1 parent 61ea1b2 commit e7a028b
Showing 1 changed file with 44 additions and 19 deletions.
63 changes: 44 additions & 19 deletions arborist/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1113,25 +1113,50 @@ func TestServer(t *testing.T) {
{"name": "dog", "subresources": [{"name": "corgi"}]}
]
}`))
w := httptest.NewRecorder()
body := []byte(`{
"name": "animal",
"subresources": [
{"name": "bird", "subresources": [{"name": "goose"}]},
{"name": "cat", "subresources": [{"name": "lion"}]}
]
}`)
req := newRequest("PUT", "/resource?merge", bytes.NewBuffer(body))
handler.ServeHTTP(w, req)
if w.Code != http.StatusCreated {
httpError(t, w, "couldn't update resource using PUT")
}
// verify that resources created before update were not overwritten
getResourceWithPath(t, "/animal/dinosaur/pterodactyl")
getResourceWithPath(t, "/animal/dog/corgi")
// verify that update actually created resources
getResourceWithPath(t, "/animal/bird/goose")
getResourceWithPath(t, "/animal/cat/lion")

t.Run("UpdateTopLevelResource", func(t *testing.T) {
w := httptest.NewRecorder()
body := []byte(`{
"name": "animal",
"subresources": [
{"name": "bird", "subresources": [{"name": "goose"}]},
{"name": "cat", "subresources": [{"name": "lion"}]}
]
}`)
req := newRequest("PUT", "/resource?merge", bytes.NewBuffer(body))
handler.ServeHTTP(w, req)
if w.Code != http.StatusCreated {
httpError(t, w, "couldn't update resource using PUT")
}
// verify that resources created before update were not overwritten
getResourceWithPath(t, "/animal/dinosaur/pterodactyl")
getResourceWithPath(t, "/animal/dog/corgi")
// verify that update actually created resources
getResourceWithPath(t, "/animal/bird/goose")
getResourceWithPath(t, "/animal/cat/lion")
})

t.Run("UpdateSubresource", func(t *testing.T) {
w := httptest.NewRecorder()
body := []byte(`{
"path": "/animal/dog",
"subresources": [
{"name": "goldenretriever", "subresources": []}
]
}`)
req := newRequest("PUT", "/resource?merge", bytes.NewBuffer(body))
handler.ServeHTTP(w, req)
if w.Code != http.StatusCreated {
httpError(t, w, "couldn't update resource using PUT")
}
// verify that resources created before update were not overwritten
getResourceWithPath(t, "/animal/dinosaur/pterodactyl")
getResourceWithPath(t, "/animal/dog/corgi")
getResourceWithPath(t, "/animal/bird/goose")
getResourceWithPath(t, "/animal/cat/lion")
// verify that update actually created resource
getResourceWithPath(t, "/animal/dog/goldenretriever")
})
})

t.Run("Delete", func(t *testing.T) {
Expand Down

0 comments on commit e7a028b

Please sign in to comment.