Skip to content

Commit

Permalink
simplified tests using ref.Of
Browse files Browse the repository at this point in the history
  • Loading branch information
cmendible committed Dec 10, 2023
1 parent 456d716 commit 3497b2f
Show file tree
Hide file tree
Showing 18 changed files with 56 additions and 239 deletions.
7 changes: 1 addition & 6 deletions internal/scanners/afd/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestFrontDoorScanner_Rules(t *testing.T) {
rule: "afd-005",
target: &armcdn.Profile{
SKU: &armcdn.SKU{
Name: getSKU(),
Name: ref.Of(armcdn.SKUNameStandardMicrosoft),
},
},
scanContext: &scanners.ScanContext{},
Expand Down Expand Up @@ -103,8 +103,3 @@ func TestFrontDoorScanner_Rules(t *testing.T) {
})
}
}

func getSKU() *armcdn.SKUName {
s := armcdn.SKUNameStandardMicrosoft
return &s
}
7 changes: 1 addition & 6 deletions internal/scanners/afw/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestFirewallScanner_Rules(t *testing.T) {
target: &armnetwork.AzureFirewall{
Properties: &armnetwork.AzureFirewallPropertiesFormat{
SKU: &armnetwork.AzureFirewallSKU{
Name: getSKU(),
Name: ref.Of(armnetwork.AzureFirewallSKUNameAZFWVnet),
},
},
},
Expand Down Expand Up @@ -134,8 +134,3 @@ func TestFirewallScanner_Rules(t *testing.T) {
})
}
}

func getSKU() *armnetwork.AzureFirewallSKUName {
s := armnetwork.AzureFirewallSKUNameAZFWVnet
return &s
}
7 changes: 1 addition & 6 deletions internal/scanners/agw/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestApplicationGatewayScanner_Rules(t *testing.T) {
target: &armnetwork.ApplicationGateway{
Properties: &armnetwork.ApplicationGatewayPropertiesFormat{
SKU: &armnetwork.ApplicationGatewaySKU{
Name: getSKUName(),
Name: ref.Of(armnetwork.ApplicationGatewaySKUNameStandardV2),
},
},
},
Expand Down Expand Up @@ -120,8 +120,3 @@ func TestApplicationGatewayScanner_Rules(t *testing.T) {
})
}
}

