Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
1riatsila1 committed Oct 31, 2024
1 parent f86fbcc commit 7fa8cd1
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions pkg/config-api-provider/test/resources/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,19 @@ func TestAgentResource429Handling(t *testing.T) {
[]map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}),
1,
)
request429 = gock.New("https://test.api.capenetworks.com").
Delete("/networking-uxi/v1alpha1/agents/uid").
Reply(429).
SetHeaders(util.RateLimitingHeaders)
util.MockDeleteAgent("uid", 1)
},
Config: provider.ProviderConfig,
Check: resource.ComposeAggregateTestCheckFunc(
func(s *terraform.State) error {
st.Assert(t, request429.Mock.Request().Counter, 0)
return nil
},
),
},
},
})
Expand Down Expand Up @@ -250,6 +260,70 @@ func TestAgentResourceHttpErrorHandling(t *testing.T) {

ExpectError: regexp.MustCompile(`Error: Cannot import non-existent remote object`),
},
// Actually importing an agent for testing purposes
{
PreConfig: func() {
util.MockGetAgent(
"uid",
util.GeneratePaginatedResponse(
[]map[string]interface{}{util.GenerateAgentResponseModel("uid", "")},
),
2,
)
},
Config: provider.ProviderConfig + `
resource "uxi_agent" "my_agent" {
name = "name"
notes = "notes"
pcap_mode = "light"
}
import {
to = uxi_agent.my_agent
id = "uid"
}`,

Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("uxi_agent.my_agent", "id", "uid"),
),
},
// Delete 4xx
{
PreConfig: func() {
// existing agent
util.MockGetAgent("uid", util.GeneratePaginatedResponse(
[]map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}),
1,
)
// delete agent - with error
gock.New("https://test.api.capenetworks.com").
Delete("/networking-uxi/v1alpha1/agents/uid").
Reply(422).
JSON(map[string]interface{}{
"httpStatusCode": 422,
"errorCode": "HPE_GL_NETWORKING_UXI_HARDWARE_SENSOR_DELETION_FORBIDDEN",
"message": "Cant delete sensor - hardware sensor deletion is forbidden",
"debugId": "12312-123123-123123-1231212",
})
},
Config: provider.ProviderConfig,
ExpectError: regexp.MustCompile(
`(?s)Cant delete sensor - hardware sensor deletion is forbidden\s*DebugID: 12312-123123-123123-1231212`,
),
},
// Actually delete group for cleanup reasons
{
PreConfig: func() {
// existing group
util.MockGetAgent("uid", util.GeneratePaginatedResponse(
[]map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}),
1,
)
// delete group
util.MockDeleteAgent("uid", 1)
},
Config: provider.ProviderConfig,
},
},
})

Expand Down

0 comments on commit 7fa8cd1

Please sign in to comment.