Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type OpenAPIV3SchemaValidator struct {
}

func (validator *OpenAPIV3SchemaValidator) ValidateRequiredFields(objectValues map[string]interface{}) (errs []error) {
errs = make([]error, 0)
errs = make([]error, 0, len(validator.Schema))

for k, v := range validator.Schema {
objectValue := objectValues[k]
Expand Down
9 changes: 5 additions & 4 deletions internal/resources/cluster/data_source_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ func TestAcceptanceForAttachClusterDataSource(t *testing.T) {
}

func checkDataSourceAttributes() resource.TestCheckFunc {
var check = []resource.TestCheckFunc{
metaChecks := testhelper.MetaDataSourceAttributeCheck(testhelper.ClusterDataSourceName, testhelper.ClusterResourceName)
check := make([]resource.TestCheckFunc, 0, 3+len(metaChecks))
check = append(check,
verifyClusterDataSource(testhelper.ClusterDataSourceName),
resource.TestCheckResourceAttrPair(testhelper.ClusterDataSourceName, "name", testhelper.ClusterResourceName, "name"),
resource.TestCheckResourceAttrSet(testhelper.ClusterDataSourceName, "id"),
}

check = append(check, testhelper.MetaDataSourceAttributeCheck(testhelper.ClusterDataSourceName, testhelper.ClusterResourceName)...)
)
check = append(check, metaChecks...)

return resource.ComposeTestCheckFunc(check...)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/cluster/nodepools/resource_node_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ func flattenTkgServiceVsphere(tkgServiceVsphere *nodepoolmodel.VmwareTanzuManage
flattenTkgServiceVsphereData[storageClassKey] = tkgServiceVsphere.StorageClass
flattenTkgServiceVsphereData[failureDomainKey] = tkgServiceVsphere.FailureDomain

vls := make([]interface{}, 0)
vls := make([]interface{}, 0, len(tkgServiceVsphere.Volumes))
for _, vl := range tkgServiceVsphere.Volumes {
vls = append(vls, flattenTKGSVolumes(vl))
}
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/cluster/tkgaws/resource_tkg_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func ConstructTKGAWSClusterSpec(data []interface{}) (spec *tkgawsmodel.VmwareTan
func FlattenTKGAWSClusterSpec(spec *tkgawsmodel.VmwareTanzuManageV1alpha1ClusterInfrastructureTkgawsSpec) (data []interface{}) {
flattenSpecData := make(map[string]interface{})

acs := make([]interface{}, 0)
acs := make([]interface{}, 0, len(spec.AdvancedConfigs))

for _, ac := range spec.AdvancedConfigs {
acs = append(acs, common.FlattenAdvancedConfig(ac))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func ConstructTKGVsphereClusterSpec(data []interface{}) (spec *tkgvspheremodel.V
func FlattenTKGVsphereClusterSpec(spec *tkgvspheremodel.VmwareTanzuManageV1alpha1ClusterInfrastructureTkgvsphereSpec) (data []interface{}) {
flattenSpecData := make(map[string]interface{})

acs := make([]interface{}, 0)
acs := make([]interface{}, 0, len(spec.AdvancedConfigs))

for _, ac := range spec.AdvancedConfigs {
acs = append(acs, common.FlattenAdvancedConfig(ac))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ data "%s" "%s" {
}

func checkDataSourceAttributes(dataSourceName, resourceName string) resource.TestCheckFunc {
var check = []resource.TestCheckFunc{
metaChecks := testhelper.MetaDataSourceAttributeCheck(dataSourceName, resourceName)
check := make([]resource.TestCheckFunc, 0, 3+len(metaChecks))
check = append(check,
verifyClusterGroupDataSource(dataSourceName),
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrSet(dataSourceName, "id"),
}

check = append(check, testhelper.MetaDataSourceAttributeCheck(dataSourceName, resourceName)...)
)
check = append(check, metaChecks...)

return resource.ComposeTestCheckFunc(check...)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ resource "%s" "%s" {
}

func checkResourceAttributes(provider *schema.Provider, resourceName, clusterGroupName string) resource.TestCheckFunc {
var check = []resource.TestCheckFunc{
metaChecks := testhelper.MetaResourceAttributeCheck(resourceName)
check := make([]resource.TestCheckFunc, 0, 2+len(metaChecks))
check = append(check,
verifyClusterGroupResourceCreation(provider, resourceName, clusterGroupName),
resource.TestCheckResourceAttr(resourceName, "name", clusterGroupName),
}

check = append(check, testhelper.MetaResourceAttributeCheck(resourceName)...)
)
check = append(check, metaChecks...)

return resource.ComposeTestCheckFunc(check...)
}
Expand Down
12 changes: 6 additions & 6 deletions internal/resources/credential/data_source_credential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ data "%s" "%s" {
}

func checkDataSourceAttributes(dataSourceName, resourceName string) resource.TestCheckFunc {
var check = []resource.TestCheckFunc{
verifyClusterGroupDataSource(dataSourceName),
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrSet(dataSourceName, "id"),
}

checks := []resource.TestCheckFunc{
resource.TestCheckResourceAttr(resourceName, "meta.#", "1"),
resource.TestCheckResourceAttrSet(resourceName, "meta.0.uid"),
}

check := make([]resource.TestCheckFunc, 0, 3+len(checks))
check = append(check,
verifyClusterGroupDataSource(dataSourceName),
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrSet(dataSourceName, "id"),
)
check = append(check, checks...)

return resource.ComposeTestCheckFunc(check...)
Expand Down
10 changes: 5 additions & 5 deletions internal/resources/credential/resource_credential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,16 @@ resource "%s" "%s" {
}

func checkResourceAttributes(provider *schema.Provider, resourceName, credentialName string) resource.TestCheckFunc {
var check = []resource.TestCheckFunc{
verifyCredentialResourceCreation(provider, resourceName, credentialName),
resource.TestCheckResourceAttr(resourceName, "name", credentialName),
}

checks := []resource.TestCheckFunc{
resource.TestCheckResourceAttr(resourceName, "meta.#", "1"),
resource.TestCheckResourceAttrSet(resourceName, "meta.0.uid"),
}

check := make([]resource.TestCheckFunc, 0, 2+len(checks))
check = append(check,
verifyCredentialResourceCreation(provider, resourceName, credentialName),
resource.TestCheckResourceAttr(resourceName, "name", credentialName),
)
check = append(check, checks...)

return resource.ComposeTestCheckFunc(check...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func formatAggregationRuleData(tfAggregationRule []interface{}, modelAggregation
}
}

aggregationRule = make([]interface{}, 0)
aggregationRule = make([]interface{}, 0, 1)
aggregationRuleMap := make(map[string]interface{})
aggregationRuleMap[ClusterRoleSelectorKey] = clusterRoleSelector
aggregationRule = append(aggregationRule, aggregationRuleMap)
Expand Down
8 changes: 4 additions & 4 deletions internal/resources/ekscluster/resource_ekscluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func setupHTTPMocks(t *testing.T, clusterName string) {
Rid: "test_rid",
UID: "test_uid",
}
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0)
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0, 1)
referenceArray = append(referenceArray, &reference)

postResponseModel := &eksmodel.VmwareTanzuManageV1alpha1EksclusterEksCluster{
Expand Down Expand Up @@ -149,9 +149,9 @@ func setupHTTPMocks(t *testing.T, clusterName string) {
}

// GET Nodepools mock setup
nodepools := make([]*eksmodel.VmwareTanzuManageV1alpha1EksclusterNodepoolNodepool, 0)
nodepoolRequests := make([]*eksmodel.VmwareTanzuManageV1alpha1EksclusterNodepoolAPIRequest, 0)
nodepoolResponses := make([]*eksmodel.VmwareTanzuManageV1alpha1EksclusterNodepoolAPIResponse, 0)
nodepools := make([]*eksmodel.VmwareTanzuManageV1alpha1EksclusterNodepoolNodepool, 0, len(nps))
nodepoolRequests := make([]*eksmodel.VmwareTanzuManageV1alpha1EksclusterNodepoolAPIRequest, 0, len(nps))
nodepoolResponses := make([]*eksmodel.VmwareTanzuManageV1alpha1EksclusterNodepoolAPIResponse, 0, len(nps))
nodepoolReadyPhase := eksmodel.VmwareTanzuManageV1alpha1EksclusterNodepoolStatusPhaseREADY

for count, nodepool := range nps {
Expand Down
4 changes: 2 additions & 2 deletions internal/resources/ekscluster/resource_nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ func flattenUpdateConfig(item *eksmodel.VmwareTanzuManageV1alpha1EksclusterNodep
}

func constructNodepools(nodepoolsDefData []interface{}) []*eksmodel.VmwareTanzuManageV1alpha1EksclusterNodepoolDefinition {
nodepools := []*eksmodel.VmwareTanzuManageV1alpha1EksclusterNodepoolDefinition{}
nodepools := make([]*eksmodel.VmwareTanzuManageV1alpha1EksclusterNodepoolDefinition, 0, len(nodepoolsDefData))

for _, npDefData := range nodepoolsDefData {
data, _ := npDefData.(map[string]interface{})
Expand Down Expand Up @@ -713,7 +713,7 @@ func constructUpdateConfig(data []interface{}) *eksmodel.VmwareTanzuManageV1alph
}

func constructTaints(taintsData []interface{}) []*eksmodel.VmwareTanzuManageV1alpha1EksclusterNodepoolTaint {
taints := []*eksmodel.VmwareTanzuManageV1alpha1EksclusterNodepoolTaint{}
taints := make([]*eksmodel.VmwareTanzuManageV1alpha1EksclusterNodepoolTaint, 0, len(taintsData))

for _, data := range taintsData {
taint := &eksmodel.VmwareTanzuManageV1alpha1EksclusterNodepoolTaint{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,14 @@ func (testConfig *testAcceptanceConfig) getTestGitRepositoryDataSourceBasicConfi

// checkGitRepositoryDataSourceAttributes checks to get git repository creation.
func (testConfig *testAcceptanceConfig) checkGitRepositoryDataSourceAttributes() resource.TestCheckFunc {
var check = []resource.TestCheckFunc{
metaChecks := MetaDataSourceAttributeCheck(testConfig.GitRepositoryDataSourceName, testConfig.GitRepositoryResourceName)
check := make([]resource.TestCheckFunc, 0, 3+len(metaChecks))
check = append(check,
testConfig.verifyGitRepositoryDataSourceCreation(testConfig.GitRepositoryDataSourceName),
resource.TestCheckResourceAttrPair(testConfig.GitRepositoryDataSourceName, "name", testConfig.GitRepositoryResourceName, "name"),
resource.TestCheckResourceAttrSet(testConfig.GitRepositoryDataSourceName, "id"),
}

check = append(check, MetaDataSourceAttributeCheck(testConfig.GitRepositoryDataSourceName, testConfig.GitRepositoryResourceName)...)
)
check = append(check, metaChecks...)

return resource.ComposeTestCheckFunc(check...)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (testConfig *testAcceptanceConfig) setupHTTPMocksUpdate(t *testing.T, scope
Rid: "test_rid",
UID: "test_uid",
}
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0)
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0, 1)
referenceArray = append(referenceArray, &reference)

switch scope {
Expand Down Expand Up @@ -235,7 +235,7 @@ func (testConfig *testAcceptanceConfig) setupHTTPMocks(t *testing.T) {
Rid: "test_rid",
UID: "test_uid",
}
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0)
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0, 1)
referenceArray = append(referenceArray, &reference)

// cluster level git repository resource.
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/helmcharts/helm_charts_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (testConfig *testAcceptanceConfig) setupHTTPMocks(t *testing.T) {
Rid: "test_rid",
UID: "test_uid",
}
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0)
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0, 1)
referenceArray = append(referenceArray, &reference)

// cluster level helm chart resource.
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/helmfeature/resource_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (testConfig *testAcceptanceConfig) setupHTTPMocks(t *testing.T) {
Rid: "test_rid",
UID: "test_uid",
}
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0)
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0, 1)
referenceArray = append(referenceArray, &reference)

// cluster level Helm resource.
Expand Down
4 changes: 2 additions & 2 deletions internal/resources/helmrelease/resource_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (testConfig *testAcceptanceConfig) setupHTTPMocksUpdate(t *testing.T, scope
Rid: "test_rid",
UID: "test_uid",
}
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0)
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0, 1)
referenceArray = append(referenceArray, &reference)

switch scope {
Expand Down Expand Up @@ -252,7 +252,7 @@ func (testConfig *testAcceptanceConfig) setupHTTPMocks(t *testing.T) {
Rid: "test_rid",
UID: "test_uid",
}
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0)
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0, 1)
referenceArray = append(referenceArray, &reference)

// cluster level Helm resource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (testConfig *testAcceptanceConfig) setupHTTPMocks(t *testing.T) {
Rid: "test_rid",
UID: "test_uid",
}
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0)
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0, 1)
referenceArray = append(referenceArray, &reference)

// cluster level package resource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ func (testConfig *testAcceptanceConfig) getTestDataSourceBasicConfigValue(scope
}

func (testConfig *testAcceptanceConfig) checkDataSourceAttributes() resource.TestCheckFunc {
var check = []resource.TestCheckFunc{
metaChecks := MetaDataSourceAttributeCheck(testConfig.DataSourceName, testConfig.SecretResourceName)
check := make([]resource.TestCheckFunc, 0, 3+len(metaChecks))
check = append(check,
testConfig.verifyDataSourceCreation(testConfig.DataSourceName),
resource.TestCheckResourceAttrPair(testConfig.DataSourceName, "name", testConfig.SecretResourceName, "name"),
resource.TestCheckResourceAttrSet(testConfig.DataSourceName, "id"),
}

check = append(check, MetaDataSourceAttributeCheck(testConfig.DataSourceName, testConfig.SecretResourceName)...)
)
check = append(check, metaChecks...)

return resource.ComposeTestCheckFunc(check...)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (testConfig *testAcceptanceConfig) setupHTTPMocksUpdate(t *testing.T, scope
Rid: "test_rid",
UID: "test_uid",
}
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0)
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0, 1)
referenceArray = append(referenceArray, &reference)

switch scope {
Expand Down Expand Up @@ -237,7 +237,7 @@ func (testConfig *testAcceptanceConfig) setupHTTPMocks(t *testing.T) {
Rid: "test_rid",
UID: "test_uid",
}
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0)
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0, 1)
referenceArray = append(referenceArray, &reference)

// cluster level Kustomization resorce.
Expand Down
9 changes: 5 additions & 4 deletions internal/resources/namespace/data_source_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ data "%s" "%s" {
}

func checkDataSourceAttributes(dataSourceName, resourceName string) resource.TestCheckFunc {
var check = []resource.TestCheckFunc{
metaChecks := testhelper.MetaDataSourceAttributeCheck(dataSourceName, resourceName)
check := make([]resource.TestCheckFunc, 0, 3+len(metaChecks))
check = append(check,
verifyNamespaceDataSource(dataSourceName),
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrSet(dataSourceName, "id"),
}

check = append(check, testhelper.MetaDataSourceAttributeCheck(dataSourceName, resourceName)...)
)
check = append(check, metaChecks...)

return resource.ComposeTestCheckFunc(check...)
}
Expand Down
9 changes: 5 additions & 4 deletions internal/resources/namespace/resource_namepace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,13 @@ resource "%s" "%s" {
}

func checkResourceAttributes(provider *schema.Provider, resourceName, clusterName, namespaceName string) resource.TestCheckFunc {
var check = []resource.TestCheckFunc{
metaChecks := testhelper.MetaResourceAttributeCheck(resourceName)
check := make([]resource.TestCheckFunc, 0, 2+len(metaChecks))
check = append(check,
verifyNamespaceResourceCreation(provider, resourceName, clusterName, namespaceName),
resource.TestCheckResourceAttr(resourceName, "name", namespaceName),
}

check = append(check, testhelper.MetaResourceAttributeCheck(resourceName)...)
)
check = append(check, metaChecks...)

return resource.ComposeTestCheckFunc(check...)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/package/package_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (testConfig *testAcceptanceConfig) setupHTTPMocks(t *testing.T) {
Rid: "test_rid",
UID: "test_uid",
}
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0)
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0, 1)
referenceArray = append(referenceArray, &reference)

// cluster level package resource.
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/packages/packages_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (testConfig *testAcceptanceConfig) setupHTTPMocks(t *testing.T) {
Rid: "test_rid",
UID: "test_uid",
}
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0)
referenceArray := make([]*objectmetamodel.VmwareTanzuCoreV1alpha1ObjectReference, 0, 1)
referenceArray = append(referenceArray, &reference)

