Skip to content

Commit

Permalink
feat: Enhaced acceptance test coverage (#381)
Browse files Browse the repository at this point in the history
* feat: Enhaced acceptance test coverage

* (doc): Updated changelog and release-notes

* fix: Applied linter and other go tools
  • Loading branch information
willguibr authored Oct 27, 2023
1 parent 1075425 commit 292278d
Show file tree
Hide file tree
Showing 78 changed files with 652 additions and 277 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/reuse-zpa-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,33 @@ jobs:
with:
go-version: ${{ matrix.go-version }}
id: go

- uses: hashicorp/setup-terraform@v2
with:
terraform_version: '>=0.13.x'
terraform_wrapper: false
- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Download Go Dependencies
run: |
go mod tidy && go mod vendor
- name: Setup Go Tools
run: make tools

- name: Check Formatting
run: make fmtcheck

- name: Vet Code
run: make vet

- name: Lint Code
run: make lint

- name: Check Build
run: make build

- name: Run tests with retry
uses: nick-invision/retry@v2
with:
Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
name: Test
on:
push:
branches:
- master
- develop
- beta
- alpha
- '[0-9]+.x'
- '[0-9]+.[0-9]+.x'
branches: [ master ]
pull_request:
branches: [ master ]

# For systems with an upstream API that could drift unexpectedly (like most SaaS systems, etc.),
# we recommend testing at a regular interval not necessarily tied to code changes. This will
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- [PR #375](/~https://github.com/zscaler/terraform-provider-zpa/pull/375) - Fixed drift issues in ``zpa_application_segment_pra`` and ``zpa_application_segment_inspection`` when setting up ``apps_config`` options.
- [PR #375](/~https://github.com/zscaler/terraform-provider-zpa/pull/375) - Upgrade to [Zscaler-SDK-GO v2.1.3](/~https://github.com/zscaler/zscaler-sdk-go/releases/tag/v2.1.3). The upgrade allows searches for resources in which the name include 1 or more spaces.
- [PR #380](/~https://github.com/zscaler/terraform-provider-zpa/pull/380) - Fixed provider authentication to accept `ZPA_CLOUD` via environment variables.
- [PR #381](/~https://github.com/zscaler/terraform-provider-zpa/pull/381) - Included and fixed additional acceptance test cases for several resources and datasources

## 3.0.2 (September, 30 2023)

Expand Down
78 changes: 47 additions & 31 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ default: build
dep: # Download required dependencies
go mod tidy

docs:
go generate

build: fmtcheck
go install

Expand All @@ -38,7 +41,7 @@ sweep:

test:
echo $(TEST) | \
xargs -t -n4 go test $(TESTARGS) $(TEST_FILTER) -timeout=30s -parallel=10
xargs -t -n4 go test $(TESTARGS) $(TEST_FILTER) -timeout=30s -parallel=20

testacc:
TF_ACC=1 go test $(TEST) $(TESTARGS) $(TEST_FILTER) -timeout 120m
Expand All @@ -56,48 +59,31 @@ build13: fmtcheck
@mkdir -p $(DESTINATION)
go build -o $(DESTINATION)/terraform-provider-zpa_v3.0.3

lint: vendor
@echo "✓ Linting source code with https://staticcheck.io/ ..."
@go run honnef.co/go/tools/cmd/staticcheck@v0.4.0 ./...

coverage: test
@echo "✓ Opening coverage for unit tests ..."
@go tool cover -html=coverage.txt

vet:
@echo "==> Checking source code against go vet and staticcheck"
@echo "go vet ."
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \
echo ""; \
echo "Vet found suspicious constructs. Please check the reported constructs"; \
echo "and fix them if necessary before submitting the code for review."; \
exit 1; \
fi
@go vet ./...
@staticcheck ./...

imports:
goimports -w $(GOFMT_FILES)

fmt:
@echo "✓ Formatting source code with goimports ..."
@go run golang.org/x/tools/cmd/goimports@latest -w $(shell find . -type f -name '*.go' -not -path "./vendor/*")
@echo "✓ Formatting source code with gofmt ..."
@gofmt -w $(shell find . -type f -name '*.go' -not -path "./vendor/*")
fmt: tools # Format the code
@echo "formatting the code with $(GOFMT)..."
@$(GOFMT) -l -w .

fmtcheck:
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"

fmt-docs:
@echo "✓ Formatting code samples in documentation"
@terrafmt fmt -p '*.md' .


errcheck:
@sh -c "'$(CURDIR)/scripts/errcheck.sh'"

tools:
@echo "==> installing required tooling..."
@sh "$(CURDIR)/scripts/gogetcookie.sh"
GO111MODULE=off go get -u github.com/client9/misspell/cmd/misspell
fmt-docs:
@echo "✓ Formatting code samples in documentation"
@terrafmt fmt -p '*.md' .

vendor-status:
@govendor status
Expand All @@ -110,22 +96,52 @@ test-compile:
fi
go test -c $(TEST) $(TESTARGS)

lint:
@echo "==> Checking source code against linters..."
@$(TFPROVIDERLINT) \
-c 1 \
-AT001 \
-R004 \
-S001 \
-S002 \
-S003 \
-S004 \
-S005 \
-S007 \
-S008 \
-S009 \
-S010 \
-S011 \
-S012 \
-S013 \
-S014 \
-S015 \
-S016 \
-S017 \
-S019 \
./$(PKG_NAME)

tools:
@which $(GOFMT) || go install mvdan.cc/gofumpt@v0.5.0
@which $(TFPROVIDERLINT) || go install github.com/bflad/tfproviderlint/cmd/tfproviderlint@v0.29.0
@which $(STATICCHECK) || go install honnef.co/go/tools/cmd/staticcheck@v0.4.6

tools-update:
@go install mvdan.cc/gofumpt@v0.5.0
@go install github.com/bflad/tfproviderlint/cmd/tfproviderlint@v0.29.0
@go install honnef.co/go/tools/cmd/staticcheck@v0.4.6

website:
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)

website-lint:
@echo "==> Checking website against linters..."
@misspell -error -source=text website/

website-test:
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)

.PHONY: build test testacc vet fmt fmtcheck errcheck tools vendor-status test-compile website-lint website website-test
1 change: 1 addition & 0 deletions docs/guides/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Track all ZPA Terraform provider's releases. New resources, features, and bug fi
- [PR #375](/~https://github.com/zscaler/terraform-provider-zpa/pull/375) - Fixed drift issues in ``zpa_application_segment_pra`` and ``zpa_application_segment_inspection`` when setting up ``apps_config`` options.
- [PR #375](/~https://github.com/zscaler/terraform-provider-zpa/pull/375) - Upgrade to [Zscaler-SDK-GO v2.1.3](/~https://github.com/zscaler/zscaler-sdk-go/releases/tag/v2.1.3). The upgrade allows searches for resources in which the name include 1 or more spaces.
- [PR #380](/~https://github.com/zscaler/terraform-provider-zpa/pull/380) - Fixed provider authentication to accept `ZPA_CLOUD` via environment variables.
- [PR #381](/~https://github.com/zscaler/terraform-provider-zpa/pull/381) - Included and fixed additional acceptance test cases for several resources and datasources

## 3.0.2 (September, 30 2023)

Expand Down
11 changes: 8 additions & 3 deletions zpa/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (
"github.com/zscaler/zscaler-sdk-go/v2/zpa/services/policysetcontroller"
)

var policySets = map[string]policysetcontroller.PolicySet{}
var policySetsMutex sync.Mutex
var (
policySets = map[string]policysetcontroller.PolicySet{}
policySetsMutex sync.Mutex
)

// Common values shared between Service Edge Groups and App Connector Groups
var versionProfileNameIDMapping map[string]string = map[string]string{
Expand Down Expand Up @@ -48,6 +50,7 @@ func ValidateConditions(conditions []policysetcontroller.Conditions, zClient *Cl
}
return nil
}

func validateOperands(operands []policysetcontroller.Operands, zClient *Client, microtenantID string) error {
for _, operand := range operands {
if err := validateOperand(operand, zClient, microtenantID); err != nil {
Expand Down Expand Up @@ -157,7 +160,6 @@ func validateOperand(operand policysetcontroller.Operands, zClient *Client, micr
values, _ := zClient.scimattributeheader.SearchValues(scim.IdpID, scim.ID, operand.RHS)
if len(values) == 0 {
return rhsWarn(operand.ObjectType, fmt.Sprintf("valid SCIM Attribute Value (%s)", values), operand.RHS, nil)

}
return nil
case "SCIM_GROUP":
Expand Down Expand Up @@ -191,6 +193,7 @@ type Getter func(id string) error
func (g Getter) Get(id string) error {
return g(id)
}

func customValidate(operand policysetcontroller.Operands, expectedLHS []string, expectedRHS string, clientRHS Getter) error {
if operand.LHS == "" || !contains(expectedLHS, operand.LHS) {
return lhsWarn(operand.ObjectType, expectedLHS, operand.LHS, nil)
Expand All @@ -204,9 +207,11 @@ func customValidate(operand policysetcontroller.Operands, expectedLHS []string,
}
return nil
}

func rhsWarn(objType, expected, rhs interface{}, err error) error {
return fmt.Errorf("[WARN] when operand object type is %v RHS must be %#v, value is \"%v\", %v", objType, expected, rhs, err)
}

func lhsWarn(objType, expected, lhs interface{}, err error) error {
return fmt.Errorf("[WARN] when operand object type is %v LHS must be %#v value is \"%v\", %v", objType, expected, lhs, err)
}
Expand Down
1 change: 1 addition & 0 deletions zpa/common/resourcetype/resource_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ const (
ZPALSSController = "zpa_lss_config_controller"
ZPAInspectionCustomControl = "zpa_inspection_custom_controls"
ZPAInspectionProfile = "zpa_inspection_profile"
ZPAMicrotenant = "zpa_microtenant_controller"
)
1 change: 0 additions & 1 deletion zpa/common/testing/method/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ func GenerateRandomSourcesTypeAndName(sourceType string) (string, string, string
resource := fmt.Sprintf("%s.%s", sourceType, name)
dataSource := fmt.Sprintf("data.%s.%s", sourceType, name)
return resource, dataSource, name

}
34 changes: 33 additions & 1 deletion zpa/common/testing/variable/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ const (
UseInDrMode = false
)

// App Connector Group Update
const (
AppConnectorResourceNameUpdate = "testAcc_app_connector_group"
AppConnectorDescriptionUpdate = "this is update app connector group test"
AppConnectorEnabledUpdate = true
AppConnectorOverrideProfileUpdate = true
TCPQuickAckAppUpdate = true
TCPQuickAckAssistantUpdate = true
TCPQuickAckReadAssistantUpdate = true
UseInDrModeUpdate = false
)

// Service Edge Group
const (
ServiceEdgeResourceName = "testAcc_service_edge_group"
Expand Down Expand Up @@ -51,16 +63,28 @@ const (
const (
ServerGroupResourceName = "testAcc_server_group"
ServerGroupDescription = "testAcc_server_group"
ServerGroupEnabled = true
ServerGroupEnabled = false
ServerGroupDynamicDiscovery = true
)

// Segment Group Update
const (
ServerGroupDescriptionUpdate = "this update the server group test"
ServerGroupEnabledUpdate = true
)

// Segment Group
const (
SegmentGroupDescription = "testAcc_segment_group"
SegmentGroupEnabled = true
)

// Segment Group Update
const (
SegmentGroupDescriptionUpdate = "testAcc_segment_group"
SegmentGroupEnabledUpdate = true
)

// Application Segment
const (
AppSegmentResourceName = "testAcc_app_segment"
Expand Down Expand Up @@ -121,3 +145,11 @@ const (
const (
InspectionProfileDescription = "testAcc_access_rule"
)

// Microtenant
const (
MicrotenantName = "testAcc_microtenant_A"
MicrotenantDescription = "testAcc_microtenant_A"
MicrotenantEnabled = true
MicrotenantCriteriaAttribute = "AuthDomain"
)
4 changes: 1 addition & 3 deletions zpa/common/version.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package common

var (
version = "3.0.2"
)
var version = "3.0.2"

// Version returns version of provider
func Version() string {
Expand Down
1 change: 0 additions & 1 deletion zpa/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ type Client struct {
}

type Config struct {

// ZPA Client ID for API Client
ClientID string

Expand Down
11 changes: 9 additions & 2 deletions zpa/data_source_zpa_access_policy_client_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ func TestAccDataSourceAccessPolicyClientTypes_Basic(t *testing.T) {
{
Config: (testAccCheckDataSourceAccessPolicyClientTypes_basic),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckNoResourceAttr(
"data.zpa_access_policy_client_types.this", ""),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_client_types.this", "zpn_client_type_exporter"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_client_types.this", "zpn_client_type_exporter_noauth"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_client_types.this", "zpn_client_type_browser_isolation"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_client_types.this", "zpn_client_type_machine_tunnel"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_client_types.this", "zpn_client_type_ip_anchoring"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_client_types.this", "zpn_client_type_edge_connector"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_client_types.this", "zpn_client_type_zapp"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_client_types.this", "zpn_client_type_slogger"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_client_types.this", "zpn_client_type_branch_connector"),
),
},
},
Expand Down
9 changes: 6 additions & 3 deletions zpa/data_source_zpa_access_policy_platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ func TestAccDataSourceAccessPolicyPlatforms_Basic(t *testing.T) {
ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: (testAccCheckDataSourceAccessPolicyPlatforms_basic),
Config: testAccCheckDataSourceAccessPolicyPlatforms_basic,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckNoResourceAttr(
"data.zpa_access_policy_platforms.this", ""),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_platforms.this", "linux"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_platforms.this", "android"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_platforms.this", "windows"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_platforms.this", "ios"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_platforms.this", "mac"),
),
},
},
Expand Down
1 change: 0 additions & 1 deletion zpa/data_source_zpa_application_segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ func dataSourceApplicationSegmentRead(d *schema.ResourceData, m interface{}) err
}

return nil

}

func flattenAppServerGroups(serverGroup *applicationsegment.ApplicationSegmentResource) []interface{} {
Expand Down
1 change: 0 additions & 1 deletion zpa/data_source_zpa_application_segment_browser_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,4 @@ func dataSourceApplicationSegmentBrowserAccessRead(d *schema.ResourceData, m int
}

return nil

}
1 change: 0 additions & 1 deletion zpa/data_source_zpa_application_segment_inspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ func dataSourceApplicationSegmentInspectionRead(d *schema.ResourceData, m interf
}

return nil

}

func flattenInspectionAppServerGroups(appServerGroup []applicationsegmentinspection.AppServerGroups) []interface{} {
Expand Down
Loading

0 comments on commit 292278d

Please sign in to comment.