Skip to content

Commit

Permalink
Merge pull request #61 from Comcast/hotfix/testSet
Browse files Browse the repository at this point in the history
empty bodies are valid in testset
  • Loading branch information
njharter authored Mar 5, 2018
2 parents 61aca0a + fc5a9af commit 20e53e4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/tr1d1um/conversion_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ func (cw *ConversionWDMP) SetFlavorFormat(req *http.Request) (wdmp *SetWDMP, err
wdmp = new(SetWDMP)

var payload []byte
if payload, err = ioutil.ReadAll(req.Body); err == nil && len(payload) > 0 {
if err = json.Unmarshal(payload, wdmp); err == nil {
if payload, err = ioutil.ReadAll(req.Body); err == nil {
if err = json.Unmarshal(payload, wdmp); err == nil || len(payload) == 0 {
err = cw.ValidateAndDeduceSET(req.Header, wdmp)
}
}
Expand Down
25 changes: 23 additions & 2 deletions src/tr1d1um/conversion_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,24 @@ func TestSetFlavorFormat(t *testing.T) {
assert.EqualValues("sync-val", wdmp.SyncCmc)
assert.EqualValues("newCid", wdmp.NewCid)
})

//Allow testSet with empty body and optional cmc header
t.Run("EmptyBodyTestSet", func(t *testing.T) {
assert := assert.New(t)

req := httptest.NewRequest(http.MethodPatch, "http://device/config?k=v", nil)
req.Header.Set(HeaderWPASyncNewCID, "newCid")
req.Header.Set(HeaderWPASyncOldCID, "oldCid")

wdmp, err := c.SetFlavorFormat(req)

assert.Nil(err)
assert.EqualValues(CommandTestSet, wdmp.Command)
assert.Empty(wdmp.Parameters)
assert.Empty(wdmp.SyncCmc)
assert.EqualValues("oldCid", wdmp.OldCid)
assert.EqualValues("newCid", wdmp.NewCid)
})
}

func TestGetCommandForParam(t *testing.T) {
Expand Down Expand Up @@ -210,10 +228,13 @@ func TestValidateAndDeduceSETCommand(t *testing.T) {
}

func TestIsValidSetWDMP(t *testing.T) {
t.Run("TestSetEmptyParams", func(t *testing.T) {
t.Run("TestAndSetZeroParams", func(t *testing.T) {
assert := assert.New(t)

wdmp := &SetWDMP{Command: CommandTestSet}
wdmp := &SetWDMP{Command: CommandTestSet} //nil parameters
assert.True(isValidSetWDMP(wdmp))

wdmp = &SetWDMP{Command: CommandTestSet, Parameters: []SetParam{}} //empty parameters
assert.True(isValidSetWDMP(wdmp))
})

Expand Down

0 comments on commit 20e53e4

Please sign in to comment.