func getSKUName() *armnetwork.ApplicationGatewaySKUName {
s := armnetwork.ApplicationGatewaySKUNameStandardV2
return &s
}
47 changes: 11 additions & 36 deletions internal/scanners/aks/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestAKSScanner_Rules(t *testing.T) {
rule: "aks-002",
target: &armcontainerservice.ManagedCluster{
SKU: &armcontainerservice.ManagedClusterSKU{
Tier: getSKUTierPaid(),
Tier: ref.Of(armcontainerservice.ManagedClusterSKUTierStandard),
},
Properties: &armcontainerservice.ManagedClusterProperties{
AgentPoolProfiles: []*armcontainerservice.ManagedClusterAgentPoolProfile{
Expand All @@ -74,7 +74,7 @@ func TestAKSScanner_Rules(t *testing.T) {
rule: "aks-004",
target: &armcontainerservice.ManagedCluster{
SKU: &armcontainerservice.ManagedClusterSKU{
Tier: getSKUTierPaid(),
Tier: ref.Of(armcontainerservice.ManagedClusterSKUTierStandard),
},
Properties: &armcontainerservice.ManagedClusterProperties{
APIServerAccessProfile: &armcontainerservice.ManagedClusterAPIServerAccessProfile{
Expand All @@ -95,7 +95,7 @@ func TestAKSScanner_Rules(t *testing.T) {
rule: "aks-003",
target: &armcontainerservice.ManagedCluster{
SKU: &armcontainerservice.ManagedClusterSKU{
Tier: getSKUTierFree(),
Tier: ref.Of(armcontainerservice.ManagedClusterSKUTierFree),
},
Properties: &armcontainerservice.ManagedClusterProperties{
AgentPoolProfiles: []*armcontainerservice.ManagedClusterAgentPoolProfile{
Expand All @@ -118,7 +118,7 @@ func TestAKSScanner_Rules(t *testing.T) {
rule: "aks-003",
target: &armcontainerservice.ManagedCluster{
SKU: &armcontainerservice.ManagedClusterSKU{
Tier: getSKUTierPaid(),
Tier: ref.Of(armcontainerservice.ManagedClusterSKUTierStandard),
},
Properties: &armcontainerservice.ManagedClusterProperties{
AgentPoolProfiles: []*armcontainerservice.ManagedClusterAgentPoolProfile{
Expand All @@ -141,7 +141,7 @@ func TestAKSScanner_Rules(t *testing.T) {
rule: "aks-003",
target: &armcontainerservice.ManagedCluster{
SKU: &armcontainerservice.ManagedClusterSKU{
Tier: getSKUTierPaid(),
Tier: ref.Of(armcontainerservice.ManagedClusterSKUTierStandard),
},
Properties: &armcontainerservice.ManagedClusterProperties{
AgentPoolProfiles: []*armcontainerservice.ManagedClusterAgentPoolProfile{
Expand All @@ -164,7 +164,7 @@ func TestAKSScanner_Rules(t *testing.T) {
rule: "aks-005",
target: &armcontainerservice.ManagedCluster{
SKU: &armcontainerservice.ManagedClusterSKU{
Tier: getSKUTierFree(),
Tier: ref.Of(armcontainerservice.ManagedClusterSKUTierFree),
},
},
scanContext: &scanners.ScanContext{},
Expand Down Expand Up @@ -405,7 +405,7 @@ func TestAKSScanner_Rules(t *testing.T) {
target: &armcontainerservice.ManagedCluster{
Properties: &armcontainerservice.ManagedClusterProperties{
NetworkProfile: &armcontainerservice.NetworkProfile{
OutboundType: getOutboundTypeUserDefinedRouting(),
OutboundType: ref.Of(armcontainerservice.OutboundTypeUserDefinedRouting),
},
},
},
Expand All @@ -423,7 +423,7 @@ func TestAKSScanner_Rules(t *testing.T) {
target: &armcontainerservice.ManagedCluster{
Properties: &armcontainerservice.ManagedClusterProperties{
NetworkProfile: &armcontainerservice.NetworkProfile{
OutboundType: getOutboundTypeLoadBalancer(),
OutboundType: ref.Of(armcontainerservice.OutboundTypeLoadBalancer),
},
},
},
Expand All @@ -441,7 +441,7 @@ func TestAKSScanner_Rules(t *testing.T) {
target: &armcontainerservice.ManagedCluster{
Properties: &armcontainerservice.ManagedClusterProperties{
NetworkProfile: &armcontainerservice.NetworkProfile{
NetworkPlugin: getNetworkPluginKubenet(),
NetworkPlugin: ref.Of(armcontainerservice.NetworkPluginKubenet),
},
},
},
Expand Down Expand Up @@ -530,7 +530,7 @@ func TestAKSScanner_Rules(t *testing.T) {
rule: "aks-016",
target: &armcontainerservice.ManagedCluster{
SKU: &armcontainerservice.ManagedClusterSKU{
Tier: getSKUTierPaid(),
Tier: ref.Of(armcontainerservice.ManagedClusterSKUTierStandard),
},
Properties: &armcontainerservice.ManagedClusterProperties{
AgentPoolProfiles: []*armcontainerservice.ManagedClusterAgentPoolProfile{
Expand All @@ -553,7 +553,7 @@ func TestAKSScanner_Rules(t *testing.T) {
rule: "aks-016",
target: &armcontainerservice.ManagedCluster{
SKU: &armcontainerservice.ManagedClusterSKU{
Tier: getSKUTierPaid(),
Tier: ref.Of(armcontainerservice.ManagedClusterSKUTierStandard),
},
Properties: &armcontainerservice.ManagedClusterProperties{
AgentPoolProfiles: []*armcontainerservice.ManagedClusterAgentPoolProfile{
Expand Down Expand Up @@ -584,28 +584,3 @@ func TestAKSScanner_Rules(t *testing.T) {
})
}
}

func getNetworkPluginKubenet() *armcontainerservice.NetworkPlugin {
s := armcontainerservice.NetworkPluginKubenet
return &s
}

func getSKUTierFree() *armcontainerservice.ManagedClusterSKUTier {
s := armcontainerservice.ManagedClusterSKUTierFree
return &s
}

func getSKUTierPaid() *armcontainerservice.ManagedClusterSKUTier {
s := armcontainerservice.ManagedClusterSKUTierStandard
return &s
}

func getOutboundTypeUserDefinedRouting() *armcontainerservice.OutboundType {
s := armcontainerservice.OutboundTypeUserDefinedRouting
return &s
}

func getOutboundTypeLoadBalancer() *armcontainerservice.OutboundType {
s := armcontainerservice.OutboundTypeLoadBalancer
return &s
}
22 changes: 4 additions & 18 deletions internal/scanners/apim/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestAPIManagementScanner_Rules(t *testing.T) {
rule: "apim-003",
target: &armapimanagement.ServiceResource{
SKU: &armapimanagement.ServiceSKUProperties{
Name: getFreeSKUName(),
Name: ref.Of(armapimanagement.SKUTypeDeveloper),
},
Zones: []*string{},
Properties: &armapimanagement.ServiceProperties{
Expand All @@ -99,7 +99,7 @@ func TestAPIManagementScanner_Rules(t *testing.T) {
rule: "apim-003",
target: &armapimanagement.ServiceResource{
SKU: &armapimanagement.ServiceSKUProperties{
Name: getPremiumSKUName(),
Name: ref.Of(armapimanagement.SKUTypePremium),
},
Zones: []*string{ref.Of("1"), ref.Of("2"), ref.Of("3")},
Properties: &armapimanagement.ServiceProperties{
Expand All @@ -119,7 +119,7 @@ func TestAPIManagementScanner_Rules(t *testing.T) {
rule: "apim-003",
target: &armapimanagement.ServiceResource{
SKU: &armapimanagement.ServiceSKUProperties{
Name: getConsumptionSKUName(),
Name: ref.Of(armapimanagement.SKUTypeConsumption),
},
Zones: []*string{},
Properties: &armapimanagement.ServiceProperties{
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestAPIManagementScanner_Rules(t *testing.T) {
rule: "apim-005",
target: &armapimanagement.ServiceResource{
SKU: &armapimanagement.ServiceSKUProperties{
Name: getFreeSKUName(),
Name: ref.Of(armapimanagement.SKUTypeDeveloper),
},
},
scanContext: &scanners.ScanContext{},
Expand Down Expand Up @@ -200,17 +200,3 @@ func TestAPIManagementScanner_Rules(t *testing.T) {
}
}

func getFreeSKUName() *armapimanagement.SKUType {
s := armapimanagement.SKUTypeDeveloper
return &s
}

func getPremiumSKUName() *armapimanagement.SKUType {
s := armapimanagement.SKUTypePremium
return &s
}

func getConsumptionSKUName() *armapimanagement.SKUType {
s := armapimanagement.SKUTypeConsumption
return &s
}
16 changes: 3 additions & 13 deletions internal/scanners/appcs/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestAppConfigurationScanner_Rules(t *testing.T) {
rule: "appcs-003",
target: &armappconfiguration.ConfigurationStore{
SKU: &armappconfiguration.SKU{
Name: getFreeSKUName(),
Name: ref.Of("Free"),
},
},
scanContext: &scanners.ScanContext{},
Expand All @@ -67,7 +67,7 @@ func TestAppConfigurationScanner_Rules(t *testing.T) {
rule: "appcs-003",
target: &armappconfiguration.ConfigurationStore{
SKU: &armappconfiguration.SKU{
Name: getStandardSKUName(),
Name: ref.Of("Standard"),
},
},
scanContext: &scanners.ScanContext{},
Expand Down Expand Up @@ -103,7 +103,7 @@ func TestAppConfigurationScanner_Rules(t *testing.T) {
rule: "appcs-005",
target: &armappconfiguration.ConfigurationStore{
SKU: &armappconfiguration.SKU{
Name: getStandardSKUName(),
Name: ref.Of("Standard"),
},
},
scanContext: &scanners.ScanContext{},
Expand Down Expand Up @@ -159,13 +159,3 @@ func TestAppConfigurationScanner_Rules(t *testing.T) {
})
}
}

func getFreeSKUName() *string {
s := "Free"
return &s
}

func getStandardSKUName() *string {
s := "Standard"
return &s
}
14 changes: 2 additions & 12 deletions internal/scanners/ci/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestContainerInstanceScanner_Rules(t *testing.T) {
target: &armcontainerinstance.ContainerGroup{
Properties: &armcontainerinstance.ContainerGroupProperties{
IPAddress: &armcontainerinstance.IPAddress{
Type: getContainerGroupIPAddressTypePrivate(),
Type: ref.Of(armcontainerinstance.ContainerGroupIPAddressTypePrivate),
},
},
},
Expand All @@ -111,7 +111,7 @@ func TestContainerInstanceScanner_Rules(t *testing.T) {
rule: "ci-005",
target: &armcontainerinstance.ContainerGroup{
Properties: &armcontainerinstance.ContainerGroupProperties{
SKU: getStandardSKU(),
SKU: ref.Of(armcontainerinstance.ContainerGroupSKUStandard),
},
},
scanContext: &scanners.ScanContext{},
Expand Down Expand Up @@ -151,13 +151,3 @@ func TestContainerInstanceScanner_Rules(t *testing.T) {
})
}
}

func getContainerGroupIPAddressTypePrivate() *armcontainerinstance.ContainerGroupIPAddressType {
s := armcontainerinstance.ContainerGroupIPAddressTypePrivate
return &s
}

func getStandardSKU() *armcontainerinstance.ContainerGroupSKU {
s := armcontainerinstance.ContainerGroupSKUStandard
return &s
}
7 changes: 1 addition & 6 deletions internal/scanners/cosmos/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func TestCosmosDBScanner_Rules(t *testing.T) {
rule: "cosmos-005",
target: &armcosmos.DatabaseAccountGetResults{
Properties: &armcosmos.DatabaseAccountGetProperties{
DatabaseAccountOfferType: getDatabaseAccountOfferType(),
DatabaseAccountOfferType: ref.Of("Standard"),
},
},
scanContext: &scanners.ScanContext{},
Expand Down Expand Up @@ -191,8 +191,3 @@ func TestCosmosDBScanner_Rules(t *testing.T) {
})
}
}

func getDatabaseAccountOfferType() *string {
s := "Standard"
return &s
}
21 changes: 3 additions & 18 deletions internal/scanners/cr/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestContainerRegistryScanner_Rules(t *testing.T) {
rule: "cr-002",
target: &armcontainerregistry.Registry{
Properties: &armcontainerregistry.RegistryProperties{
ZoneRedundancy: getZoneRedundancy(),
ZoneRedundancy: ref.Of(armcontainerregistry.ZoneRedundancyEnabled),
},
},
scanContext: &scanners.ScanContext{},
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestContainerRegistryScanner_Rules(t *testing.T) {
rule: "cr-005",
target: &armcontainerregistry.Registry{
SKU: &armcontainerregistry.SKU{
Name: getSKUName(),
Name: ref.Of(armcontainerregistry.SKUNameStandard),
},
},
scanContext: &scanners.ScanContext{},
Expand Down Expand Up @@ -205,7 +205,7 @@ func TestContainerRegistryScanner_Rules(t *testing.T) {
Properties: &armcontainerregistry.RegistryProperties{
Policies: &armcontainerregistry.Policies{
RetentionPolicy: &armcontainerregistry.RetentionPolicy{
Status: getPolicyStatusDisabled(),
Status: ref.Of(armcontainerregistry.PolicyStatusDisabled),
},
},
},
Expand Down Expand Up @@ -233,18 +233,3 @@ func TestContainerRegistryScanner_Rules(t *testing.T) {
})
}
}

func getZoneRedundancy() *armcontainerregistry.ZoneRedundancy {
s := armcontainerregistry.ZoneRedundancyEnabled
return &s
}

func getSKUName() *armcontainerregistry.SKUName {
s := armcontainerregistry.SKUNameStandard
return &s
}

func getPolicyStatusDisabled() *armcontainerregistry.PolicyStatus {
s := armcontainerregistry.PolicyStatusDisabled
return &s
}
7 changes: 1 addition & 6 deletions internal/scanners/dec/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestDataExplorerScanner_Rules(t *testing.T) {
rule: "dec-003",
target: &armkusto.Cluster{
SKU: &armkusto.AzureSKU{
Name: getSKU(),
Name: ref.Of(armkusto.AzureSKUNameDevNoSLAStandardD11V2),
},
},
scanContext: &scanners.ScanContext{},
Expand Down Expand Up @@ -103,8 +103,3 @@ func TestDataExplorerScanner_Rules(t *testing.T) {
})
}
}

func getSKU() *armkusto.AzureSKUName {
s := armkusto.AzureSKUNameDevNoSLAStandardD11V2
return &s
}
Loading

0 comments on commit 3497b2f

Please sign in to comment.