Skip to content

Commit

Permalink
Merge pull request #91 from svetlinas/master
Browse files Browse the repository at this point in the history
Modify dataGroupDTO struct
  • Loading branch information
scottdware authored Feb 25, 2019
2 parents ba5bf5e + 181c086 commit 41ea60d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ltm.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,10 @@ type dataGroupDTO struct {
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
Type string `json:"type,omitempty"`
Records []DataGroupRecord `json:"records,omitempty"`

// Records contains a list of DataGroupRecord objects.
// `omitempty` tag is removed on purpose. See issue https://github.com/scottdware/go-bigip/issues/90
Records []DataGroupRecord `json:"records"`
}

func (p *DataGroup) MarshalJSON() ([]byte, error) {
Expand Down
26 changes: 26 additions & 0 deletions ltm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,20 @@ func (s *LTMTestSuite) TestAddInternalDataGroup() {
assert.Equal(s.T(), `{"name":"test-datagroup","type":"string","records":[{"name":"name1","data":"data1"},{"name":"name2","data":"data2"}]}`, s.LastRequestBody)
}

func (s *LTMTestSuite) TestAddInternalDataGroup_emptyRecords() {
config := &DataGroup{
Name: "test-datagroup",
Type: "string",
Records: []DataGroupRecord{},
}

s.Client.AddInternalDataGroup(config)

assert.Equal(s.T(), "POST", s.LastRequest.Method)
assert.Equal(s.T(), fmt.Sprintf("/mgmt/tm/%s/%s/%s", uriLtm, uriDatagroup, uriInternal), s.LastRequest.URL.Path)
assert.Equal(s.T(), `{"name":"test-datagroup","type":"string","records":[]}`, s.LastRequestBody)
}

func (s *LTMTestSuite) TestModifyInternalDataGroupRecords() {
dataGroup := "test"

Expand All @@ -1330,6 +1344,18 @@ func (s *LTMTestSuite) TestModifyInternalDataGroupRecords() {
assert.Equal(s.T(), `{"records":[{"name":"name1","data":"data1"},{"name":"name42","data":"data42"}]}`, s.LastRequestBody)
}

func (s *LTMTestSuite) TestModifyInternalDataGroupRecords_emptyRecords() {
dataGroup := "test"

records := &[]DataGroupRecord{}

s.Client.ModifyInternalDataGroupRecords(dataGroup, records)

assert.Equal(s.T(), "PUT", s.LastRequest.Method)
assert.Equal(s.T(), fmt.Sprintf("/mgmt/tm/%s/%s/%s/%s", uriLtm, uriDatagroup, uriInternal, dataGroup), s.LastRequest.URL.Path)
assert.Equal(s.T(), `{"records":[]}`, s.LastRequestBody)
}

func (s *LTMTestSuite) TestDeleteInternalDataGroup() {
dataGroup := "test"
s.Client.DeleteInternalDataGroup(dataGroup)
Expand Down

0 comments on commit 41ea60d

Please sign in to comment.