Skip to content

Commit

Permalink
neaten up shared resources
Browse files Browse the repository at this point in the history
  • Loading branch information
1riatsila1 committed Oct 9, 2024
1 parent c407201 commit 1586d78
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 119 deletions.
4 changes: 2 additions & 2 deletions pkg/config-api-provider/test/data-sources/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestGroupDataSource(t *testing.T) {
PreConfig: func() {
util.MockGetGroup(
"uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.StructToMap(util.GenerateGroupResponseGetModel("uid", "", ""))}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("uid", "", "")}),
3,
)
},
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestGroupDataSource429Handling(t *testing.T) {
SetHeaders(util.RateLimitingHeaders)
util.MockGetGroup(
"uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.StructToMap(util.GenerateGroupResponseGetModel("uid", "", ""))}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("uid", "", "")}),
3,
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestNetworkGroupAssignmentDataSource(t *testing.T) {
PreConfig: func() {
util.MockGetNetworkGroupAssignment(
"uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("uid", "")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("uid", "")}),
3,
)
},
Expand Down Expand Up @@ -63,7 +63,7 @@ func TestNetworkGroupAssignmentSource429Handling(t *testing.T) {
SetHeaders(util.RateLimitingHeaders)
util.MockGetNetworkGroupAssignment(
"uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("uid", "")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("uid", "")}),
3,
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestSensorGroupAssignmentDataSource(t *testing.T) {
PreConfig: func() {
util.MockGetSensorGroupAssignment(
"uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentGetResponse("uid", "")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentResponse("uid", "")}),
3,
)
},
Expand Down Expand Up @@ -63,7 +63,7 @@ func TestSensorGroupAssignmentSource429Handling(t *testing.T) {
SetHeaders(util.RateLimitingHeaders)
util.MockGetSensorGroupAssignment(
"uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentGetResponse("uid", "")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentResponse("uid", "")}),
3,
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ func TestAgentGroupAssignmentResource(t *testing.T) {
}

// required for group create
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponsePostModel("group_uid", "", "")), 1)
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), 1)
util.MockGetGroup(
"group_uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.StructToMap(util.GenerateGroupResponseGetModel("group_uid", "", ""))}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}),
1,
)

Expand Down Expand Up @@ -86,21 +86,19 @@ func TestAgentGroupAssignmentResource(t *testing.T) {
return util.GenerateAgentResponseModel(uid, "_2")
}
}
util.MockGetGroup("group_uid_2", util.GeneratePaginatedResponse(
[]map[string]interface{}{
util.StructToMap(util.GenerateGroupResponseGetModel("group_uid_2", "_2", "_2")),
}),
util.MockGetGroup(
"group_uid_2",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")}),
1,
)
util.MockGetGroup("group_uid", util.GeneratePaginatedResponse(
[]map[string]interface{}{
util.StructToMap(util.GenerateGroupResponseGetModel("group_uid", "", "")),
}),
util.MockGetGroup(
"group_uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}),
2,
)

// required for creating another group
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponsePostModel("group_uid_2", "_2", "_2")), 1)
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")), 1)

// required for agent group assignment create
resources.GetAgentGroupAssignment = func(uid string) resources.AgentGroupAssignmentResponseModel {
Expand Down
4 changes: 2 additions & 2 deletions pkg/config-api-provider/test/resources/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func TestGroupResource(t *testing.T) {
// Create and Read testing
{
PreConfig: func() {
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponsePostModel("uid", "", "")), 1)
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponseModel("uid", "", "")), 1)
util.MockGetGroup("uid", util.GeneratePaginatedResponse(
[]map[string]interface{}{util.StructToMap(util.GenerateGroupResponseGetModel("uid", "", ""))}),
[]map[string]interface{}{util.GenerateGroupResponseModel("uid", "", "")}),
1,
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) {
)

// required for group create
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponsePostModel("group_uid", "", "")), 1)
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), 1)
util.MockGetGroup("group_uid", util.GeneratePaginatedResponse(
[]map[string]interface{}{util.StructToMap(util.GenerateGroupResponseGetModel("group_uid", "", ""))}),
[]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}),
2,
)

Expand All @@ -43,7 +43,7 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) {
)
util.MockGetNetworkGroupAssignment(
"network_group_assignment_uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", "")}),
1,
)
},
Expand Down Expand Up @@ -78,7 +78,7 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) {
PreConfig: func() {
util.MockGetNetworkGroupAssignment(
"network_group_assignment_uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", "")}),
1,
)
},
Expand All @@ -101,17 +101,17 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) {
)
util.MockGetGroup(
"group_uid_2",
util.GeneratePaginatedResponse([]map[string]interface{}{util.StructToMap(util.GenerateGroupResponseGetModel("group_uid_2", "_2", "_2"))}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")}),
1,
)
util.MockGetGroup(
"group_uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.StructToMap(util.GenerateGroupResponseGetModel("group_uid", "", ""))}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}),
3,
)

// required for creating another group
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponsePostModel("group_uid_2", "_2", "_2")), 1)
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")), 1)