// cluster level package resource.
Expand Down
4 changes: 2 additions & 2 deletions internal/resources/permissiontemplate/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ var undefinedTemplateValuesSchema = &schema.Schema{
func buildCapabilityProviderDescription(schemaKey string) (description string) {
if schemaKey == CapabilityKey {
description = "The Tanzu capability of the credentials."
validValues := make([]string, 0)
validValues := make([]string, 0, len(capabilityProviderMap))

for k, v := range capabilityProviderMap {
valueDescription := fmt.Sprintf("When %s is set to '%s' %s must be set to '%s'.", CapabilityKey, k, ProviderKey, v)
Expand All @@ -108,7 +108,7 @@ func buildCapabilityProviderDescription(schemaKey string) (description string) {
description = fmt.Sprintf("%s\nValid values are: %v", description, validValues)
} else if schemaKey == ProviderKey {
description = "The Tanzu provider of the credentials."
validValues := make([]string, 0)
validValues := make([]string, 0, len(capabilityProviderMap))

for k, v := range capabilityProviderMap {
valueDescription := fmt.Sprintf("When %s is set to '%s' %s must be set to '%s'.", ProviderKey, v, CapabilityKey, k)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func ValidateRecipeParameters(recipeSchema string, recipeParameters string) (err

recipeParametersJSON := make(map[string]interface{})
_ = json.Unmarshal([]byte(recipeParameters), &recipeParametersJSON)
errs = make([]error, 0)
errs = make([]error, 0, 2)

errs = append(errs, openAPIV3Validator.ValidateRequiredFields(recipeParametersJSON)...)
errs = append(errs, openAPIV3Validator.ValidateFormat(recipeParametersJSON)...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func FlattenAnnotation(mutationAnnotation *policyrecipemutationmodel.VmwareTanzu
}

func flattenKeyValuesFromAnnotation(keyValue *policyrecipemutationcommonmodel.KeyValue) []interface{} {
var annotationKeyValue []interface{}
annotationKeyValue := make([]interface{}, 0, 1)

flattenAnnotationValue := make(map[string]interface{})
flattenAnnotationValue[keyKey] = keyValue.Key
Expand Down
Loading