Skip to content

Commit

Permalink
Added PatchVirtualServer and PatchVirtualAddress functions and tests …
Browse files Browse the repository at this point in the history
…to update VirtualServer and VirtualAddress objects using patch method
  • Loading branch information
rawmind0 committed Jan 29, 2019
1 parent 158be62 commit bbc4e39
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
16 changes: 14 additions & 2 deletions ltm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1824,11 +1824,17 @@ func (b *BigIP) DeleteVirtualServer(name string) error {
}

// ModifyVirtualServer allows you to change any attribute of a virtual server. Fields that
// can be modified are referenced in the VirtualServer struct.
// can be modified are referenced in the VirtualServer struct. Set all the attributes.
func (b *BigIP) ModifyVirtualServer(name string, config *VirtualServer) error {
return b.put(config, uriLtm, uriVirtual, name)
}

// PatchVirtualServer allows you to change any attribute of a virtual server. Fields that
// can be modified are referenced in the VirtualServer struct. Sets only the attributes specified.
func (b *BigIP) PatchVirtualServer(name string, config *VirtualServer) error {
return b.patch(config, uriLtm, uriVirtual, name)
}

// VirtualServerProfiles gets the profiles currently associated with a virtual server.
func (b *BigIP) VirtualServerProfiles(vs string) (*Profiles, error) {
var p Profiles
Expand Down Expand Up @@ -1891,11 +1897,17 @@ func (b *BigIP) VirtualAddressStatus(vaddr, state string) error {
}

// ModifyVirtualAddress allows you to change any attribute of a virtual address. Fields that
// can be modified are referenced in the VirtualAddress struct.
// can be modified are referenced in the VirtualAddress struct. Sets all the attributes.
func (b *BigIP) ModifyVirtualAddress(vaddr string, config *VirtualAddress) error {
return b.put(config, uriLtm, uriVirtualAddress, vaddr)
}

// PatchVirtualAddress allows you to change any attribute of a virtual address. Fields that
// can be modified are referenced in the VirtualAddress struct. Sets only the attributes specified.
func (b *BigIP) PatchVirtualAddress(vaddr string, config *VirtualAddress) error {
return b.patch(config, uriLtm, uriVirtualAddress, vaddr)
}

func (b *BigIP) DeleteVirtualAddress(vaddr string) error {
return b.delete(uriLtm, uriVirtualAddress, vaddr)
}
Expand Down
32 changes: 32 additions & 0 deletions ltm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ func (s *LTMTestSuite) TestModifyVirtualAddress() {
assert.Equal(s.T(), "PUT", s.LastRequest.Method)
}

func (s *LTMTestSuite) TestPatchVirtualAddress() {
d := &VirtualAddress{}
s.Client.PatchVirtualAddress("address1", d)

assert.Equal(s.T(), fmt.Sprintf("/mgmt/tm/%s/%s/%s", uriLtm, uriVirtualAddress, "address1"), s.LastRequest.URL.Path)
assert.Equal(s.T(), "PATCH", s.LastRequest.Method)
}

func (s *LTMTestSuite) TestGetPolicies() {
s.ResponseFunc = func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`{
Expand Down Expand Up @@ -468,6 +476,30 @@ func (s *LTMTestSuite) TestModifyVirtualServer() {

}

func (s *LTMTestSuite) TestPatchVirtualServer() {
vs := &VirtualServer{
Name: "test",
Profiles: []Profile{
Profile{Name: "/Common/tcp", Context: CONTEXT_CLIENT},
Profile{Name: "/Common/tcp", Context: CONTEXT_SERVER}},
//TODO: test more
}

s.Client.PatchVirtualServer("test", vs)

assert.Equal(s.T(), "PATCH", s.LastRequest.Method)
assert.Equal(s.T(), fmt.Sprintf("/mgmt/tm/%s/%s/test", uriLtm, uriVirtual), s.LastRequest.URL.Path)
assert.JSONEq(s.T(), `
{"name":"test",
"sourceAddressTranslation":{},
"profiles":[
{"name":"/Common/tcp","context":"clientside"},
{"name":"/Common/tcp","context":"serverside"}
]
}`, s.LastRequestBody)

}

func (s *LTMTestSuite) TestDeleteVirtualServer() {
s.Client.DeleteVirtualServer("/Common/test-vs")

Expand Down

0 comments on commit bbc4e39

Please sign in to comment.