// required for network group assignment create
util.MockDeleteNetworkGroupAssignment("network_group_assignment_uid", 1)
Expand All @@ -122,12 +122,12 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) {
)
util.MockGetNetworkGroupAssignment(
"network_group_assignment_uid_2",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid_2", "_2")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid_2", "_2")}),
2,
)
util.MockGetNetworkGroupAssignment(
"network_group_assignment_uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", "")}),
2,
)
},
Expand Down Expand Up @@ -187,21 +187,21 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) {
1,
)
util.MockGetGroup("group_uid", util.GeneratePaginatedResponse(
[]map[string]interface{}{util.StructToMap(util.GenerateGroupResponseGetModel("group_uid", "", ""))}),
[]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}),
2,
)
util.MockGetGroup("group_uid_2", util.GeneratePaginatedResponse(
[]map[string]interface{}{util.StructToMap(util.GenerateGroupResponseGetModel("group_uid_2", "_2", "_2"))}),
[]map[string]interface{}{util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")}),
1,
)
util.MockGetNetworkGroupAssignment(
"network_group_assignment_uid_2",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid_2", "_2")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid_2", "_2")}),
1,
)
util.MockGetNetworkGroupAssignment(
"network_group_assignment_uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", "")}),
1,
)

Expand Down Expand Up @@ -249,10 +249,10 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) {
2,
)
// required for group create
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponsePostModel("group_uid", "", "")), 1)
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), 1)
util.MockGetGroup(
"group_uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.StructToMap(util.GenerateGroupResponseGetModel("group_uid", "", ""))}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}),
1,
)

Expand All @@ -264,7 +264,7 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) {
)
util.MockGetNetworkGroupAssignment(
"network_group_assignment_uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", "")}),
1,
)
},
Expand Down Expand Up @@ -299,7 +299,7 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) {
PreConfig: func() {
util.MockGetNetworkGroupAssignment(
"network_group_assignment_uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", "")}),
1,
)
},
Expand All @@ -323,28 +323,28 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) {

// required for creating another group
util.MockDeleteNetworkGroupAssignment("network_group_assignment_uid", 1)
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponsePostModel("group_uid_2", "_2", "_2")), 1)
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")), 1)
util.MockGetGroup(
"group_uid_2",
util.GeneratePaginatedResponse([]map[string]interface{}{util.StructToMap(util.GenerateGroupResponseGetModel("group_uid_2", "_2", "_2"))}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")}),
1,
)

util.MockGetGroup(
"group_uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.StructToMap(util.GenerateGroupResponseGetModel("group_uid", "", ""))}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}),
3,
)

// required for network group assignment create
util.MockGetNetworkGroupAssignment(
"network_group_assignment_uid_2",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid_2", "_2")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid_2", "_2")}),
2,
)
util.MockGetNetworkGroupAssignment(
"network_group_assignment_uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", "")}),
2,
)
util.MockPostNetworkGroupAssignment(
Expand Down Expand Up @@ -410,22 +410,22 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) {
)
util.MockGetGroup(
"group_uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.StructToMap(util.GenerateGroupResponseGetModel("group_uid", "", ""))}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}),
2,
)
util.MockGetGroup(
"group_uid_2",
util.GeneratePaginatedResponse([]map[string]interface{}{util.StructToMap(util.GenerateGroupResponseGetModel("group_uid_2", "_2", "_2"))}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")}),
1,
)
util.MockGetNetworkGroupAssignment(
"network_group_assignment_uid_2",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid_2", "_2")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid_2", "_2")}),
1,
)
util.MockGetNetworkGroupAssignment(
"network_group_assignment_uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", "")}),
1,
)

Expand Down Expand Up @@ -473,9 +473,9 @@ func TestNetworkGroupAssignmentSource429Handling(t *testing.T) {
)

// required for group create
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponsePostModel("group_uid", "", "")), 1)
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), 1)
util.MockGetGroup("group_uid", util.GeneratePaginatedResponse(
[]map[string]interface{}{util.StructToMap(util.GenerateGroupResponseGetModel("group_uid", "", ""))}),
[]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}),
2,
)

Expand All @@ -491,7 +491,7 @@ func TestNetworkGroupAssignmentSource429Handling(t *testing.T) {
)
util.MockGetNetworkGroupAssignment(
"network_group_assignment_uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", "")}),
1,
)
},
Expand Down Expand Up @@ -532,12 +532,12 @@ func TestNetworkGroupAssignmentSource429Handling(t *testing.T) {
1,
)
util.MockGetGroup("group_uid", util.GeneratePaginatedResponse(
[]map[string]interface{}{util.StructToMap(util.GenerateGroupResponseGetModel("group_uid", "", ""))}),
[]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}),
1,
)
util.MockGetNetworkGroupAssignment(
"network_group_assignment_uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("network_group_assignment_uid", "")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", "")}),
1,
)

Expand Down
Loading

0 comments on commit 1586d78

Please sign in to comment.