Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

api,functional: dynamic metadata - fix bugs and add functional tests #1703

Merged
merged 3 commits into from
Nov 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions api/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ type machinesResource struct {

type machineMetadataOp struct {
Operation string `json:"op"`
Path string
Value string
Path string `json:"path"`
Value struct {
Value string `json:"value"`
}
}

func (mr *machinesResource) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
Expand Down Expand Up @@ -100,7 +102,7 @@ func (mr *machinesResource) patch(rw http.ResponseWriter, req *http.Request) {
return
}

if op.Operation != "remove" && len(op.Value) == 0 {
if op.Operation != "remove" && len(op.Value.Value) == 0 {
sendError(rw, http.StatusBadRequest, errors.New("invalid value: add and replace require a value"))
return
}
Expand All @@ -119,7 +121,7 @@ func (mr *machinesResource) patch(rw http.ResponseWriter, req *http.Request) {
return
}
} else {
err := mr.cAPI.SetMachineMetadata(machID, key, op.Value)
err := mr.cAPI.SetMachineMetadata(machID, key, op.Value.Value)
if err != nil {
sendError(rw, http.StatusInternalServerError, err)
return
Expand Down
8 changes: 4 additions & 4 deletions api/machines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ func TestExtractMachinePage(t *testing.T) {

func TestMachinesPatchAddModify(t *testing.T) {
reqBody := `
[{"op": "add", "path": "/XXX/metadata/foo", "value": "bar"},
{"op": "replace", "path": "/YYY/metadata/ping", "value": "splat"}]
[{"op": "add", "path": "/XXX/metadata/foo", "value": { "value": "bar" }},
{"op": "replace", "path": "/YYY/metadata/ping", "value": { "value": "splat" }}]
`

resource, rw := fakeMachinesSetup()
Expand Down Expand Up @@ -218,7 +218,7 @@ func TestMachinesPatchDelete(t *testing.T) {

func TestMachinesPatchBadOp(t *testing.T) {
reqBody := `
[{"op": "noop", "path": "/XXX/metadata/foo", "value": "bar"}]
[{"op": "noop", "path": "/XXX/metadata/foo", "value": { "value": "bar" }}]
`

resource, rw := fakeMachinesSetup()
Expand All @@ -235,7 +235,7 @@ func TestMachinesPatchBadOp(t *testing.T) {

func TestMachinesPatchBadPath(t *testing.T) {
reqBody := `
[{"op": "add", "path": "/XXX/foo", "value": "bar"}]
[{"op": "add", "path": "/XXX/foo", "value": { "value": "bar" }}]
`

resource, rw := fakeMachinesSetup()
Expand Down
Loading