diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fc5ce2f4..31258383 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -120,14 +120,13 @@ jobs: needs: build runs-on: ubuntu-latest if: "!github.event.pull_request.head.repo.fork" - timeout-minutes: 15 strategy: - max-parallel: 2 + max-parallel: 3 fail-fast: false matrix: terraform: - '1.8.*' - - '1.9.*' +# - '1.9.*' - 'latest' steps: @@ -161,6 +160,7 @@ jobs: TWINGATE_API_TOKEN: ${{ secrets.TWINGATE_API_TOKEN }} TEST_UNIQUE_VALUE: ${{ github.run_id }}-${{ github.run_number }}-${{ matrix.terraform }} run: | + terraform version make testacc - name: Send coverage @@ -175,13 +175,13 @@ jobs: needs: build runs-on: ubuntu-latest if: "!github.event.pull_request.head.repo.fork" - timeout-minutes: 15 strategy: - max-parallel: 2 + max-parallel: 3 fail-fast: false matrix: tofu: - '1.6.*' + - '1.7.*' - 'latest' steps: @@ -224,7 +224,7 @@ jobs: cleanup: name: Cleanup - if: "!github.event.pull_request.head.repo.fork" + if: '!github.event.pull_request.head.repo.fork && always()' needs: [tests-acceptance, tests-acceptance-opentofu] runs-on: ubuntu-latest timeout-minutes: 15 diff --git a/.github/workflows/smoketests.yml b/.github/workflows/smoketests.yml index b3edaeee..3525f2f7 100644 --- a/.github/workflows/smoketests.yml +++ b/.github/workflows/smoketests.yml @@ -40,14 +40,13 @@ jobs: name: Matrix Acceptance Tests needs: build runs-on: ubuntu-latest - timeout-minutes: 15 strategy: - max-parallel: 2 + max-parallel: 3 fail-fast: false matrix: terraform: - '1.8.*' - - '1.9.*' +# - '1.9.*' - 'latest' steps: - name: Check out code into the Go module directory @@ -94,6 +93,7 @@ jobs: TWINGATE_API_TOKEN: ${{ secrets.TWINGATE_API_TOKEN }} TEST_UNIQUE_VALUE: ${{ github.run_id }}-${{ github.run_number }}-${{ matrix.terraform }} run: | + terraform version make testacc - name: Report Status @@ -112,14 +112,13 @@ jobs: name: OpenTofu Matrix Acceptance Tests needs: build runs-on: ubuntu-latest - if: "!github.event.pull_request.head.repo.fork" - timeout-minutes: 15 strategy: - max-parallel: 2 + max-parallel: 3 fail-fast: false matrix: tofu: - '1.6.*' + - '1.7.*' - 'latest' steps: @@ -162,7 +161,7 @@ jobs: cleanup: name: Cleanup - if: always() + if: '!github.event.pull_request.head.repo.fork && always()' needs: [tests-acceptance, tests-acceptance-opentofu] runs-on: ubuntu-latest timeout-minutes: 15 diff --git a/.go-version b/.go-version index 71f7f51d..a1b6e17d 100644 --- a/.go-version +++ b/.go-version @@ -1 +1 @@ -1.22 +1.23 diff --git a/.tool-versions b/.tool-versions index 2ffc68b7..01bf8091 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,3 +1,3 @@ -golang 1.22.0 +golang 1.23.2 python 3.12.2 terraform 1.9.2 diff --git a/go.mod b/go.mod index 5dc4c122..1eceb97d 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,6 @@ module github.com/Twingate/terraform-provider-twingate/v3 -go 1.22.0 - -toolchain go1.22.5 +go 1.23.2 require ( github.com/client9/misspell v0.3.4 @@ -11,7 +9,7 @@ require ( github.com/hashicorp/go-uuid v1.0.3 github.com/hashicorp/terraform-plugin-docs v0.19.4 github.com/hashicorp/terraform-plugin-framework v1.13.0 - github.com/hashicorp/terraform-plugin-framework-validators v0.14.0 + github.com/hashicorp/terraform-plugin-framework-validators v0.15.0 github.com/hashicorp/terraform-plugin-go v0.25.0 github.com/hashicorp/terraform-plugin-testing v1.10.0 github.com/hasura/go-graphql-client v0.13.1 diff --git a/go.sum b/go.sum index 7f35c9e0..5ccb682a 100644 --- a/go.sum +++ b/go.sum @@ -178,8 +178,8 @@ github.com/hashicorp/terraform-plugin-docs v0.19.4 h1:G3Bgo7J22OMtegIgn8Cd/CaSey github.com/hashicorp/terraform-plugin-docs v0.19.4/go.mod h1:4pLASsatTmRynVzsjEhbXZ6s7xBlUw/2Kt0zfrq8HxA= github.com/hashicorp/terraform-plugin-framework v1.13.0 h1:8OTG4+oZUfKgnfTdPTJwZ532Bh2BobF4H+yBiYJ/scw= github.com/hashicorp/terraform-plugin-framework v1.13.0/go.mod h1:j64rwMGpgM3NYXTKuxrCnyubQb/4VKldEKlcG8cvmjU= -github.com/hashicorp/terraform-plugin-framework-validators v0.14.0 h1:3PCn9iyzdVOgHYOBmncpSSOxjQhCTYmc+PGvbdlqSaI= -github.com/hashicorp/terraform-plugin-framework-validators v0.14.0/go.mod h1:LwDKNdzxrDY/mHBrlC6aYfE2fQ3Dk3gaJD64vNiXvo4= +github.com/hashicorp/terraform-plugin-framework-validators v0.15.0 h1:RXMmu7JgpFjnI1a5QjMCBb11usrW2OtAG+iOTIj5c9Y= +github.com/hashicorp/terraform-plugin-framework-validators v0.15.0/go.mod h1:Bh89/hNmqsEWug4/XWKYBwtnw3tbz5BAy1L1OgvbIaY= github.com/hashicorp/terraform-plugin-go v0.25.0 h1:oi13cx7xXA6QciMcpcFi/rwA974rdTxjqEhXJjbAyks= github.com/hashicorp/terraform-plugin-go v0.25.0/go.mod h1:+SYagMYadJP86Kvn+TGeV+ofr/R3g4/If0O5sO96MVw= github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0= diff --git a/scripts/test.sh b/scripts/test.sh index 67f6211f..feaa2f10 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -10,7 +10,7 @@ mkdir -p "${TEST_RESULTS}" echo PACKAGE_NAME: "$PACKAGE_NAME" echo "Running tests:" -go run gotest.tools/gotestsum --rerun-fails --packages "${PACKAGE_NAME}" --format standard-quiet --junitfile "${TEST_RESULTS}"/test-results.xml -- -coverpkg="${PACKAGE_NAME}" -coverprofile="${TEST_RESULTS}"/coverage.out.tmp "${PACKAGE_NAME}" +go run gotest.tools/gotestsum --rerun-fails=5 --packages "${PACKAGE_NAME}" --format standard-quiet --junitfile "${TEST_RESULTS}"/test-results.xml -- -coverpkg="${PACKAGE_NAME}" -coverprofile="${TEST_RESULTS}"/coverage.out.tmp "${PACKAGE_NAME}" echo echo "Generating coverage report (removing generated **/api/gen/** and *.pb.go files)" diff --git a/twingate/internal/client/client.go b/twingate/internal/client/client.go index 6357ee0c..bfc9c0a3 100644 --- a/twingate/internal/client/client.go +++ b/twingate/internal/client/client.go @@ -339,6 +339,19 @@ func (client *Client) mutate(ctx context.Context, resp MutationResponse, variabl return nil } +func (client *Client) mutateWithTimeout(ctx context.Context, resp MutationResponse, variables map[string]any, opr operation, attrs ...attr) error { + var err error + + for i := 0; i == 0 || err != nil && (strings.Contains(err.Error(), "timeout") || strings.Contains(err.Error(), "deadline")) && i < defaultQueryRetries; i++ { + timeoutCtx, cancel := context.WithTimeout(ctx, defaultQueryTimeout) + err = client.mutate(timeoutCtx, resp, variables, opr, attrs...) + + cancel() + } + + return err +} + type ResponseWithPayload interface { IsEmpty() bool } diff --git a/twingate/internal/client/dns-filtering-profile.go b/twingate/internal/client/dns-filtering-profile.go index b197f80c..658228cd 100644 --- a/twingate/internal/client/dns-filtering-profile.go +++ b/twingate/internal/client/dns-filtering-profile.go @@ -11,7 +11,7 @@ func (client *Client) ReadShallowDNSFilteringProfiles(ctx context.Context) ([]*m opr := resourceDNSFilteringProfile.read().withCustomName("readShallowDNSFilteringProfiles") response := query.ReadDNSFilteringProfiles{} - if err := client.query(ctx, &response, nil, opr, attr{id: "All"}); err != nil { + if err := client.queryWithTimeout(ctx, &response, nil, opr, attr{id: "All"}); err != nil { return nil, err } @@ -59,7 +59,7 @@ func (client *Client) CreateDNSFilteringProfile(ctx context.Context, name string ) var response query.CreateDNSFilteringProfile - if err := client.mutate(ctx, &response, variables, opr, attr{name: name}); err != nil { + if err := client.mutateWithTimeout(ctx, &response, variables, opr, attr{name: name}); err != nil { return nil, err } @@ -169,7 +169,7 @@ func (client *Client) UpdateDNSFilteringProfile(ctx context.Context, input *mode ) var response query.UpdateDNSFilteringProfile - if err := client.mutate(ctx, &response, variables, opr, attr{id: input.ID}); err != nil { + if err := client.mutateWithTimeout(ctx, &response, variables, opr, attr{id: input.ID}); err != nil { return nil, err } @@ -188,7 +188,7 @@ func (client *Client) readDNSFilteringProfileGroupsAfter(ctx context.Context, va variables[query.CursorGroups] = cursor response := query.ReadDNSFilteringProfileGroups{} - if err := client.query(ctx, &response, variables, opr, attr{id: "All"}); err != nil { + if err := client.queryWithTimeout(ctx, &response, variables, opr, attr{id: "All"}); err != nil { return nil, err } @@ -204,5 +204,5 @@ func (client *Client) DeleteDNSFilteringProfile(ctx context.Context, profileID s var response query.DeleteDNSFilteringProfile - return client.mutate(ctx, &response, newVars(gqlID(profileID)), opr, attr{id: profileID}) + return client.mutateWithTimeout(ctx, &response, newVars(gqlID(profileID)), opr, attr{id: profileID}) } diff --git a/twingate/internal/test/acctests/datasource/connector_test.go b/twingate/internal/test/acctests/datasource/connector_test.go index bd7ead9b..95381d35 100644 --- a/twingate/internal/test/acctests/datasource/connector_test.go +++ b/twingate/internal/test/acctests/datasource/connector_test.go @@ -13,24 +13,24 @@ import ( ) func TestAccDatasourceTwingateConnector_basic(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Connector Basic", func(t *testing.T) { - networkName := test.RandomName() - connectorName := test.RandomConnectorName() - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateConnectorDestroy, - Steps: []resource.TestStep{ - { - Config: testDatasourceTwingateConnector(networkName, connectorName), - Check: acctests.ComposeTestCheckFunc( - resource.TestCheckOutput("my_connector", connectorName), - resource.TestCheckOutput("my_connector_notification_status", "true"), - ), - }, + t.Parallel() + + networkName := test.RandomName() + connectorName := test.RandomConnectorName() + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateConnectorDestroy, + Steps: []resource.TestStep{ + { + Config: testDatasourceTwingateConnector(networkName, connectorName), + Check: acctests.ComposeTestCheckFunc( + resource.TestCheckOutput("my_connector", connectorName), + resource.TestCheckOutput("my_connector_notification_status", "true"), + ), }, - }) + }, }) } @@ -59,21 +59,21 @@ func testDatasourceTwingateConnector(remoteNetworkName, connectorName string) st } func TestAccDatasourceTwingateConnector_negative(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Connector - does not exists", func(t *testing.T) { - connectorID := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("Connector:%d", acctest.RandInt()))) + t.Parallel() - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { - acctests.PreCheck(t) - }, - Steps: []resource.TestStep{ - { - Config: testTwingateConnectorDoesNotExists(connectorID), - ExpectError: regexp.MustCompile("failed to read connector with id"), - }, + connectorID := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("Connector:%d", acctest.RandInt()))) + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { + acctests.PreCheck(t) + }, + Steps: []resource.TestStep{ + { + Config: testTwingateConnectorDoesNotExists(connectorID), + ExpectError: regexp.MustCompile("failed to read connector with id"), }, - }) + }, }) } @@ -90,20 +90,20 @@ func testTwingateConnectorDoesNotExists(id string) string { } func TestAccDatasourceTwingateConnector_invalidID(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Connector - failed parse ID", func(t *testing.T) { - connectorID := acctest.RandString(10) + t.Parallel() - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { - acctests.PreCheck(t) - }, - Steps: []resource.TestStep{ - { - Config: testTwingateConnectorDoesNotExists(connectorID), - ExpectError: regexp.MustCompile("failed to read connector with id"), - }, + connectorID := acctest.RandString(10) + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { + acctests.PreCheck(t) + }, + Steps: []resource.TestStep{ + { + Config: testTwingateConnectorDoesNotExists(connectorID), + ExpectError: regexp.MustCompile("failed to read connector with id"), }, - }) + }, }) } diff --git a/twingate/internal/test/acctests/datasource/connectors_test.go b/twingate/internal/test/acctests/datasource/connectors_test.go index 9125e413..206bf64d 100644 --- a/twingate/internal/test/acctests/datasource/connectors_test.go +++ b/twingate/internal/test/acctests/datasource/connectors_test.go @@ -19,7 +19,7 @@ var ( ) func TestAccDatasourceTwingateConnectors_basic(t *testing.T) { - acctests.SetPageLimit(1) + t.Parallel() networkName1 := test.RandomName() networkName2 := test.RandomName() @@ -69,6 +69,7 @@ func testDatasourceTwingateConnectors(networkName1, connectorName1, networkName2 } func TestAccDatasourceTwingateConnectors_emptyResult(t *testing.T) { + t.Parallel() prefix := acctest.RandString(10) resource.Test(t, resource.TestCase{ @@ -153,48 +154,6 @@ func testCheckOutputAttr(name string, index int, attr string, expected interface } } -func testCheckOutputNestedLen(name string, index int, attr string, length int) resource.TestCheckFunc { - return func(s *terraform.State) error { - ms := s.RootModule() - - res, ok := ms.Outputs[name] - if !ok || res == nil || res.Value == nil { - return fmt.Errorf("output '%s' not found", name) - } - - list, ok := res.Value.([]interface{}) - if !ok { - return fmt.Errorf("output '%s' is not a list", name) - } - - if index >= len(list) { - return fmt.Errorf("index out of bounds, actual length %d", len(list)) - } - - item := list[index] - obj, ok := item.(map[string]interface{}) - if !ok { - return fmt.Errorf("expected map, actual is %T", item) - } - - actual, ok := obj[attr] - if !ok { - return fmt.Errorf("attribute '%s' not found", attr) - } - - attrList, ok := actual.([]interface{}) - if !ok { - return fmt.Errorf("output '%s' is not a list", attr) - } - - if len(attrList) != length { - return fmt.Errorf("expected length %d, got %d", length, len(attrList)) - } - - return nil - } -} - func TestAccDatasourceTwingateConnectorsFilterByName(t *testing.T) { t.Parallel() diff --git a/twingate/internal/test/acctests/datasource/dns-filtering-profile_test.go b/twingate/internal/test/acctests/datasource/dns-filtering-profile_test.go index 15ffdb1d..540ea965 100644 --- a/twingate/internal/test/acctests/datasource/dns-filtering-profile_test.go +++ b/twingate/internal/test/acctests/datasource/dns-filtering-profile_test.go @@ -11,6 +11,8 @@ import ( ) func TestAccDatasourceTwingateDNSFilteringProfile_basic(t *testing.T) { + t.Parallel() + testName := "t" + acctest.RandString(6) profileName := test.RandomName() diff --git a/twingate/internal/test/acctests/datasource/group_test.go b/twingate/internal/test/acctests/datasource/group_test.go index 3724633b..b1621778 100644 --- a/twingate/internal/test/acctests/datasource/group_test.go +++ b/twingate/internal/test/acctests/datasource/group_test.go @@ -13,32 +13,32 @@ import ( ) func TestAccDatasourceTwingateGroup_basic(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Group Basic", func(t *testing.T) { - groupName := test.RandomName() - - securityPolicies, err := acctests.ListSecurityPolicies() - if err != nil { - t.Skip("can't run test:", err) - } - - testPolicy := securityPolicies[0] - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateGroupDestroy, - Steps: []resource.TestStep{ - { - Config: testDatasourceTwingateGroup(groupName, testPolicy.ID), - Check: acctests.ComposeTestCheckFunc( - resource.TestCheckOutput("my_group_dg1", groupName), - resource.TestCheckOutput("my_group_is_active_dg1", "true"), - resource.TestCheckOutput("my_group_type_dg1", "MANUAL"), - resource.TestCheckOutput("my_group_policy_dg1", testPolicy.ID), - ), - }, + t.Parallel() + + groupName := test.RandomName() + + securityPolicies, err := acctests.ListSecurityPolicies() + if err != nil { + t.Skip("can't run test:", err) + } + + testPolicy := securityPolicies[0] + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateGroupDestroy, + Steps: []resource.TestStep{ + { + Config: testDatasourceTwingateGroup(groupName, testPolicy.ID), + Check: acctests.ComposeTestCheckFunc( + resource.TestCheckOutput("my_group_dg1", groupName), + resource.TestCheckOutput("my_group_is_active_dg1", "true"), + resource.TestCheckOutput("my_group_type_dg1", "MANUAL"), + resource.TestCheckOutput("my_group_policy_dg1", testPolicy.ID), + ), }, - }) + }, }) } @@ -72,21 +72,21 @@ func testDatasourceTwingateGroup(name, securityPolicyID string) string { } func TestAccDatasourceTwingateGroup_negative(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Group - does not exists", func(t *testing.T) { - groupID := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("Group:%d", acctest.RandInt()))) - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { - acctests.PreCheck(t) - }, - Steps: []resource.TestStep{ - { - Config: testTwingateGroupDoesNotExists(groupID), - ExpectError: regexp.MustCompile("failed to read group with id"), - }, + t.Parallel() + + groupID := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("Group:%d", acctest.RandInt()))) + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { + acctests.PreCheck(t) + }, + Steps: []resource.TestStep{ + { + Config: testTwingateGroupDoesNotExists(groupID), + ExpectError: regexp.MustCompile("failed to read group with id"), }, - }) + }, }) } @@ -99,20 +99,20 @@ func testTwingateGroupDoesNotExists(id string) string { } func TestAccDatasourceTwingateGroup_invalidGroupID(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Group - failed parse group ID", func(t *testing.T) { - groupID := acctest.RandString(10) - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { - acctests.PreCheck(t) - }, - Steps: []resource.TestStep{ - { - Config: testTwingateGroupDoesNotExists(groupID), - ExpectError: regexp.MustCompile("failed to read group with id"), - }, + t.Parallel() + + groupID := acctest.RandString(10) + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { + acctests.PreCheck(t) + }, + Steps: []resource.TestStep{ + { + Config: testTwingateGroupDoesNotExists(groupID), + ExpectError: regexp.MustCompile("failed to read group with id"), }, - }) + }, }) } diff --git a/twingate/internal/test/acctests/datasource/groups_test.go b/twingate/internal/test/acctests/datasource/groups_test.go index debc436a..e89c60a8 100644 --- a/twingate/internal/test/acctests/datasource/groups_test.go +++ b/twingate/internal/test/acctests/datasource/groups_test.go @@ -95,7 +95,7 @@ func testTwingateGroupsDoesNotExists(name string) string { } func TestAccDatasourceTwingateGroupsWithFilters_basic(t *testing.T) { - acctests.SetPageLimit(1) + t.Parallel() groupName := test.RandomName() const theDatasource = "data.twingate_groups.out_dgs2" diff --git a/twingate/internal/test/acctests/datasource/remote-network_test.go b/twingate/internal/test/acctests/datasource/remote-network_test.go index 42e949d3..90b2b86f 100644 --- a/twingate/internal/test/acctests/datasource/remote-network_test.go +++ b/twingate/internal/test/acctests/datasource/remote-network_test.go @@ -14,24 +14,23 @@ import ( ) func TestAccDatasourceTwingateRemoteNetwork_basic(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Remote Network Basic", func(t *testing.T) { - - networkName := test.RandomName() - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateRemoteNetworkDestroy, - Steps: []resource.TestStep{ - { - Config: testDatasourceTwingateRemoteNetwork(networkName), - Check: acctests.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.twingate_remote_network.test_dn1_2", attr.Name, networkName), - ), - ExpectNonEmptyPlan: true, - }, + t.Parallel() + + networkName := test.RandomName() + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateRemoteNetworkDestroy, + Steps: []resource.TestStep{ + { + Config: testDatasourceTwingateRemoteNetwork(networkName), + Check: acctests.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.twingate_remote_network.test_dn1_2", attr.Name, networkName), + ), + ExpectNonEmptyPlan: true, }, - }) + }, }) } @@ -52,23 +51,22 @@ func testDatasourceTwingateRemoteNetwork(name string) string { } func TestAccDatasourceTwingateRemoteNetworkByName_basic(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Remote Network Basic", func(t *testing.T) { - - networkName := test.RandomName() - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateRemoteNetworkDestroy, - Steps: []resource.TestStep{ - { - Config: testDatasourceTwingateRemoteNetworkByName(networkName), - Check: acctests.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.twingate_remote_network.test_dn2_2", attr.Name, networkName), - ), - }, + t.Parallel() + + networkName := test.RandomName() + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateRemoteNetworkDestroy, + Steps: []resource.TestStep{ + { + Config: testDatasourceTwingateRemoteNetworkByName(networkName), + Check: acctests.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.twingate_remote_network.test_dn2_2", attr.Name, networkName), + ), }, - }) + }, }) } @@ -89,20 +87,19 @@ func testDatasourceTwingateRemoteNetworkByName(name string) string { `, name, name) } -func TestAccDatasourceTwingateRemoteNetwork_negative(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Remote Network - does not exists", func(t *testing.T) { - networkID := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("RemoteNetwork:%d", acctest.RandInt()))) - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - Steps: []resource.TestStep{ - { - Config: testTwingateRemoteNetworkDoesNotExists(networkID), - ExpectError: regexp.MustCompile("failed to read remote network with id"), - }, +func TestAccDatasourceTwingateRemoteNetwork_NetworkDoesNotExists(t *testing.T) { + t.Parallel() + networkID := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("RemoteNetwork:%d", acctest.RandInt()))) + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + Steps: []resource.TestStep{ + { + Config: testTwingateRemoteNetworkDoesNotExists(networkID), + ExpectError: regexp.MustCompile("failed to read remote network with id"), }, - }) + }, }) } @@ -119,39 +116,37 @@ func testTwingateRemoteNetworkDoesNotExists(id string) string { } func TestAccDatasourceTwingateRemoteNetwork_invalidNetworkID(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Remote Network - failed parse network ID", func(t *testing.T) { - networkID := acctest.RandString(10) - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - Steps: []resource.TestStep{ - { - Config: testTwingateRemoteNetworkDoesNotExists(networkID), - ExpectError: regexp.MustCompile("failed to read remote network with id"), - }, + t.Parallel() + networkID := acctest.RandString(10) + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + Steps: []resource.TestStep{ + { + Config: testTwingateRemoteNetworkDoesNotExists(networkID), + ExpectError: regexp.MustCompile("failed to read remote network with id"), }, - }) + }, }) } -func TestAccDatasourceTwingateRemoteNetwork_bothNetworkIDAndName(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Remote Network - failed passing both network ID and name", func(t *testing.T) { - networkID := acctest.RandString(10) - networkName := acctest.RandString(10) - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { - acctests.PreCheck(t) - }, - Steps: []resource.TestStep{ - { - Config: testTwingateRemoteNetworkValidationFailed(networkID, networkName), - ExpectError: regexp.MustCompile("Invalid Attribute Combination"), - }, +func TestAccDatasourceTwingateRemoteNetwork_invalidBothNetworkIDAndName(t *testing.T) { + t.Parallel() + networkID := acctest.RandString(10) + networkName := acctest.RandString(10) + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { + acctests.PreCheck(t) + }, + Steps: []resource.TestStep{ + { + Config: testTwingateRemoteNetworkValidationFailed(networkID, networkName), + ExpectError: regexp.MustCompile("Invalid Attribute Combination"), }, - }) + }, }) } diff --git a/twingate/internal/test/acctests/datasource/remote-networks_test.go b/twingate/internal/test/acctests/datasource/remote-networks_test.go index 27bceacc..8a79dfe0 100644 --- a/twingate/internal/test/acctests/datasource/remote-networks_test.go +++ b/twingate/internal/test/acctests/datasource/remote-networks_test.go @@ -17,26 +17,24 @@ var ( ) func TestAccDatasourceTwingateRemoteNetworks_read(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Remote Networks Read", func(t *testing.T) { - acctests.SetPageLimit(1) - - prefix := acctest.RandString(10) - networkName1 := test.RandomName(prefix) - networkName2 := test.RandomName(prefix) - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateRemoteNetworkDestroy, - Steps: []resource.TestStep{ - { - Config: testDatasourceTwingateRemoteNetworks2(networkName1, networkName2, prefix), - Check: acctests.ComposeTestCheckFunc( - testCheckOutputLength("test_networks", 2), - ), - }, + t.Parallel() + + prefix := acctest.RandString(10) + networkName1 := test.RandomName(prefix) + networkName2 := test.RandomName(prefix) + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateRemoteNetworkDestroy, + Steps: []resource.TestStep{ + { + Config: testDatasourceTwingateRemoteNetworks2(networkName1, networkName2, prefix), + Check: acctests.ComposeTestCheckFunc( + testCheckOutputLength("test_networks", 2), + ), }, - }) + }, }) } diff --git a/twingate/internal/test/acctests/datasource/resource_test.go b/twingate/internal/test/acctests/datasource/resource_test.go index 8e2a7fea..30daabf4 100644 --- a/twingate/internal/test/acctests/datasource/resource_test.go +++ b/twingate/internal/test/acctests/datasource/resource_test.go @@ -14,23 +14,23 @@ import ( ) func TestAccDatasourceTwingateResource_basic(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Resource Basic", func(t *testing.T) { - networkName := test.RandomName() - resourceName := test.RandomResourceName() - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateResourceDestroy, - Steps: []resource.TestStep{ - { - Config: testDatasourceTwingateResource(networkName, resourceName), - Check: acctests.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.twingate_resource.out_dr1", attr.Name, resourceName), - ), - }, + t.Parallel() + + networkName := test.RandomName() + resourceName := test.RandomResourceName() + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateResourceDestroy, + Steps: []resource.TestStep{ + { + Config: testDatasourceTwingateResource(networkName, resourceName), + Check: acctests.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.twingate_resource.out_dr1", attr.Name, resourceName), + ), }, - }) + }, }) } @@ -63,22 +63,22 @@ func testDatasourceTwingateResource(networkName, resourceName string) string { `, networkName, resourceName) } -func TestAccDatasourceTwingateResource_negative(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Resource - does not exists", func(t *testing.T) { - resourceID := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("Resource:%d", acctest.RandInt()))) +func TestAccDatasourceTwingateResource_ResourceDoesNotExists(t *testing.T) { + t.Parallel() - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { - acctests.PreCheck(t) - }, - Steps: []resource.TestStep{ - { - Config: testTwingateResourceDoesNotExists(resourceID), - ExpectError: regexp.MustCompile("failed to read resource with id"), - }, + resourceID := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("Resource:%d", acctest.RandInt()))) + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { + acctests.PreCheck(t) + }, + Steps: []resource.TestStep{ + { + Config: testTwingateResourceDoesNotExists(resourceID), + ExpectError: regexp.MustCompile("failed to read resource with id"), }, - }) + }, }) } @@ -95,20 +95,20 @@ func testTwingateResourceDoesNotExists(id string) string { } func TestAccDatasourceTwingateResource_invalidID(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Resource - failed parse resource ID", func(t *testing.T) { - networkID := acctest.RandString(10) + t.Parallel() - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { - acctests.PreCheck(t) - }, - Steps: []resource.TestStep{ - { - Config: testTwingateResourceDoesNotExists(networkID), - ExpectError: regexp.MustCompile("failed to read resource with id"), - }, + networkID := acctest.RandString(10) + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { + acctests.PreCheck(t) + }, + Steps: []resource.TestStep{ + { + Config: testTwingateResourceDoesNotExists(networkID), + ExpectError: regexp.MustCompile("failed to read resource with id"), }, - }) + }, }) } diff --git a/twingate/internal/test/acctests/datasource/resources_test.go b/twingate/internal/test/acctests/datasource/resources_test.go index 0e6514eb..75d4d28f 100644 --- a/twingate/internal/test/acctests/datasource/resources_test.go +++ b/twingate/internal/test/acctests/datasource/resources_test.go @@ -18,26 +18,25 @@ var ( ) func TestAccDatasourceTwingateResources_basic(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Resources Basic", func(t *testing.T) { - acctests.SetPageLimit(1) - networkName := test.RandomName() - resourceName := test.RandomResourceName() - const theDatasource = "data.twingate_resources.out_drs1" - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateResourceDestroy, - Steps: []resource.TestStep{ - { - Config: testDatasourceTwingateResources(networkName, resourceName), - Check: acctests.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(theDatasource, resourcesLen, "2"), - resource.TestCheckResourceAttr(theDatasource, resourceNamePath, resourceName), - ), - }, + t.Parallel() + + networkName := test.RandomName() + resourceName := test.RandomResourceName() + const theDatasource = "data.twingate_resources.out_drs1" + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateResourceDestroy, + Steps: []resource.TestStep{ + { + Config: testDatasourceTwingateResources(networkName, resourceName), + Check: acctests.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(theDatasource, resourcesLen, "2"), + resource.TestCheckResourceAttr(theDatasource, resourceNamePath, resourceName), + ), }, - }) + }, }) } @@ -90,23 +89,23 @@ func testDatasourceTwingateResources(networkName, resourceName string) string { } func TestAccDatasourceTwingateResources_emptyResult(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Resources - empty result", func(t *testing.T) { - resourceName := test.RandomResourceName() + t.Parallel() - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { - acctests.PreCheck(t) - }, - Steps: []resource.TestStep{ - { - Config: testTwingateResourcesDoesNotExists(resourceName), - Check: acctests.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.twingate_resources.out_drs2", resourcesLen, "0"), - ), - }, + resourceName := test.RandomResourceName() + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { + acctests.PreCheck(t) + }, + Steps: []resource.TestStep{ + { + Config: testTwingateResourcesDoesNotExists(resourceName), + Check: acctests.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.twingate_resources.out_drs2", resourcesLen, "0"), + ), }, - }) + }, }) } diff --git a/twingate/internal/test/acctests/datasource/security-policies_test.go b/twingate/internal/test/acctests/datasource/security-policies_test.go index 4695f316..714db4b5 100644 --- a/twingate/internal/test/acctests/datasource/security-policies_test.go +++ b/twingate/internal/test/acctests/datasource/security-policies_test.go @@ -12,26 +12,24 @@ import ( var securityPolicyNamePath = attr.Path(attr.SecurityPolicies, attr.Name) func TestAccDatasourceTwingateSecurityPoliciesBasic(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Security Policies - basic", func(t *testing.T) { - acctests.SetPageLimit(1) - - securityPolicies, err := acctests.ListSecurityPolicies() - if err != nil { - t.Skip("can't run test:", err) - } - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - Steps: []sdk.TestStep{ - { - Config: testDatasourceTwingateSecurityPolicies(), - Check: acctests.ComposeTestCheckFunc( - sdk.TestCheckResourceAttr("data.twingate_security_policies.all", attr.Len(attr.SecurityPolicies), fmt.Sprintf("%d", len(securityPolicies))), - ), - }, + t.Parallel() + + securityPolicies, err := acctests.ListSecurityPolicies() + if err != nil { + t.Skip("can't run test:", err) + } + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + Steps: []sdk.TestStep{ + { + Config: testDatasourceTwingateSecurityPolicies(), + Check: acctests.ComposeTestCheckFunc( + sdk.TestCheckResourceAttr("data.twingate_security_policies.all", attr.Len(attr.SecurityPolicies), fmt.Sprintf("%d", len(securityPolicies))), + ), }, - }) + }, }) } diff --git a/twingate/internal/test/acctests/datasource/security-policy_test.go b/twingate/internal/test/acctests/datasource/security-policy_test.go index c634df8e..4f8ee988 100644 --- a/twingate/internal/test/acctests/datasource/security-policy_test.go +++ b/twingate/internal/test/acctests/datasource/security-policy_test.go @@ -12,21 +12,21 @@ import ( ) func TestAccDatasourceTwingateSecurityPolicyInvalidID(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Security Policy - failed parse ID", func(t *testing.T) { - randStr := acctest.RandString(10) - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { - acctests.PreCheck(t) - }, - Steps: []resource.TestStep{ - { - Config: testDatasourceTwingateSecurityPolicy(randStr), - ExpectError: regexp.MustCompile("failed to read security policy"), - }, + t.Parallel() + + randStr := acctest.RandString(10) + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { + acctests.PreCheck(t) + }, + Steps: []resource.TestStep{ + { + Config: testDatasourceTwingateSecurityPolicy(randStr), + ExpectError: regexp.MustCompile("failed to read security policy"), }, - }) + }, }) } @@ -43,21 +43,21 @@ func testDatasourceTwingateSecurityPolicy(id string) string { } func TestAccDatasourceTwingateSecurityPolicyReadWithNameAndID(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Security Policy - read with name and id", func(t *testing.T) { - randStr := acctest.RandString(10) - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { - acctests.PreCheck(t) - }, - Steps: []resource.TestStep{ - { - Config: testDatasourceTwingateSecurityPolicyWithNameAndID(randStr, randStr), - ExpectError: regexp.MustCompile("Error: Invalid Attribute Combination"), - }, + t.Parallel() + + randStr := acctest.RandString(10) + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { + acctests.PreCheck(t) + }, + Steps: []resource.TestStep{ + { + Config: testDatasourceTwingateSecurityPolicyWithNameAndID(randStr, randStr), + ExpectError: regexp.MustCompile("Error: Invalid Attribute Combination"), }, - }) + }, }) } @@ -75,47 +75,47 @@ func testDatasourceTwingateSecurityPolicyWithNameAndID(id, name string) string { } func TestAccDatasourceTwingateSecurityPolicyDoesNotExists(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Security Policy - does not exists", func(t *testing.T) { - securityPolicyID := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("SecurityPolicy:%d", acctest.RandInt()))) - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { - acctests.PreCheck(t) - }, - Steps: []resource.TestStep{ - { - Config: testDatasourceTwingateSecurityPolicy(securityPolicyID), - ExpectError: regexp.MustCompile("failed to read security policy with id"), - }, + t.Parallel() + + securityPolicyID := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("SecurityPolicy:%d", acctest.RandInt()))) + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { + acctests.PreCheck(t) + }, + Steps: []resource.TestStep{ + { + Config: testDatasourceTwingateSecurityPolicy(securityPolicyID), + ExpectError: regexp.MustCompile("failed to read security policy with id"), }, - }) + }, }) } func TestAccDatasourceTwingateSecurityPolicyReadOkByID(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Security Policy - read Ok By ID", func(t *testing.T) { - securityPolicies, err := acctests.ListSecurityPolicies() - if err != nil { - t.Skip("can't run test:", err) - } - - testPolicy := securityPolicies[0] - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { - acctests.PreCheck(t) - }, - Steps: []resource.TestStep{ - { - Config: testDatasourceTwingateSecurityPolicyByID(testPolicy.ID), - Check: acctests.ComposeTestCheckFunc( - resource.TestCheckOutput("security_policy_name", testPolicy.Name), - ), - }, + t.Parallel() + + securityPolicies, err := acctests.ListSecurityPolicies() + if err != nil { + t.Skip("can't run test:", err) + } + + testPolicy := securityPolicies[0] + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { + acctests.PreCheck(t) + }, + Steps: []resource.TestStep{ + { + Config: testDatasourceTwingateSecurityPolicyByID(testPolicy.ID), + Check: acctests.ComposeTestCheckFunc( + resource.TestCheckOutput("security_policy_name", testPolicy.Name), + ), }, - }) + }, }) } @@ -132,28 +132,28 @@ func testDatasourceTwingateSecurityPolicyByID(id string) string { } func TestAccDatasourceTwingateSecurityPolicyReadOkByName(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Security Policy - read Ok By Name", func(t *testing.T) { - securityPolicies, err := acctests.ListSecurityPolicies() - if err != nil { - t.Skip("can't run test:", err) - } - - testPolicy := securityPolicies[0] - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { - acctests.PreCheck(t) - }, - Steps: []resource.TestStep{ - { - Config: testDatasourceTwingateSecurityPolicyByName(testPolicy.Name), - Check: acctests.ComposeTestCheckFunc( - resource.TestCheckOutput("security_policy_id", testPolicy.ID), - ), - }, + t.Parallel() + + securityPolicies, err := acctests.ListSecurityPolicies() + if err != nil { + t.Skip("can't run test:", err) + } + + testPolicy := securityPolicies[0] + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { + acctests.PreCheck(t) + }, + Steps: []resource.TestStep{ + { + Config: testDatasourceTwingateSecurityPolicyByName(testPolicy.Name), + Check: acctests.ComposeTestCheckFunc( + resource.TestCheckOutput("security_policy_id", testPolicy.ID), + ), }, - }) + }, }) } diff --git a/twingate/internal/test/acctests/datasource/service-accounts_test.go b/twingate/internal/test/acctests/datasource/service-accounts_test.go index f5675dc4..bc5c815a 100644 --- a/twingate/internal/test/acctests/datasource/service-accounts_test.go +++ b/twingate/internal/test/acctests/datasource/service-accounts_test.go @@ -21,106 +21,104 @@ var ( ) func TestAccDatasourceTwingateServicesFilterByName(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Services - Filter By Name", func(t *testing.T) { + t.Parallel() - name := test.Prefix("orange") + acctest.RandString(5) - const ( - terraformResourceName = "dts_service" - theDatasource = "data.twingate_service_accounts.out" - ) + name := test.Prefix("orange") + acctest.RandString(5) + const ( + terraformResourceName = "dts_service" + theDatasource = "data.twingate_service_accounts.out" + ) - config := []terraformServiceConfig{ - { - serviceName: name, - terraformResourceName: test.TerraformRandName(terraformResourceName), - }, + config := []terraformServiceConfig{ + { + serviceName: name, + terraformResourceName: test.TerraformRandName(terraformResourceName), + }, + { + serviceName: test.Prefix("lemon") + acctest.RandString(5), + terraformResourceName: test.TerraformRandName(terraformResourceName), + }, + } + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, + Steps: []resource.TestStep{ { - serviceName: test.Prefix("lemon") + acctest.RandString(5), - terraformResourceName: test.TerraformRandName(terraformResourceName), - }, - } - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, - Steps: []resource.TestStep{ - { - Config: terraformConfig( - createServices(config), - datasourceServices(name, config), - ), - Check: acctests.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(theDatasource, serviceAccountsLen, "1"), - resource.TestCheckResourceAttr(theDatasource, keyIDsLen, "1"), - resource.TestCheckResourceAttr(theDatasource, attr.ID, "service-by-name-"+name), - ), - }, + Config: terraformConfig( + createServices(config), + datasourceServices(name, config), + ), + Check: acctests.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(theDatasource, serviceAccountsLen, "1"), + resource.TestCheckResourceAttr(theDatasource, keyIDsLen, "1"), + resource.TestCheckResourceAttr(theDatasource, attr.ID, "service-by-name-"+name), + ), }, - }) + }, }) } func TestAccDatasourceTwingateServicesAll(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Services - All", func(t *testing.T) { - prefix := test.Prefix() + acctest.RandString(4) - const ( - terraformResourceName = "dts_service" - theDatasource = "data.twingate_service_accounts.out" - ) - - config := []terraformServiceConfig{ + t.Parallel() + + prefix := test.Prefix() + acctest.RandString(4) + const ( + terraformResourceName = "dts_service" + theDatasource = "data.twingate_service_accounts.out" + ) + + config := []terraformServiceConfig{ + { + serviceName: prefix + "_orange", + terraformResourceName: test.TerraformRandName(terraformResourceName), + }, + { + serviceName: prefix + "_lemon", + terraformResourceName: test.TerraformRandName(terraformResourceName), + }, + } + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, + Steps: []resource.TestStep{ { - serviceName: prefix + "_orange", - terraformResourceName: test.TerraformRandName(terraformResourceName), + Config: filterDatasourceServices(prefix, config), + Check: acctests.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(theDatasource, attr.ID, "all-services"), + ), + ExpectNonEmptyPlan: true, }, { - serviceName: prefix + "_lemon", - terraformResourceName: test.TerraformRandName(terraformResourceName), - }, - } - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, - Steps: []resource.TestStep{ - { - Config: filterDatasourceServices(prefix, config), - Check: acctests.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(theDatasource, attr.ID, "all-services"), - ), - ExpectNonEmptyPlan: true, - }, - { - Config: filterDatasourceServices(prefix, config), - Check: acctests.ComposeTestCheckFunc( - testCheckOutputLength("my_services", 2), - ), - }, + Config: filterDatasourceServices(prefix, config), + Check: acctests.ComposeTestCheckFunc( + testCheckOutputLength("my_services", 2), + ), }, - }) + }, }) } func TestAccDatasourceTwingateServicesEmptyResult(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Services - Empty Result", func(t *testing.T) { - - const theDatasource = "data.twingate_service_accounts.out" - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, - Steps: []resource.TestStep{ - { - Config: datasourceServices(test.RandomName(), nil), - Check: acctests.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(theDatasource, serviceAccountsLen, "0"), - ), - }, + t.Parallel() + + const theDatasource = "data.twingate_service_accounts.out" + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, + Steps: []resource.TestStep{ + { + Config: datasourceServices(test.RandomName(), nil), + Check: acctests.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(theDatasource, serviceAccountsLen, "0"), + ), }, - }) + }, }) } @@ -200,23 +198,22 @@ func filterDatasourceServices(prefix string, configs []terraformServiceConfig) s } func TestAccDatasourceTwingateServicesAllCursors(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Services - All Cursors", func(t *testing.T) { - acctests.SetPageLimit(1) - prefix := test.Prefix() + acctest.RandString(4) - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, - Steps: []resource.TestStep{ - { - Config: datasourceServicesConfig(prefix), - Check: acctests.ComposeTestCheckFunc( - testCheckOutputLength("my_services", 2), - ), - }, + t.Parallel() + + prefix := test.Prefix() + acctest.RandString(4) + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, + Steps: []resource.TestStep{ + { + Config: datasourceServicesConfig(prefix), + Check: acctests.ComposeTestCheckFunc( + testCheckOutputLength("my_services", 2), + ), }, - }) + }, }) } diff --git a/twingate/internal/test/acctests/datasource/user_test.go b/twingate/internal/test/acctests/datasource/user_test.go index 922e50aa..45e6e4c0 100644 --- a/twingate/internal/test/acctests/datasource/user_test.go +++ b/twingate/internal/test/acctests/datasource/user_test.go @@ -12,24 +12,24 @@ import ( ) func TestAccDatasourceTwingateUser_basic(t *testing.T) { - t.Run("Test Twingate Datasource : Acc User Basic", func(t *testing.T) { - user, err := acctests.GetTestUser() - if err != nil { - t.Skip("can't run test:", err) - } + t.Parallel() - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - Steps: []resource.TestStep{ - { - Config: testDatasourceTwingateUser(user.ID), - Check: acctests.ComposeTestCheckFunc( - resource.TestCheckOutput("my_user_email_du1", user.Email), - ), - }, + user, err := acctests.GetTestUser() + if err != nil { + t.Skip("can't run test:", err) + } + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + Steps: []resource.TestStep{ + { + Config: testDatasourceTwingateUser(user.ID), + Check: acctests.ComposeTestCheckFunc( + resource.TestCheckOutput("my_user_email_du1", user.Email), + ), }, - }) + }, }) } @@ -46,22 +46,23 @@ func testDatasourceTwingateUser(userID string) string { } func TestAccDatasourceTwingateUser_negative(t *testing.T) { - t.Run("Test Twingate Datasource : Acc User - does not exists", func(t *testing.T) { - userID := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("User:%d", acctest.RandInt()))) + t.Parallel() - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { - acctests.PreCheck(t) - }, - Steps: []resource.TestStep{ - { - Config: testTwingateUserDoesNotExists(userID), - ExpectError: regexp.MustCompile("failed to read user with id"), - }, + userID := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("User:%d", acctest.RandInt()))) + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { + acctests.PreCheck(t) + }, + Steps: []resource.TestStep{ + { + Config: testTwingateUserDoesNotExists(userID), + ExpectError: regexp.MustCompile("failed to read user with id"), }, - }) + }, }) + } func testTwingateUserDoesNotExists(id string) string { @@ -73,20 +74,20 @@ func testTwingateUserDoesNotExists(id string) string { } func TestAccDatasourceTwingateUser_invalidID(t *testing.T) { - t.Run("Test Twingate Datasource : Acc User - failed parse ID", func(t *testing.T) { - userID := acctest.RandString(10) + t.Parallel() - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { - acctests.PreCheck(t) - }, - Steps: []resource.TestStep{ - { - Config: testTwingateUserDoesNotExists(userID), - ExpectError: regexp.MustCompile("failed to read user with id"), - }, + userID := acctest.RandString(10) + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { + acctests.PreCheck(t) + }, + Steps: []resource.TestStep{ + { + Config: testTwingateUserDoesNotExists(userID), + ExpectError: regexp.MustCompile("failed to read user with id"), }, - }) + }, }) } diff --git a/twingate/internal/test/acctests/datasource/users_test.go b/twingate/internal/test/acctests/datasource/users_test.go index 25c47341..ad0d08b4 100644 --- a/twingate/internal/test/acctests/datasource/users_test.go +++ b/twingate/internal/test/acctests/datasource/users_test.go @@ -15,27 +15,26 @@ import ( ) func TestAccDatasourceTwingateUsers_basic(t *testing.T) { - t.Run("Test Twingate Datasource : Acc Users Basic", func(t *testing.T) { - users, err := acctests.GetTestUsers() - if err != nil && !errors.Is(err, acctests.ErrResourceNotFound) { - t.Skip("can't run test:", err) - } + t.Parallel() + + users, err := acctests.GetTestUsers() + if err != nil && !errors.Is(err, acctests.ErrResourceNotFound) { + t.Skip("can't run test:", err) + } - acctests.SetPageLimit(len(users)/3 + 1) - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - Steps: []resource.TestStep{ - { - Config: testDatasourceTwingateUsers(), - Check: acctests.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.twingate_users.all", attr.Len(attr.Users), fmt.Sprintf("%d", len(users))), - ), - }, + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + Steps: []resource.TestStep{ + { + Config: testDatasourceTwingateUsers(), + Check: acctests.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.twingate_users.all", attr.Len(attr.Users), fmt.Sprintf("%d", len(users))), + ), }, - }) + }, }) + } func testDatasourceTwingateUsers() string { diff --git a/twingate/internal/test/acctests/resource/connector-tokens_test.go b/twingate/internal/test/acctests/resource/connector-tokens_test.go index b66820e9..cc203252 100644 --- a/twingate/internal/test/acctests/resource/connector-tokens_test.go +++ b/twingate/internal/test/acctests/resource/connector-tokens_test.go @@ -12,24 +12,24 @@ import ( ) func TestAccRemoteConnectorWithTokens(t *testing.T) { - t.Run("Test Twingate Resource : Acc Remote Connector With Tokens", func(t *testing.T) { - const terraformResourceName = "test_t1" - theResource := acctests.TerraformConnectorTokens(terraformResourceName) - remoteNetworkName := test.RandomName() + t.Parallel() - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateConnectorTokensInvalidated, - Steps: []sdk.TestStep{ - { - Config: terraformResourceTwingateConnectorTokens(terraformResourceName, remoteNetworkName), - Check: acctests.ComposeTestCheckFunc( - checkTwingateConnectorTokensSet(theResource), - ), - }, + const terraformResourceName = "test_t1" + theResource := acctests.TerraformConnectorTokens(terraformResourceName) + remoteNetworkName := test.RandomName() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateConnectorTokensInvalidated, + Steps: []sdk.TestStep{ + { + Config: terraformResourceTwingateConnectorTokens(terraformResourceName, remoteNetworkName), + Check: acctests.ComposeTestCheckFunc( + checkTwingateConnectorTokensSet(theResource), + ), }, - }) + }, }) } diff --git a/twingate/internal/test/acctests/resource/connector_test.go b/twingate/internal/test/acctests/resource/connector_test.go index 933e9b20..9996c396 100644 --- a/twingate/internal/test/acctests/resource/connector_test.go +++ b/twingate/internal/test/acctests/resource/connector_test.go @@ -14,139 +14,139 @@ import ( ) func TestAccRemoteConnectorCreate(t *testing.T) { - t.Run("Test Twingate Resource : Acc Remote Connector", func(t *testing.T) { - const terraformResourceName = "test_c1" - theResource := acctests.TerraformConnector(terraformResourceName) - remoteNetworkName := test.RandomName() - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateConnectorAndRemoteNetworkDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceTwingateConnector(terraformResourceName, terraformResourceName, remoteNetworkName), - Check: acctests.ComposeTestCheckFunc( - checkTwingateConnectorSetWithRemoteNetwork(theResource, acctests.TerraformRemoteNetwork(terraformResourceName)), - sdk.TestCheckResourceAttrSet(theResource, attr.Name), - ), - }, + t.Parallel() + + const terraformResourceName = "test_c1" + theResource := acctests.TerraformConnector(terraformResourceName) + remoteNetworkName := test.RandomName() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateConnectorAndRemoteNetworkDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceTwingateConnector(terraformResourceName, terraformResourceName, remoteNetworkName), + Check: acctests.ComposeTestCheckFunc( + checkTwingateConnectorSetWithRemoteNetwork(theResource, acctests.TerraformRemoteNetwork(terraformResourceName)), + sdk.TestCheckResourceAttrSet(theResource, attr.Name), + ), }, - }) + }, }) } func TestAccRemoteConnectorWithCustomName(t *testing.T) { - t.Run("Test Twingate Resource : Acc Remote Connector With Custom Name", func(t *testing.T) { - const terraformResourceName = "test_c2" - theResource := acctests.TerraformConnector(terraformResourceName) - remoteNetworkName := test.RandomName() - connectorName := test.RandomConnectorName() - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateConnectorAndRemoteNetworkDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceTwingateConnectorWithName(terraformResourceName, remoteNetworkName, connectorName), - Check: acctests.ComposeTestCheckFunc( - checkTwingateConnectorSetWithRemoteNetwork(theResource, acctests.TerraformRemoteNetwork(terraformResourceName)), - sdk.TestMatchResourceAttr(theResource, attr.Name, regexp.MustCompile(connectorName)), - ), - }, + t.Parallel() + + const terraformResourceName = "test_c2" + theResource := acctests.TerraformConnector(terraformResourceName) + remoteNetworkName := test.RandomName() + connectorName := test.RandomConnectorName() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateConnectorAndRemoteNetworkDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceTwingateConnectorWithName(terraformResourceName, remoteNetworkName, connectorName), + Check: acctests.ComposeTestCheckFunc( + checkTwingateConnectorSetWithRemoteNetwork(theResource, acctests.TerraformRemoteNetwork(terraformResourceName)), + sdk.TestMatchResourceAttr(theResource, attr.Name, regexp.MustCompile(connectorName)), + ), }, - }) + }, }) } func TestAccRemoteConnectorImport(t *testing.T) { - t.Run("Test Twingate Resource : Acc Remote Connector - Import", func(t *testing.T) { - const terraformResourceName = "test_c3" - theResource := acctests.TerraformConnector(terraformResourceName) - remoteNetworkName := test.RandomName() - connectorName := test.RandomConnectorName() - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateConnectorAndRemoteNetworkDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceTwingateConnectorWithName(terraformResourceName, remoteNetworkName, connectorName), - Check: acctests.ComposeTestCheckFunc( - checkTwingateConnectorSetWithRemoteNetwork(theResource, acctests.TerraformRemoteNetwork(terraformResourceName)), - sdk.TestMatchResourceAttr(theResource, attr.Name, regexp.MustCompile(connectorName[:len(connectorName)-3]+".*")), - ), - }, - { - ResourceName: theResource, - ImportState: true, - ImportStateVerify: true, - }, + t.Parallel() + + const terraformResourceName = "test_c3" + theResource := acctests.TerraformConnector(terraformResourceName) + remoteNetworkName := test.RandomName() + connectorName := test.RandomConnectorName() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateConnectorAndRemoteNetworkDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceTwingateConnectorWithName(terraformResourceName, remoteNetworkName, connectorName), + Check: acctests.ComposeTestCheckFunc( + checkTwingateConnectorSetWithRemoteNetwork(theResource, acctests.TerraformRemoteNetwork(terraformResourceName)), + sdk.TestMatchResourceAttr(theResource, attr.Name, regexp.MustCompile(connectorName[:len(connectorName)-3]+".*")), + ), }, - }) + { + ResourceName: theResource, + ImportState: true, + ImportStateVerify: true, + }, + }, }) } func TestAccRemoteConnectorNotAllowedToChangeRemoteNetworkId(t *testing.T) { - t.Run("Test Twingate Resource : Acc Remote Connector - should fail on remote_network_id update", func(t *testing.T) { - const ( - terraformConnectorName = "test_c4" - terraformRemoteNetworkName1 = "test_c4_1" - terraformRemoteNetworkName2 = "test_c4_2" - ) - theResource := acctests.TerraformConnector(terraformConnectorName) - remoteNetworkName1 := test.RandomName() - remoteNetworkName2 := test.RandomName() - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateConnectorAndRemoteNetworkDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceTwingateConnector(terraformRemoteNetworkName1, terraformConnectorName, remoteNetworkName1), - Check: acctests.ComposeTestCheckFunc( - checkTwingateConnectorSetWithRemoteNetwork(theResource, acctests.TerraformRemoteNetwork(terraformRemoteNetworkName1)), - ), - }, - { - Config: terraformResourceTwingateConnector(terraformRemoteNetworkName2, terraformConnectorName, remoteNetworkName2), - ExpectError: regexp.MustCompile(resource.ErrNotAllowChangeRemoteNetworkID.Error()), - }, + t.Parallel() + + const ( + terraformConnectorName = "test_c4" + terraformRemoteNetworkName1 = "test_c4_1" + terraformRemoteNetworkName2 = "test_c4_2" + ) + theResource := acctests.TerraformConnector(terraformConnectorName) + remoteNetworkName1 := test.RandomName() + remoteNetworkName2 := test.RandomName() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateConnectorAndRemoteNetworkDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceTwingateConnector(terraformRemoteNetworkName1, terraformConnectorName, remoteNetworkName1), + Check: acctests.ComposeTestCheckFunc( + checkTwingateConnectorSetWithRemoteNetwork(theResource, acctests.TerraformRemoteNetwork(terraformRemoteNetworkName1)), + ), + }, + { + Config: terraformResourceTwingateConnector(terraformRemoteNetworkName2, terraformConnectorName, remoteNetworkName2), + ExpectError: regexp.MustCompile(resource.ErrNotAllowChangeRemoteNetworkID.Error()), }, - }) + }, }) } func TestAccTwingateConnectorReCreateAfterDeletion(t *testing.T) { - t.Run("Test Twingate Resource : Acc Remote Connector ReCreate After Deletion", func(t *testing.T) { - const terraformResourceName = "test_c5" - theResource := acctests.TerraformConnector(terraformResourceName) - remoteNetworkName := test.RandomName() - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateConnectorAndRemoteNetworkDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceTwingateConnector(terraformResourceName, terraformResourceName, remoteNetworkName), - Check: acctests.ComposeTestCheckFunc( - checkTwingateConnectorSetWithRemoteNetwork(theResource, acctests.TerraformRemoteNetwork(terraformResourceName)), - acctests.DeleteTwingateResource(theResource, resource.TwingateConnector), - ), - ExpectNonEmptyPlan: true, - }, - { - Config: terraformResourceTwingateConnector(terraformResourceName, terraformResourceName, remoteNetworkName), - Check: acctests.ComposeTestCheckFunc( - checkTwingateConnectorSetWithRemoteNetwork(theResource, acctests.TerraformRemoteNetwork(terraformResourceName)), - ), - }, + t.Parallel() + + const terraformResourceName = "test_c5" + theResource := acctests.TerraformConnector(terraformResourceName) + remoteNetworkName := test.RandomName() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateConnectorAndRemoteNetworkDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceTwingateConnector(terraformResourceName, terraformResourceName, remoteNetworkName), + Check: acctests.ComposeTestCheckFunc( + checkTwingateConnectorSetWithRemoteNetwork(theResource, acctests.TerraformRemoteNetwork(terraformResourceName)), + acctests.DeleteTwingateResource(theResource, resource.TwingateConnector), + ), + ExpectNonEmptyPlan: true, }, - }) + { + Config: terraformResourceTwingateConnector(terraformResourceName, terraformResourceName, remoteNetworkName), + Check: acctests.ComposeTestCheckFunc( + checkTwingateConnectorSetWithRemoteNetwork(theResource, acctests.TerraformRemoteNetwork(terraformResourceName)), + ), + }, + }, }) } @@ -196,77 +196,77 @@ func checkTwingateConnectorSetWithRemoteNetwork(connectorResource, remoteNetwork } func TestAccRemoteConnectorUpdateName(t *testing.T) { - t.Run("Test Twingate Resource : Acc Remote Connector Update Name", func(t *testing.T) { - const terraformResourceName = "test_c6" - theResource := acctests.TerraformConnector(terraformResourceName) - remoteNetworkName := test.RandomName() - connectorName := test.RandomConnectorName() - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateConnectorAndRemoteNetworkDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceTwingateConnector(terraformResourceName, terraformResourceName, remoteNetworkName), - Check: acctests.ComposeTestCheckFunc( - checkTwingateConnectorSetWithRemoteNetwork(theResource, acctests.TerraformRemoteNetwork(terraformResourceName)), - sdk.TestCheckResourceAttrSet(theResource, attr.Name), - ), - }, - { - Config: terraformResourceTwingateConnectorWithName(terraformResourceName, remoteNetworkName, connectorName), - Check: acctests.ComposeTestCheckFunc( - sdk.TestCheckResourceAttr(theResource, attr.Name, connectorName), - ), - }, + t.Parallel() + + const terraformResourceName = "test_c6" + theResource := acctests.TerraformConnector(terraformResourceName) + remoteNetworkName := test.RandomName() + connectorName := test.RandomConnectorName() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateConnectorAndRemoteNetworkDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceTwingateConnector(terraformResourceName, terraformResourceName, remoteNetworkName), + Check: acctests.ComposeTestCheckFunc( + checkTwingateConnectorSetWithRemoteNetwork(theResource, acctests.TerraformRemoteNetwork(terraformResourceName)), + sdk.TestCheckResourceAttrSet(theResource, attr.Name), + ), }, - }) + { + Config: terraformResourceTwingateConnectorWithName(terraformResourceName, remoteNetworkName, connectorName), + Check: acctests.ComposeTestCheckFunc( + sdk.TestCheckResourceAttr(theResource, attr.Name, connectorName), + ), + }, + }, }) } func TestAccRemoteConnectorCreateWithNotificationStatus(t *testing.T) { - t.Run("Test Twingate Resource : Acc Remote Connector With Notification Status", func(t *testing.T) { - const terraformResourceName = "test_c7" - theResource := acctests.TerraformConnector(terraformResourceName) - remoteNetworkName := test.RandomName() - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateConnectorAndRemoteNetworkDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceTwingateConnector(terraformResourceName, terraformResourceName, remoteNetworkName), - Check: acctests.ComposeTestCheckFunc( - checkTwingateConnectorSetWithRemoteNetwork(theResource, acctests.TerraformRemoteNetwork(terraformResourceName)), - sdk.TestCheckResourceAttrSet(theResource, attr.Name), - ), - }, - { - // expecting no changes, as by default notifications enabled - PlanOnly: true, - Config: terraformResourceTwingateConnectorWithNotificationStatus(terraformResourceName, terraformResourceName, remoteNetworkName, true), - Check: acctests.ComposeTestCheckFunc( - sdk.TestCheckResourceAttr(theResource, attr.StatusUpdatesEnabled, "true"), - ), - }, - { - Config: terraformResourceTwingateConnectorWithNotificationStatus(terraformResourceName, terraformResourceName, remoteNetworkName, false), - Check: acctests.ComposeTestCheckFunc( - sdk.TestCheckResourceAttr(theResource, attr.StatusUpdatesEnabled, "false"), - ), - }, - { - // expecting no changes, when user removes `status_updates_enabled` field from terraform - PlanOnly: true, - Config: terraformResourceTwingateConnector(terraformResourceName, terraformResourceName, remoteNetworkName), - Check: acctests.ComposeTestCheckFunc( - sdk.TestCheckResourceAttr(theResource, attr.StatusUpdatesEnabled, "false"), - ), - }, + t.Parallel() + + const terraformResourceName = "test_c7" + theResource := acctests.TerraformConnector(terraformResourceName) + remoteNetworkName := test.RandomName() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateConnectorAndRemoteNetworkDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceTwingateConnector(terraformResourceName, terraformResourceName, remoteNetworkName), + Check: acctests.ComposeTestCheckFunc( + checkTwingateConnectorSetWithRemoteNetwork(theResource, acctests.TerraformRemoteNetwork(terraformResourceName)), + sdk.TestCheckResourceAttrSet(theResource, attr.Name), + ), }, - }) + { + // expecting no changes, as by default notifications enabled + PlanOnly: true, + Config: terraformResourceTwingateConnectorWithNotificationStatus(terraformResourceName, terraformResourceName, remoteNetworkName, true), + Check: acctests.ComposeTestCheckFunc( + sdk.TestCheckResourceAttr(theResource, attr.StatusUpdatesEnabled, "true"), + ), + }, + { + Config: terraformResourceTwingateConnectorWithNotificationStatus(terraformResourceName, terraformResourceName, remoteNetworkName, false), + Check: acctests.ComposeTestCheckFunc( + sdk.TestCheckResourceAttr(theResource, attr.StatusUpdatesEnabled, "false"), + ), + }, + { + // expecting no changes, when user removes `status_updates_enabled` field from terraform + PlanOnly: true, + Config: terraformResourceTwingateConnector(terraformResourceName, terraformResourceName, remoteNetworkName), + Check: acctests.ComposeTestCheckFunc( + sdk.TestCheckResourceAttr(theResource, attr.StatusUpdatesEnabled, "false"), + ), + }, + }, }) } @@ -282,6 +282,8 @@ func terraformResourceTwingateConnectorWithNotificationStatus(terraformRemoteNet } func TestAccRemoteConnectorCreateWithNotificationStatusFalse(t *testing.T) { + t.Parallel() + const terraformResourceName = "test_c8" theResource := acctests.TerraformConnector(terraformResourceName) remoteNetworkName := test.RandomName() diff --git a/twingate/internal/test/acctests/resource/group_test.go b/twingate/internal/test/acctests/resource/group_test.go index 531b063d..d92de38b 100644 --- a/twingate/internal/test/acctests/resource/group_test.go +++ b/twingate/internal/test/acctests/resource/group_test.go @@ -18,33 +18,33 @@ var ( ) func TestAccTwingateGroupCreateUpdate(t *testing.T) { - t.Run("Test Twingate Resource : Acc Group Create/Update", func(t *testing.T) { - const terraformResourceName = "test001" - theResource := acctests.TerraformGroup(terraformResourceName) - nameBefore := test.RandomName() - nameAfter := test.RandomName() - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateGroupDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceTwingateGroup(terraformResourceName, nameBefore), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - sdk.TestCheckResourceAttr(theResource, attr.Name, nameBefore), - ), - }, - { - Config: terraformResourceTwingateGroup(terraformResourceName, nameAfter), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - sdk.TestCheckResourceAttr(theResource, attr.Name, nameAfter), - ), - }, + t.Parallel() + + const terraformResourceName = "test001" + theResource := acctests.TerraformGroup(terraformResourceName) + nameBefore := test.RandomName() + nameAfter := test.RandomName() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateGroupDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceTwingateGroup(terraformResourceName, nameBefore), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + sdk.TestCheckResourceAttr(theResource, attr.Name, nameBefore), + ), }, - }) + { + Config: terraformResourceTwingateGroup(terraformResourceName, nameAfter), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + sdk.TestCheckResourceAttr(theResource, attr.Name, nameAfter), + ), + }, + }, }) } @@ -57,107 +57,107 @@ func terraformResourceTwingateGroup(terraformResourceName, name string) string { } func TestAccTwingateGroupDeleteNonExisting(t *testing.T) { - t.Run("Test Twingate Resource : Acc Group Delete NonExisting", func(t *testing.T) { - const terraformResourceName = "test002" - theResource := acctests.TerraformGroup(terraformResourceName) - groupName := test.RandomName() - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateGroupDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceTwingateGroup(terraformResourceName, groupName), - Destroy: true, - }, - { - Config: terraformResourceTwingateGroup(terraformResourceName, groupName), - ConfigPlanChecks: sdk.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(theResource, plancheck.ResourceActionCreate), - }, + t.Parallel() + + const terraformResourceName = "test002" + theResource := acctests.TerraformGroup(terraformResourceName) + groupName := test.RandomName() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateGroupDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceTwingateGroup(terraformResourceName, groupName), + Destroy: true, + }, + { + Config: terraformResourceTwingateGroup(terraformResourceName, groupName), + ConfigPlanChecks: sdk.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(theResource, plancheck.ResourceActionCreate), }, }, }, - }) + }, }) } func TestAccTwingateGroupReCreateAfterDeletion(t *testing.T) { - t.Run("Test Twingate Resource : Acc Group Create After Deletion", func(t *testing.T) { - const terraformResourceName = "test003" - theResource := acctests.TerraformGroup(terraformResourceName) - groupName := test.RandomName() - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateGroupDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceTwingateGroup(terraformResourceName, groupName), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - acctests.DeleteTwingateResource(theResource, resource.TwingateGroup), - ), - ExpectNonEmptyPlan: true, - }, - { - Config: terraformResourceTwingateGroup(terraformResourceName, groupName), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - ), - }, + t.Parallel() + + const terraformResourceName = "test003" + theResource := acctests.TerraformGroup(terraformResourceName) + groupName := test.RandomName() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateGroupDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceTwingateGroup(terraformResourceName, groupName), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + acctests.DeleteTwingateResource(theResource, resource.TwingateGroup), + ), + ExpectNonEmptyPlan: true, + }, + { + Config: terraformResourceTwingateGroup(terraformResourceName, groupName), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + ), }, - }) + }, }) } func TestAccTwingateGroupWithSecurityPolicy(t *testing.T) { - t.Run("Test Twingate Resource : Acc Group Create/Update - With Security Policy", func(t *testing.T) { - const terraformResourceName = "test004" - theResource := acctests.TerraformGroup(terraformResourceName) - name := test.RandomName() - - securityPolicies, err := acctests.ListSecurityPolicies() - if err != nil { - t.Skip("can't run test:", err) - } - - testPolicy := securityPolicies[0] - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateGroupDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceTwingateGroup(terraformResourceName, name), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - sdk.TestCheckResourceAttr(theResource, attr.Name, name), - ), - }, - { - Config: terraformResourceTwingateGroupWithSecurityPolicy(terraformResourceName, name, testPolicy.ID), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - sdk.TestCheckResourceAttr(theResource, attr.Name, name), - sdk.TestCheckResourceAttr(theResource, attr.SecurityPolicyID, testPolicy.ID), - ), - }, - { - // expecting no changes - PlanOnly: true, - Config: terraformResourceTwingateGroup(terraformResourceName, name), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - sdk.TestCheckResourceAttr(theResource, attr.Name, name), - ), - }, + t.Parallel() + + const terraformResourceName = "test004" + theResource := acctests.TerraformGroup(terraformResourceName) + name := test.RandomName() + + securityPolicies, err := acctests.ListSecurityPolicies() + if err != nil { + t.Skip("can't run test:", err) + } + + testPolicy := securityPolicies[0] + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateGroupDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceTwingateGroup(terraformResourceName, name), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + sdk.TestCheckResourceAttr(theResource, attr.Name, name), + ), + }, + { + Config: terraformResourceTwingateGroupWithSecurityPolicy(terraformResourceName, name, testPolicy.ID), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + sdk.TestCheckResourceAttr(theResource, attr.Name, name), + sdk.TestCheckResourceAttr(theResource, attr.SecurityPolicyID, testPolicy.ID), + ), + }, + { + // expecting no changes + PlanOnly: true, + Config: terraformResourceTwingateGroup(terraformResourceName, name), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + sdk.TestCheckResourceAttr(theResource, attr.Name, name), + ), }, - }) + }, }) } @@ -171,92 +171,92 @@ func terraformResourceTwingateGroupWithSecurityPolicy(terraformResourceName, nam } func TestAccTwingateGroupUsersAuthoritativeByDefault(t *testing.T) { - t.Run("Test Twingate Resource : Acc Group Users Authoritative By Default", func(t *testing.T) { - const terraformResourceName = "test005" - theResource := acctests.TerraformGroup(terraformResourceName) - groupName := test.RandomName() - - users, userIDs := genNewUsers("u005", 3) - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateGroupDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceTwingateGroupWithUsers(terraformResourceName, groupName, users, userIDs[:1]), - Check: acctests.ComposeTestCheckFunc( - sdk.TestCheckResourceAttr(theResource, userIdsLen, "1"), - acctests.CheckGroupUsersLen(theResource, 1), - ), - }, - { - Config: terraformResourceTwingateGroupWithUsers(terraformResourceName, groupName, users, userIDs[:1]), - Check: acctests.ComposeTestCheckFunc( - // added new user to the group though API - acctests.AddGroupUser(theResource, groupName, userIDs[1]), - acctests.WaitTestFunc(), - acctests.CheckGroupUsersLen(theResource, 2), - ), - // expecting drift - terraform going to remove unknown user - ExpectNonEmptyPlan: true, - }, - { - Config: terraformResourceTwingateGroupWithUsers(terraformResourceName, groupName, users, userIDs[:1]), - Check: acctests.ComposeTestCheckFunc( - sdk.TestCheckResourceAttr(theResource, userIdsLen, "1"), - acctests.CheckGroupUsersLen(theResource, 1), - ), - }, - { - // added 2 new users to the group though terraform - Config: terraformResourceTwingateGroupWithUsers(terraformResourceName, groupName, users, userIDs[:3]), - Check: acctests.ComposeTestCheckFunc( - sdk.TestCheckResourceAttr(theResource, userIdsLen, "3"), - acctests.CheckGroupUsersLen(theResource, 3), - ), - }, - { - Config: terraformResourceTwingateGroupWithUsers(terraformResourceName, groupName, users, userIDs[:3]), - Check: acctests.ComposeTestCheckFunc( - // delete one user from the group though API - acctests.DeleteGroupUser(theResource, userIDs[2]), - acctests.WaitTestFunc(), - sdk.TestCheckResourceAttr(theResource, userIdsLen, "3"), - acctests.CheckGroupUsersLen(theResource, 2), - ), - // expecting drift - terraform going to restore deleted user - ExpectNonEmptyPlan: true, - }, - { - Config: terraformResourceTwingateGroupWithUsers(terraformResourceName, groupName, users, userIDs[:3]), - Check: acctests.ComposeTestCheckFunc( - sdk.TestCheckResourceAttr(theResource, userIdsLen, "3"), - acctests.CheckGroupUsersLen(theResource, 3), - ), - }, - { - // remove 2 users from the group though terraform - Config: terraformResourceTwingateGroupWithUsers(terraformResourceName, groupName, users, userIDs[:1]), - Check: acctests.ComposeTestCheckFunc( - sdk.TestCheckResourceAttr(theResource, userIdsLen, "1"), - acctests.CheckGroupUsersLen(theResource, 1), - ), - }, - { - // expecting no drift - Config: terraformResourceTwingateGroupWithUsersAuthoritative(terraformResourceName, groupName, users, userIDs[:1], true), - PlanOnly: true, - }, - { - Config: terraformResourceTwingateGroupWithUsersAuthoritative(terraformResourceName, groupName, users, userIDs[:2], true), - Check: acctests.ComposeTestCheckFunc( - sdk.TestCheckResourceAttr(theResource, userIdsLen, "2"), - acctests.CheckGroupUsersLen(theResource, 2), - ), - }, + t.Parallel() + + const terraformResourceName = "test005" + theResource := acctests.TerraformGroup(terraformResourceName) + groupName := test.RandomName() + + users, userIDs := genNewUsers("u005", 3) + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateGroupDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceTwingateGroupWithUsers(terraformResourceName, groupName, users, userIDs[:1]), + Check: acctests.ComposeTestCheckFunc( + sdk.TestCheckResourceAttr(theResource, userIdsLen, "1"), + acctests.CheckGroupUsersLen(theResource, 1), + ), + }, + { + Config: terraformResourceTwingateGroupWithUsers(terraformResourceName, groupName, users, userIDs[:1]), + Check: acctests.ComposeTestCheckFunc( + // added new user to the group though API + acctests.AddGroupUser(theResource, groupName, userIDs[1]), + acctests.WaitTestFunc(), + acctests.CheckGroupUsersLen(theResource, 2), + ), + // expecting drift - terraform going to remove unknown user + ExpectNonEmptyPlan: true, + }, + { + Config: terraformResourceTwingateGroupWithUsers(terraformResourceName, groupName, users, userIDs[:1]), + Check: acctests.ComposeTestCheckFunc( + sdk.TestCheckResourceAttr(theResource, userIdsLen, "1"), + acctests.CheckGroupUsersLen(theResource, 1), + ), + }, + { + // added 2 new users to the group though terraform + Config: terraformResourceTwingateGroupWithUsers(terraformResourceName, groupName, users, userIDs[:3]), + Check: acctests.ComposeTestCheckFunc( + sdk.TestCheckResourceAttr(theResource, userIdsLen, "3"), + acctests.CheckGroupUsersLen(theResource, 3), + ), }, - }) + { + Config: terraformResourceTwingateGroupWithUsers(terraformResourceName, groupName, users, userIDs[:3]), + Check: acctests.ComposeTestCheckFunc( + // delete one user from the group though API + acctests.DeleteGroupUser(theResource, userIDs[2]), + acctests.WaitTestFunc(), + sdk.TestCheckResourceAttr(theResource, userIdsLen, "3"), + acctests.CheckGroupUsersLen(theResource, 2), + ), + // expecting drift - terraform going to restore deleted user + ExpectNonEmptyPlan: true, + }, + { + Config: terraformResourceTwingateGroupWithUsers(terraformResourceName, groupName, users, userIDs[:3]), + Check: acctests.ComposeTestCheckFunc( + sdk.TestCheckResourceAttr(theResource, userIdsLen, "3"), + acctests.CheckGroupUsersLen(theResource, 3), + ), + }, + { + // remove 2 users from the group though terraform + Config: terraformResourceTwingateGroupWithUsers(terraformResourceName, groupName, users, userIDs[:1]), + Check: acctests.ComposeTestCheckFunc( + sdk.TestCheckResourceAttr(theResource, userIdsLen, "1"), + acctests.CheckGroupUsersLen(theResource, 1), + ), + }, + { + // expecting no drift + Config: terraformResourceTwingateGroupWithUsersAuthoritative(terraformResourceName, groupName, users, userIDs[:1], true), + PlanOnly: true, + }, + { + Config: terraformResourceTwingateGroupWithUsersAuthoritative(terraformResourceName, groupName, users, userIDs[:2], true), + Check: acctests.ComposeTestCheckFunc( + sdk.TestCheckResourceAttr(theResource, userIdsLen, "2"), + acctests.CheckGroupUsersLen(theResource, 2), + ), + }, + }, }) } @@ -284,93 +284,91 @@ func terraformResourceTwingateGroupWithUsersAuthoritative(terraformResourceName, } func TestAccTwingateGroupUsersNotAuthoritative(t *testing.T) { - t.Run("Test Twingate Resource : Acc Group Users Not Authoritative", func(t *testing.T) { - const terraformResourceName = "test006" - theResource := acctests.TerraformGroup(terraformResourceName) - groupName := test.RandomName() - - users, userIDs := genNewUsers("u006", 3) - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateGroupDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceTwingateGroupWithUsersAuthoritative(terraformResourceName, groupName, users, userIDs[:1], false), - Check: acctests.ComposeTestCheckFunc( - sdk.TestCheckResourceAttr(theResource, userIdsLen, "1"), - acctests.CheckGroupUsersLen(theResource, 1), - ), - }, - { - Config: terraformResourceTwingateGroupWithUsersAuthoritative(terraformResourceName, groupName, users, userIDs[:1], false), - Check: acctests.ComposeTestCheckFunc( - // added new user to the group though API - acctests.AddGroupUser(theResource, groupName, userIDs[2]), - acctests.WaitTestFunc(), - acctests.CheckGroupUsersLen(theResource, 2), - ), - }, - { - // added new user to the group though terraform - Config: terraformResourceTwingateGroupWithUsersAuthoritative(terraformResourceName, groupName, users, userIDs[:2], false), - Check: acctests.ComposeTestCheckFunc( - sdk.TestCheckResourceAttr(theResource, userIdsLen, "2"), - acctests.CheckGroupUsersLen(theResource, 3), - ), - }, - { - // remove one user from the group though terraform - Config: terraformResourceTwingateGroupWithUsersAuthoritative(terraformResourceName, groupName, users, userIDs[:1], false), - Check: acctests.ComposeTestCheckFunc( - sdk.TestCheckResourceAttr(theResource, userIdsLen, "1"), - acctests.CheckGroupUsersLen(theResource, 2), - // remove one user from the group though API - acctests.DeleteGroupUser(theResource, userIDs[2]), - acctests.WaitTestFunc(), - acctests.CheckGroupUsersLen(theResource, 1), - ), - }, - { - // expecting no drift - empty plan - Config: terraformResourceTwingateGroupWithUsersAuthoritative(terraformResourceName, groupName, users, userIDs[:1], false), - PlanOnly: true, - }, + t.Parallel() + + const terraformResourceName = "test006" + theResource := acctests.TerraformGroup(terraformResourceName) + groupName := test.RandomName() + + users, userIDs := genNewUsers("u006", 3) + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateGroupDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceTwingateGroupWithUsersAuthoritative(terraformResourceName, groupName, users, userIDs[:1], false), + Check: acctests.ComposeTestCheckFunc( + sdk.TestCheckResourceAttr(theResource, userIdsLen, "1"), + acctests.CheckGroupUsersLen(theResource, 1), + ), + }, + { + Config: terraformResourceTwingateGroupWithUsersAuthoritative(terraformResourceName, groupName, users, userIDs[:1], false), + Check: acctests.ComposeTestCheckFunc( + // added new user to the group though API + acctests.AddGroupUser(theResource, groupName, userIDs[2]), + acctests.WaitTestFunc(), + acctests.CheckGroupUsersLen(theResource, 2), + ), + }, + { + // added new user to the group though terraform + Config: terraformResourceTwingateGroupWithUsersAuthoritative(terraformResourceName, groupName, users, userIDs[:2], false), + Check: acctests.ComposeTestCheckFunc( + sdk.TestCheckResourceAttr(theResource, userIdsLen, "2"), + acctests.CheckGroupUsersLen(theResource, 3), + ), + }, + { + // remove one user from the group though terraform + Config: terraformResourceTwingateGroupWithUsersAuthoritative(terraformResourceName, groupName, users, userIDs[:1], false), + Check: acctests.ComposeTestCheckFunc( + sdk.TestCheckResourceAttr(theResource, userIdsLen, "1"), + acctests.CheckGroupUsersLen(theResource, 2), + // remove one user from the group though API + acctests.DeleteGroupUser(theResource, userIDs[2]), + acctests.WaitTestFunc(), + acctests.CheckGroupUsersLen(theResource, 1), + ), }, - }) + { + // expecting no drift - empty plan + Config: terraformResourceTwingateGroupWithUsersAuthoritative(terraformResourceName, groupName, users, userIDs[:1], false), + PlanOnly: true, + }, + }, }) } func TestAccTwingateGroupUsersCursor(t *testing.T) { - t.Run("Test Twingate Resource : Acc Group Users Cursor", func(t *testing.T) { - acctests.SetPageLimit(1) - - const terraformResourceName = "test007" - theResource := acctests.TerraformGroup(terraformResourceName) - groupName := test.RandomName() - - users, userIDs := genNewUsers("u007", 3) - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateGroupDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceTwingateGroupAndUsers(terraformResourceName, groupName, users, userIDs), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckGroupUsersLen(theResource, len(users)), - ), - }, - { - Config: terraformResourceTwingateGroupAndUsers(terraformResourceName, groupName, users, userIDs[:2]), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckGroupUsersLen(theResource, 2), - ), - }, + t.Parallel() + + const terraformResourceName = "test007" + theResource := acctests.TerraformGroup(terraformResourceName) + groupName := test.RandomName() + + users, userIDs := genNewUsers("u007", 3) + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateGroupDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceTwingateGroupAndUsers(terraformResourceName, groupName, users, userIDs), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckGroupUsersLen(theResource, len(users)), + ), + }, + { + Config: terraformResourceTwingateGroupAndUsers(terraformResourceName, groupName, users, userIDs[:2]), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckGroupUsersLen(theResource, 2), + ), }, - }) + }, }) } diff --git a/twingate/internal/test/acctests/resource/remote-network_test.go b/twingate/internal/test/acctests/resource/remote-network_test.go index 09185429..60f1d037 100644 --- a/twingate/internal/test/acctests/resource/remote-network_test.go +++ b/twingate/internal/test/acctests/resource/remote-network_test.go @@ -14,27 +14,27 @@ import ( ) func TestAccTwingateRemoteNetworkCreate(t *testing.T) { - t.Run("Test Twingate Resource : Acc Remote Network Create", func(t *testing.T) { - const terraformResourceName = "test000" - theResource := acctests.TerraformRemoteNetwork(terraformResourceName) - networkName := test.RandomName() - networkLocation := model.LocationAzure - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateRemoteNetworkDestroy, - Steps: []sdk.TestStep{ - { - Config: createRemoteNetworkWithLocation(terraformResourceName, networkName, networkLocation), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - sdk.TestCheckResourceAttr(theResource, attr.Name, networkName), - sdk.TestCheckResourceAttr(theResource, attr.Location, networkLocation), - ), - }, + t.Parallel() + + const terraformResourceName = "test000" + theResource := acctests.TerraformRemoteNetwork(terraformResourceName) + networkName := test.RandomName() + networkLocation := model.LocationAzure + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateRemoteNetworkDestroy, + Steps: []sdk.TestStep{ + { + Config: createRemoteNetworkWithLocation(terraformResourceName, networkName, networkLocation), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + sdk.TestCheckResourceAttr(theResource, attr.Name, networkName), + sdk.TestCheckResourceAttr(theResource, attr.Location, networkLocation), + ), }, - }) + }, }) } @@ -48,35 +48,35 @@ func createRemoteNetworkWithLocation(terraformResourceName, name, location strin } func TestAccTwingateRemoteNetworkUpdate(t *testing.T) { - t.Run("Test Twingate Resource : Acc Remote Network Update", func(t *testing.T) { - const terraformResourceName = "test001" - theResource := acctests.TerraformRemoteNetwork(terraformResourceName) - nameBefore := test.RandomName() - nameAfter := test.RandomName() - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateRemoteNetworkDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceRemoteNetwork(terraformResourceName, nameBefore), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - sdk.TestCheckResourceAttr(theResource, attr.Name, nameBefore), - sdk.TestCheckResourceAttr(theResource, attr.Location, model.LocationOther), - ), - }, - { - Config: createRemoteNetworkWithLocation(terraformResourceName, nameAfter, model.LocationAWS), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - sdk.TestCheckResourceAttr(theResource, attr.Name, nameAfter), - sdk.TestCheckResourceAttr(theResource, attr.Location, model.LocationAWS), - ), - }, + t.Parallel() + + const terraformResourceName = "test001" + theResource := acctests.TerraformRemoteNetwork(terraformResourceName) + nameBefore := test.RandomName() + nameAfter := test.RandomName() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateRemoteNetworkDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceRemoteNetwork(terraformResourceName, nameBefore), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + sdk.TestCheckResourceAttr(theResource, attr.Name, nameBefore), + sdk.TestCheckResourceAttr(theResource, attr.Location, model.LocationOther), + ), + }, + { + Config: createRemoteNetworkWithLocation(terraformResourceName, nameAfter, model.LocationAWS), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + sdk.TestCheckResourceAttr(theResource, attr.Name, nameAfter), + sdk.TestCheckResourceAttr(theResource, attr.Location, model.LocationAWS), + ), }, - }) + }, }) } @@ -89,91 +89,91 @@ func terraformResourceRemoteNetwork(terraformResourceName, name string) string { } func TestAccTwingateRemoteNetworkDeleteNonExisting(t *testing.T) { - t.Run("Test Twingate Resource : Acc Remote Network Delete NonExisting", func(t *testing.T) { - const terraformResourceName = "test002" - theResource := acctests.TerraformRemoteNetwork(terraformResourceName) - networkName := test.RandomName() - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateRemoteNetworkDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceRemoteNetwork(terraformResourceName, networkName), - Destroy: true, - }, - { - Config: terraformResourceRemoteNetwork(terraformResourceName, networkName), - ConfigPlanChecks: sdk.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(theResource, plancheck.ResourceActionCreate), - }, + t.Parallel() + + const terraformResourceName = "test002" + theResource := acctests.TerraformRemoteNetwork(terraformResourceName) + networkName := test.RandomName() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateRemoteNetworkDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceRemoteNetwork(terraformResourceName, networkName), + Destroy: true, + }, + { + Config: terraformResourceRemoteNetwork(terraformResourceName, networkName), + ConfigPlanChecks: sdk.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(theResource, plancheck.ResourceActionCreate), }, }, }, - }) + }, }) } func TestAccTwingateRemoteNetworkReCreateAfterDeletion(t *testing.T) { - t.Run("Test Twingate Resource : Acc Remote Network Re Create After Deletion", func(t *testing.T) { - const terraformResourceName = "test003" - theResource := acctests.TerraformRemoteNetwork(terraformResourceName) - remoteNetworkName := test.RandomName() - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateRemoteNetworkDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceRemoteNetwork(terraformResourceName, remoteNetworkName), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - acctests.DeleteTwingateResource(theResource, resource.TwingateRemoteNetwork), - ), - ExpectNonEmptyPlan: true, - }, - { - Config: terraformResourceRemoteNetwork(terraformResourceName, remoteNetworkName), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - ), - }, + t.Parallel() + + const terraformResourceName = "test003" + theResource := acctests.TerraformRemoteNetwork(terraformResourceName) + remoteNetworkName := test.RandomName() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateRemoteNetworkDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceRemoteNetwork(terraformResourceName, remoteNetworkName), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + acctests.DeleteTwingateResource(theResource, resource.TwingateRemoteNetwork), + ), + ExpectNonEmptyPlan: true, + }, + { + Config: terraformResourceRemoteNetwork(terraformResourceName, remoteNetworkName), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + ), }, - }) + }, }) } func TestAccTwingateRemoteNetworkUpdateWithTheSameName(t *testing.T) { - t.Run("Test Twingate Resource : Acc Remote Network Update With The Same Name", func(t *testing.T) { - const terraformResourceName = "test004" - theResource := acctests.TerraformRemoteNetwork(terraformResourceName) - name := test.RandomName() - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateRemoteNetworkDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceRemoteNetwork(terraformResourceName, name), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - sdk.TestCheckResourceAttr(theResource, attr.Name, name), - sdk.TestCheckResourceAttr(theResource, attr.Location, model.LocationOther), - ), - }, - { - Config: createRemoteNetworkWithLocation(terraformResourceName, name, model.LocationAWS), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - sdk.TestCheckResourceAttr(theResource, attr.Name, name), - sdk.TestCheckResourceAttr(theResource, attr.Location, model.LocationAWS), - ), - }, + t.Parallel() + + const terraformResourceName = "test004" + theResource := acctests.TerraformRemoteNetwork(terraformResourceName) + name := test.RandomName() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateRemoteNetworkDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceRemoteNetwork(terraformResourceName, name), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + sdk.TestCheckResourceAttr(theResource, attr.Name, name), + sdk.TestCheckResourceAttr(theResource, attr.Location, model.LocationOther), + ), + }, + { + Config: createRemoteNetworkWithLocation(terraformResourceName, name, model.LocationAWS), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + sdk.TestCheckResourceAttr(theResource, attr.Name, name), + sdk.TestCheckResourceAttr(theResource, attr.Location, model.LocationAWS), + ), }, - }) + }, }) } diff --git a/twingate/internal/test/acctests/resource/resource_test.go b/twingate/internal/test/acctests/resource/resource_test.go index ec07f6ef..3c6a1e91 100644 --- a/twingate/internal/test/acctests/resource/resource_test.go +++ b/twingate/internal/test/acctests/resource/resource_test.go @@ -30,6 +30,8 @@ var ( ) func TestAccTwingateResourceCreate(t *testing.T) { + t.Parallel() + const terraformResourceName = "test1" theResource := acctests.TerraformResource(terraformResourceName) remoteNetworkName := test.RandomName() @@ -55,6 +57,8 @@ func TestAccTwingateResourceCreate(t *testing.T) { } func TestAccTwingateResourceUpdateProtocols(t *testing.T) { + t.Parallel() + const terraformResourceName = "test1u" theResource := acctests.TerraformResource(terraformResourceName) remoteNetworkName := test.RandomName() @@ -124,6 +128,8 @@ func createResourceWithSimpleProtocols(terraformResourceName, networkName, resou } func TestAccTwingateResourceCreateWithProtocolsAndGroups(t *testing.T) { + t.Parallel() + const theResource = "twingate_resource.test2" remoteNetworkName := test.RandomName() groupName1 := test.RandomGroupName() @@ -190,6 +196,8 @@ func createResourceWithProtocolsAndGroups(networkName, groupName1, groupName2, r } func TestAccTwingateResourceFullCreationFlow(t *testing.T) { + t.Parallel() + const theResource = "twingate_resource.test3" remoteNetworkName := test.RandomName() groupName := test.RandomGroupName() @@ -262,6 +270,8 @@ func resourceFullCreationFlow(networkName, groupName, resourceName string) strin } func TestAccTwingateResourceWithInvalidGroupId(t *testing.T) { + t.Parallel() + resourceName := test.RandomResourceName() networkName := test.RandomResourceName() @@ -299,6 +309,8 @@ func createResourceWithInvalidGroupId(networkName, resourceName string) string { } func TestAccTwingateResourceWithTcpDenyAllPolicy(t *testing.T) { + t.Parallel() + const theResource = "twingate_resource.test5" resourceName := test.RandomResourceName() networkName := test.RandomResourceName() @@ -356,6 +368,8 @@ func createResourceWithTcpDenyAllPolicy(networkName, groupName, resourceName str } func TestAccTwingateResourceWithUdpDenyAllPolicy(t *testing.T) { + t.Parallel() + const theResource = "twingate_resource.test6" remoteNetworkName := test.RandomName() groupName := test.RandomGroupName() @@ -413,6 +427,8 @@ func createResourceWithUdpDenyAllPolicy(networkName, groupName, resourceName str } func TestAccTwingateResourceWithDenyAllPolicyAndEmptyPortsList(t *testing.T) { + t.Parallel() + const theResource = "twingate_resource.test7" remoteNetworkName := test.RandomName() groupName := test.RandomGroupName() @@ -473,6 +489,8 @@ func createResourceWithDenyAllPolicyAndEmptyPortsList(networkName, groupName, re } func TestAccTwingateResourceWithInvalidPortRange(t *testing.T) { + t.Parallel() + remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() expectedError := regexp.MustCompile("failed to parse protocols port range") @@ -546,6 +564,8 @@ func createResourceWithRestrictedPolicyAndPortRange(networkName, resourceName, p } func TestAccTwingateResourcePortReorderingCreatesNoChanges(t *testing.T) { + t.Parallel() + const theResource = "twingate_resource.test9" remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() @@ -612,6 +632,8 @@ func createResourceWithPortRange(networkName, resourceName, portRange string) st } func TestAccTwingateResourcePortsRepresentationChanged(t *testing.T) { + t.Parallel() + const theResource = "twingate_resource.test9" remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() @@ -633,6 +655,8 @@ func TestAccTwingateResourcePortsRepresentationChanged(t *testing.T) { } func TestAccTwingateResourcePortsNotChanged(t *testing.T) { + t.Parallel() + const theResource = "twingate_resource.test9" remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() @@ -662,6 +686,8 @@ func TestAccTwingateResourcePortsNotChanged(t *testing.T) { } func TestAccTwingateResourcePortReorderingNoChanges(t *testing.T) { + t.Parallel() + const theResource = "twingate_resource.test9" remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() @@ -706,6 +732,8 @@ func TestAccTwingateResourcePortReorderingNoChanges(t *testing.T) { } func TestAccTwingateResourceSetActiveStateOnUpdate(t *testing.T) { + t.Parallel() + const terraformResourceName = "test10" theResource := acctests.TerraformResource(terraformResourceName) remoteNetworkName := test.RandomName() @@ -738,6 +766,8 @@ func TestAccTwingateResourceSetActiveStateOnUpdate(t *testing.T) { } func TestAccTwingateResourceReCreateAfterDeletion(t *testing.T) { + t.Parallel() + const terraformResourceName = "test10" theResource := acctests.TerraformResource(terraformResourceName) remoteNetworkName := test.RandomName() @@ -767,6 +797,8 @@ func TestAccTwingateResourceReCreateAfterDeletion(t *testing.T) { } func TestAccTwingateResourceImport(t *testing.T) { + t.Parallel() + const theResource = "twingate_resource.test12" remoteNetworkName := test.RandomName() groupName := test.RandomGroupName() @@ -885,6 +917,8 @@ func newTerraformGroup(resourceName, groupName string) string { } func TestAccTwingateResourceAddAccessServiceAccounts(t *testing.T) { + t.Parallel() + const theResource = "twingate_resource.test15" remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() @@ -942,6 +976,8 @@ func createResource15(networkName, resourceName string, terraformServiceAccount } func TestAccTwingateResourceAddAccessGroupsAndServiceAccounts(t *testing.T) { + t.Parallel() + const theResource = "twingate_resource.test16" remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() @@ -1101,6 +1137,7 @@ func createResource16WithoutGroups(networkName, resourceName string, groups, gro func TestAccTwingateResourceAccessServiceAccountsNotAuthoritative(t *testing.T) { t.Parallel() + const theResource = "twingate_resource.test17" remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() @@ -1214,6 +1251,7 @@ func createResource17(networkName, resourceName string, serviceAccounts, service func TestAccTwingateResourceAccessServiceAccountsAuthoritative(t *testing.T) { t.Parallel() + const theResource = "twingate_resource.test13" remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() @@ -1324,6 +1362,8 @@ func createResource13(networkName, resourceName string, serviceAccounts, service } func TestAccTwingateResourceAccessWithEmptyGroups(t *testing.T) { + t.Parallel() + remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() @@ -1371,6 +1411,8 @@ func createResource18(networkName, resourceName string) string { } func TestAccTwingateResourceAccessWithEmptyServiceAccounts(t *testing.T) { + t.Parallel() + remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() @@ -1418,6 +1460,8 @@ func createResource19(networkName, resourceName string) string { } func TestAccTwingateResourceAccessWithEmptyBlock(t *testing.T) { + t.Parallel() + remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() @@ -1465,6 +1509,7 @@ func createResource20(networkName, resourceName string) string { func TestAccTwingateResourceAccessGroupsNotAuthoritative(t *testing.T) { t.Parallel() + const theResource = "twingate_resource.test22" remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() @@ -1578,6 +1623,7 @@ func createResource22(networkName, resourceName string, groups, groupsID []strin func TestAccTwingateResourceAccessGroupsAuthoritative(t *testing.T) { t.Parallel() + const theResource = "twingate_resource.test23" remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() @@ -1687,6 +1733,8 @@ func createResource23(networkName, resourceName string, groups, groupsID []strin } func TestGetResourceNameFromID(t *testing.T) { + t.Parallel() + cases := []struct { input string expected string @@ -1712,6 +1760,8 @@ func TestGetResourceNameFromID(t *testing.T) { } func TestAccTwingateCreateResourceWithFlagIsVisible(t *testing.T) { + t.Parallel() + const terraformResourceName = "test24" theResource := acctests.TerraformResource(terraformResourceName) remoteNetworkName := test.RandomName() @@ -1784,6 +1834,8 @@ func createResourceWithFlagIsVisible(terraformResourceName, networkName, resourc } func TestAccTwingateCreateResourceWithFlagIsBrowserShortcutEnabled(t *testing.T) { + t.Parallel() + const terraformResourceName = "test25" theResource := acctests.TerraformResource(terraformResourceName) remoteNetworkName := test.RandomName() @@ -1854,6 +1906,7 @@ func createResourceWithFlagIsBrowserShortcutEnabled(terraformResourceName, netwo func TestAccTwingateResourceGroupsAuthoritativeByDefault(t *testing.T) { t.Parallel() + const theResource = "twingate_resource.test26" remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() @@ -1962,6 +2015,8 @@ func createResource26(networkName, resourceName string, groups, groupsID []strin } func TestAccTwingateResourceDoesNotSupportOldGroups(t *testing.T) { + t.Parallel() + remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() @@ -2011,6 +2066,8 @@ func createResource28(networkName, resourceName string, groups, groupsID []strin } func TestAccTwingateResourceCreateWithAlias(t *testing.T) { + t.Parallel() + const terraformResourceName = "test29" theResource := acctests.TerraformResource(terraformResourceName) remoteNetworkName := test.RandomName() @@ -2049,6 +2106,8 @@ func TestAccTwingateResourceCreateWithAlias(t *testing.T) { } func TestAccTwingateResourceUpdateWithInvalidAlias(t *testing.T) { + t.Parallel() + const terraformResourceName = "test29_update_invalid" theResource := acctests.TerraformResource(terraformResourceName) remoteNetworkName := test.RandomName() @@ -2074,6 +2133,8 @@ func TestAccTwingateResourceUpdateWithInvalidAlias(t *testing.T) { } func TestAccTwingateResourceCreateWithInvalidAlias(t *testing.T) { + t.Parallel() + const terraformResourceName = "test29_create_invalid" remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() @@ -2120,7 +2181,7 @@ func createResource29WithoutAlias(terraformResourceName, networkName, resourceNa } func TestAccTwingateResourceGroupsCursor(t *testing.T) { - acctests.SetPageLimit(1) + t.Parallel() const terraformResourceName = "test27" theResource := acctests.TerraformResource(terraformResourceName) @@ -2199,6 +2260,8 @@ func createResourceWithGroupsAndServiceAccounts(name, networkName, resourceName } func TestAccTwingateResourceCreateWithPort(t *testing.T) { + t.Parallel() + remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() @@ -2251,6 +2314,8 @@ func createResourceWithPort(networkName, resourceName, port string) string { } func TestAccTwingateResourceUpdateWithPort(t *testing.T) { + t.Parallel() + theResource := acctests.TerraformResource("test30") remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() @@ -2275,6 +2340,8 @@ func TestAccTwingateResourceUpdateWithPort(t *testing.T) { } func TestAccTwingateResourceWithPortsFailsForAllowAllAndDenyAllPolicy(t *testing.T) { + t.Parallel() + const terraformResourceName = "test28" remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() @@ -2321,6 +2388,8 @@ func createResourceWithPorts(name, networkName, resourceName, policy string) str } func TestAccTwingateResourceWithoutPortsOkForAllowAllAndDenyAllPolicy(t *testing.T) { + t.Parallel() + const terraformResourceName = "test29" remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() @@ -2375,6 +2444,8 @@ func createResourceWithoutPorts(name, networkName, resourceName, policy string) } func TestAccTwingateResourceWithRestrictedPolicy(t *testing.T) { + t.Parallel() + const terraformResourceName = "test30" remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() @@ -2398,6 +2469,8 @@ func TestAccTwingateResourceWithRestrictedPolicy(t *testing.T) { } func TestAccTwingateResourcePolicyTransitionDenyAllToRestricted(t *testing.T) { + t.Parallel() + const terraformResourceName = "test31" theResource := acctests.TerraformResource(terraformResourceName) remoteNetworkName := test.RandomName() @@ -2429,6 +2502,8 @@ func TestAccTwingateResourcePolicyTransitionDenyAllToRestricted(t *testing.T) { } func TestAccTwingateResourcePolicyTransitionDenyAllToAllowAll(t *testing.T) { + t.Parallel() + const terraformResourceName = "test32" theResource := acctests.TerraformResource(terraformResourceName) remoteNetworkName := test.RandomName() @@ -2460,6 +2535,8 @@ func TestAccTwingateResourcePolicyTransitionDenyAllToAllowAll(t *testing.T) { } func TestAccTwingateResourcePolicyTransitionRestrictedToDenyAll(t *testing.T) { + t.Parallel() + const terraformResourceName = "test33" theResource := acctests.TerraformResource(terraformResourceName) remoteNetworkName := test.RandomName() @@ -2491,6 +2568,8 @@ func TestAccTwingateResourcePolicyTransitionRestrictedToDenyAll(t *testing.T) { } func TestAccTwingateResourcePolicyTransitionRestrictedToAllowAll(t *testing.T) { + t.Parallel() + const terraformResourceName = "test34" theResource := acctests.TerraformResource(terraformResourceName) remoteNetworkName := test.RandomName() @@ -2522,6 +2601,8 @@ func TestAccTwingateResourcePolicyTransitionRestrictedToAllowAll(t *testing.T) { } func TestAccTwingateResourcePolicyTransitionRestrictedToAllowAllWithPortsShouldFail(t *testing.T) { + t.Parallel() + const terraformResourceName = "test35" theResource := acctests.TerraformResource(terraformResourceName) remoteNetworkName := test.RandomName() @@ -2549,6 +2630,8 @@ func TestAccTwingateResourcePolicyTransitionRestrictedToAllowAllWithPortsShouldF } func TestAccTwingateResourcePolicyTransitionAllowAllToRestricted(t *testing.T) { + t.Parallel() + const terraformResourceName = "test36" theResource := acctests.TerraformResource(terraformResourceName) remoteNetworkName := test.RandomName() @@ -2580,6 +2663,8 @@ func TestAccTwingateResourcePolicyTransitionAllowAllToRestricted(t *testing.T) { } func TestAccTwingateResourcePolicyTransitionAllowAllToDenyAll(t *testing.T) { + t.Parallel() + const terraformResourceName = "test37" theResource := acctests.TerraformResource(terraformResourceName) remoteNetworkName := test.RandomName() @@ -2611,6 +2696,8 @@ func TestAccTwingateResourcePolicyTransitionAllowAllToDenyAll(t *testing.T) { } func TestAccTwingateResourceTestCaseInsensitiveAlias(t *testing.T) { + t.Parallel() + const terraformResourceName = "test38" theResource := acctests.TerraformResource(terraformResourceName) remoteNetworkName := test.RandomName() @@ -2643,6 +2730,8 @@ func TestAccTwingateResourceTestCaseInsensitiveAlias(t *testing.T) { } func TestAccTwingateResourceWithBrowserOption(t *testing.T) { + t.Parallel() + const terraformResourceName = "test40" theResource := acctests.TerraformResource(terraformResourceName) remoteNetworkName := test.RandomName() @@ -2675,6 +2764,8 @@ func TestAccTwingateResourceWithBrowserOption(t *testing.T) { } func TestAccTwingateResourceWithBrowserOptionFailOnUpdate(t *testing.T) { + t.Parallel() + const terraformResourceName = "test41" theResource := acctests.TerraformResource(terraformResourceName) remoteNetworkName := test.RandomName() @@ -2708,6 +2799,8 @@ func TestAccTwingateResourceWithBrowserOptionFailOnUpdate(t *testing.T) { } func TestAccTwingateResourceWithBrowserOptionRecovered(t *testing.T) { + t.Parallel() + const terraformResourceName = "test42" theResource := acctests.TerraformResource(terraformResourceName) remoteNetworkName := test.RandomName() @@ -2737,6 +2830,8 @@ func TestAccTwingateResourceWithBrowserOptionRecovered(t *testing.T) { } func TestAccTwingateResourceWithBrowserOptionIP(t *testing.T) { + t.Parallel() + const terraformResourceName = "testIPWithBrowserOption" theResource := acctests.TerraformResource(terraformResourceName) remoteNetworkName := test.RandomName() @@ -2771,6 +2866,8 @@ func TestAccTwingateResourceWithBrowserOptionIP(t *testing.T) { } func TestAccTwingateResourceWithBrowserOptionCIDR(t *testing.T) { + t.Parallel() + const terraformResourceName = "testCIDRWithBrowserOption" theResource := acctests.TerraformResource(terraformResourceName) remoteNetworkName := test.RandomName() @@ -2857,6 +2954,8 @@ func createResourceWithoutSecurityPolicy(remoteNetwork, resource string) string } func TestAccTwingateResourceUpdateWithDefaultProtocols(t *testing.T) { + t.Parallel() + remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() theResource := acctests.TerraformResource(resourceName) @@ -2920,6 +3019,8 @@ func createResourceWithoutProtocols(remoteNetwork, resource string) string { } func TestAccTwingateResourceUpdatePortsFromEmptyListToNull(t *testing.T) { + t.Parallel() + remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() theResource := acctests.TerraformResource(resourceName) @@ -2945,6 +3046,8 @@ func TestAccTwingateResourceUpdatePortsFromEmptyListToNull(t *testing.T) { } func TestAccTwingateResourceUpdatePortsFromNullToEmptyList(t *testing.T) { + t.Parallel() + remoteNetworkName := test.RandomName() resourceName := test.RandomResourceName() theResource := acctests.TerraformResource(resourceName) diff --git a/twingate/internal/test/acctests/resource/service-account_test.go b/twingate/internal/test/acctests/resource/service-account_test.go index 5b7ed5b4..36dae3fa 100644 --- a/twingate/internal/test/acctests/resource/service-account_test.go +++ b/twingate/internal/test/acctests/resource/service-account_test.go @@ -21,91 +21,91 @@ func createServiceAccount(resourceName, serviceAccountName string) string { } func TestAccTwingateServiceAccountCreateUpdate(t *testing.T) { - t.Run("Test Twingate Resource : Acc Service Account Create/Update", func(t *testing.T) { - const terraformResourceName = "test01" - theResource := acctests.TerraformServiceAccount(terraformResourceName) - nameBefore := test.RandomName() - nameAfter := test.RandomName() + t.Parallel() - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, - Steps: []sdk.TestStep{ - { - Config: createServiceAccount(terraformResourceName, nameBefore), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - sdk.TestCheckResourceAttr(theResource, attr.Name, nameBefore), - ), - }, - { - Config: createServiceAccount(terraformResourceName, nameAfter), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - sdk.TestCheckResourceAttr(theResource, attr.Name, nameAfter), - ), - }, + const terraformResourceName = "test01" + theResource := acctests.TerraformServiceAccount(terraformResourceName) + nameBefore := test.RandomName() + nameAfter := test.RandomName() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, + Steps: []sdk.TestStep{ + { + Config: createServiceAccount(terraformResourceName, nameBefore), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + sdk.TestCheckResourceAttr(theResource, attr.Name, nameBefore), + ), }, - }) + { + Config: createServiceAccount(terraformResourceName, nameAfter), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + sdk.TestCheckResourceAttr(theResource, attr.Name, nameAfter), + ), + }, + }, }) } func TestAccTwingateServiceAccountDeleteNonExisting(t *testing.T) { - t.Run("Test Twingate Resource : Acc Service Account Delete NonExisting", func(t *testing.T) { - const terraformResourceName = "test02" - theResource := acctests.TerraformServiceAccount(terraformResourceName) - name := test.RandomName() + t.Parallel() - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, - Steps: []sdk.TestStep{ - { - Config: createServiceAccount(terraformResourceName, name), - Destroy: true, - }, - { - Config: createServiceAccount(terraformResourceName, name), - ConfigPlanChecks: sdk.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(theResource, plancheck.ResourceActionCreate), - }, + const terraformResourceName = "test02" + theResource := acctests.TerraformServiceAccount(terraformResourceName) + name := test.RandomName() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, + Steps: []sdk.TestStep{ + { + Config: createServiceAccount(terraformResourceName, name), + Destroy: true, + }, + { + Config: createServiceAccount(terraformResourceName, name), + ConfigPlanChecks: sdk.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(theResource, plancheck.ResourceActionCreate), }, }, }, - }) + }, }) } func TestAccTwingateServiceAccountReCreateAfterDeletion(t *testing.T) { - t.Run("Test Twingate Resource : Acc Service Account Create After Deletion", func(t *testing.T) { - const terraformResourceName = "test03" - theResource := acctests.TerraformServiceAccount(terraformResourceName) - name := test.RandomName() + t.Parallel() - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, - Steps: []sdk.TestStep{ - { - Config: createServiceAccount(terraformResourceName, name), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - acctests.DeleteTwingateResource(theResource, resource.TwingateServiceAccount), - acctests.WaitTestFunc(), - ), - ExpectNonEmptyPlan: true, - }, - { - Config: createServiceAccount(terraformResourceName, name), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - ), - }, + const terraformResourceName = "test03" + theResource := acctests.TerraformServiceAccount(terraformResourceName) + name := test.RandomName() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, + Steps: []sdk.TestStep{ + { + Config: createServiceAccount(terraformResourceName, name), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + acctests.DeleteTwingateResource(theResource, resource.TwingateServiceAccount), + acctests.WaitTestFunc(), + ), + ExpectNonEmptyPlan: true, + }, + { + Config: createServiceAccount(terraformResourceName, name), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + ), }, - }) + }, }) } diff --git a/twingate/internal/test/acctests/resource/service-key_test.go b/twingate/internal/test/acctests/resource/service-key_test.go index 9f676e2a..95a75768 100644 --- a/twingate/internal/test/acctests/resource/service-key_test.go +++ b/twingate/internal/test/acctests/resource/service-key_test.go @@ -58,347 +58,347 @@ func nonEmptyValue(value string) error { } func TestAccTwingateServiceKeyCreateUpdate(t *testing.T) { - t.Run("Test Twingate Resource : Acc Service Key Create/Update", func(t *testing.T) { - serviceAccountName := test.RandomName() - terraformResourceName := test.TerraformRandName("test_key") - serviceAccount := acctests.TerraformServiceAccount(terraformResourceName) - serviceKey := acctests.TerraformServiceKey(terraformResourceName) - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, - Steps: []sdk.TestStep{ - { - Config: createServiceKey(terraformResourceName, serviceAccountName), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(serviceAccount), - sdk.TestCheckResourceAttr(serviceAccount, attr.Name, serviceAccountName), - acctests.CheckTwingateResourceExists(serviceKey), - sdk.TestCheckResourceAttrWith(serviceKey, attr.Token, nonEmptyValue), - ), - }, - { - Config: createServiceKey(terraformResourceName, serviceAccountName), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(serviceAccount), - sdk.TestCheckResourceAttr(serviceAccount, attr.Name, serviceAccountName), - acctests.CheckTwingateResourceExists(serviceKey), - sdk.TestCheckResourceAttrWith(serviceKey, attr.Token, nonEmptyValue), - ), - }, + t.Parallel() + + serviceAccountName := test.RandomName() + terraformResourceName := test.TerraformRandName("test_key") + serviceAccount := acctests.TerraformServiceAccount(terraformResourceName) + serviceKey := acctests.TerraformServiceKey(terraformResourceName) + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, + Steps: []sdk.TestStep{ + { + Config: createServiceKey(terraformResourceName, serviceAccountName), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(serviceAccount), + sdk.TestCheckResourceAttr(serviceAccount, attr.Name, serviceAccountName), + acctests.CheckTwingateResourceExists(serviceKey), + sdk.TestCheckResourceAttrWith(serviceKey, attr.Token, nonEmptyValue), + ), + }, + { + Config: createServiceKey(terraformResourceName, serviceAccountName), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(serviceAccount), + sdk.TestCheckResourceAttr(serviceAccount, attr.Name, serviceAccountName), + acctests.CheckTwingateResourceExists(serviceKey), + sdk.TestCheckResourceAttrWith(serviceKey, attr.Token, nonEmptyValue), + ), }, - }) + }, }) } func TestAccTwingateServiceKeyCreateUpdateWithName(t *testing.T) { - t.Run("Test Twingate Resource : Acc Service Key Create/Update With Name", func(t *testing.T) { - serviceAccountName := test.RandomName() - terraformResourceName := test.TerraformRandName("test_key") - serviceAccount := acctests.TerraformServiceAccount(terraformResourceName) - serviceKey := acctests.TerraformServiceKey(terraformResourceName) - beforeName := test.RandomName() - afterName := test.RandomName() - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, - Steps: []sdk.TestStep{ - { - Config: createServiceKeyWithName(terraformResourceName, serviceAccountName, beforeName), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(serviceAccount), - sdk.TestCheckResourceAttr(serviceAccount, attr.Name, serviceAccountName), - acctests.CheckTwingateResourceExists(serviceKey), - sdk.TestCheckResourceAttr(serviceKey, attr.Name, beforeName), - sdk.TestCheckResourceAttrWith(serviceKey, attr.Token, nonEmptyValue), - ), - }, - { - Config: createServiceKeyWithName(terraformResourceName, serviceAccountName, afterName), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(serviceAccount), - sdk.TestCheckResourceAttr(serviceAccount, attr.Name, serviceAccountName), - acctests.CheckTwingateResourceExists(serviceKey), - sdk.TestCheckResourceAttr(serviceKey, attr.Name, afterName), - sdk.TestCheckResourceAttrWith(serviceKey, attr.Token, nonEmptyValue), - acctests.WaitTestFunc(), - ), - }, + t.Parallel() + + serviceAccountName := test.RandomName() + terraformResourceName := test.TerraformRandName("test_key") + serviceAccount := acctests.TerraformServiceAccount(terraformResourceName) + serviceKey := acctests.TerraformServiceKey(terraformResourceName) + beforeName := test.RandomName() + afterName := test.RandomName() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, + Steps: []sdk.TestStep{ + { + Config: createServiceKeyWithName(terraformResourceName, serviceAccountName, beforeName), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(serviceAccount), + sdk.TestCheckResourceAttr(serviceAccount, attr.Name, serviceAccountName), + acctests.CheckTwingateResourceExists(serviceKey), + sdk.TestCheckResourceAttr(serviceKey, attr.Name, beforeName), + sdk.TestCheckResourceAttrWith(serviceKey, attr.Token, nonEmptyValue), + ), + }, + { + Config: createServiceKeyWithName(terraformResourceName, serviceAccountName, afterName), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(serviceAccount), + sdk.TestCheckResourceAttr(serviceAccount, attr.Name, serviceAccountName), + acctests.CheckTwingateResourceExists(serviceKey), + sdk.TestCheckResourceAttr(serviceKey, attr.Name, afterName), + sdk.TestCheckResourceAttrWith(serviceKey, attr.Token, nonEmptyValue), + acctests.WaitTestFunc(), + ), }, - }) + }, }) } func TestAccTwingateServiceKeyWontReCreateAfterInactive(t *testing.T) { - t.Run("Test Twingate Resource : Acc Service Key Won't ReCreate After Inactive", func(t *testing.T) { - serviceAccountName := test.RandomName() - terraformResourceName := test.TerraformRandName("test_key") - serviceKey := acctests.TerraformServiceKey(terraformResourceName) - - resourceID := new(string) - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, - Steps: []sdk.TestStep{ - { - Config: createServiceKey(terraformResourceName, serviceAccountName), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(serviceKey), - acctests.GetTwingateResourceID(serviceKey, &resourceID), - sdk.TestCheckResourceAttrWith(serviceKey, attr.Token, nonEmptyValue), - acctests.RevokeTwingateServiceKey(serviceKey), - acctests.WaitTestFunc(), - acctests.CheckTwingateServiceKeyStatus(serviceKey, model.StatusRevoked), - ), - }, - { - Config: createServiceKey(terraformResourceName, serviceAccountName), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(serviceKey), - sdk.TestCheckResourceAttr(serviceKey, attr.IsActive, "false"), - sdk.TestCheckResourceAttrWith(serviceKey, attr.Token, nonEmptyValue), - sdk.TestCheckResourceAttrWith(serviceKey, attr.ID, func(value string) error { - if *resourceID == "" { - return errors.New("failed to fetch resource id") - } - - if value != *resourceID { - return errors.New("resource was re-created") - } - - return nil - }), - ), - }, + t.Parallel() + + serviceAccountName := test.RandomName() + terraformResourceName := test.TerraformRandName("test_key") + serviceKey := acctests.TerraformServiceKey(terraformResourceName) + + resourceID := new(string) + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, + Steps: []sdk.TestStep{ + { + Config: createServiceKey(terraformResourceName, serviceAccountName), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(serviceKey), + acctests.GetTwingateResourceID(serviceKey, &resourceID), + sdk.TestCheckResourceAttrWith(serviceKey, attr.Token, nonEmptyValue), + acctests.RevokeTwingateServiceKey(serviceKey), + acctests.WaitTestFunc(), + acctests.CheckTwingateServiceKeyStatus(serviceKey, model.StatusRevoked), + ), + }, + { + Config: createServiceKey(terraformResourceName, serviceAccountName), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(serviceKey), + sdk.TestCheckResourceAttr(serviceKey, attr.IsActive, "false"), + sdk.TestCheckResourceAttrWith(serviceKey, attr.Token, nonEmptyValue), + sdk.TestCheckResourceAttrWith(serviceKey, attr.ID, func(value string) error { + if *resourceID == "" { + return errors.New("failed to fetch resource id") + } + + if value != *resourceID { + return errors.New("resource was re-created") + } + + return nil + }), + ), }, - }) + }, }) } func TestAccTwingateServiceKeyDelete(t *testing.T) { - t.Run("Test Twingate Resource : Acc Service Key Delete", func(t *testing.T) { - serviceAccountName := test.RandomName() - terraformResourceName := test.TerraformRandName("test_key") - serviceKey := acctests.TerraformServiceKey(terraformResourceName) - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, - Steps: []sdk.TestStep{ - { - Config: createServiceKey(terraformResourceName, serviceAccountName), - Destroy: true, - }, - { - Config: createServiceKey(terraformResourceName, serviceAccountName), - ConfigPlanChecks: sdk.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(serviceKey, plancheck.ResourceActionCreate), - }, + t.Parallel() + + serviceAccountName := test.RandomName() + terraformResourceName := test.TerraformRandName("test_key") + serviceKey := acctests.TerraformServiceKey(terraformResourceName) + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, + Steps: []sdk.TestStep{ + { + Config: createServiceKey(terraformResourceName, serviceAccountName), + Destroy: true, + }, + { + Config: createServiceKey(terraformResourceName, serviceAccountName), + ConfigPlanChecks: sdk.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(serviceKey, plancheck.ResourceActionCreate), }, }, }, - }) + }, }) } func TestAccTwingateServiceKeyReCreateAfterDeletion(t *testing.T) { - t.Run("Test Twingate Resource : Acc Service Key ReCreate After Delete", func(t *testing.T) { - serviceAccountName := test.RandomName() - terraformResourceName := test.TerraformRandName("test_key") - serviceKey := acctests.TerraformServiceKey(terraformResourceName) - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, - Steps: []sdk.TestStep{ - { - Config: createServiceKey(terraformResourceName, serviceAccountName), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(serviceKey), - acctests.RevokeTwingateServiceKey(serviceKey), - acctests.DeleteTwingateResource(serviceKey, resource.TwingateServiceAccountKey), - ), - ExpectNonEmptyPlan: true, - }, - { - Config: createServiceKey(terraformResourceName, serviceAccountName), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(serviceKey), - sdk.TestCheckResourceAttrWith(serviceKey, attr.Token, nonEmptyValue), - ), - }, + t.Parallel() + + serviceAccountName := test.RandomName() + terraformResourceName := test.TerraformRandName("test_key") + serviceKey := acctests.TerraformServiceKey(terraformResourceName) + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, + Steps: []sdk.TestStep{ + { + Config: createServiceKey(terraformResourceName, serviceAccountName), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(serviceKey), + acctests.RevokeTwingateServiceKey(serviceKey), + acctests.DeleteTwingateResource(serviceKey, resource.TwingateServiceAccountKey), + ), + ExpectNonEmptyPlan: true, + }, + { + Config: createServiceKey(terraformResourceName, serviceAccountName), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(serviceKey), + sdk.TestCheckResourceAttrWith(serviceKey, attr.Token, nonEmptyValue), + ), }, - }) + }, }) } func TestAccTwingateServiceKeyCreateWithInvalidExpiration(t *testing.T) { - t.Run("Test Twingate Resource : Acc Service Key Create With Invalid Expiration", func(t *testing.T) { - serviceAccountName := test.RandomName() - terraformResourceName := test.TerraformRandName("test_key") - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, - Steps: []sdk.TestStep{ - { - Config: createServiceKeyWithExpiration(terraformResourceName, serviceAccountName, -1), - ExpectError: regexp.MustCompile(resource.ErrInvalidExpirationTime.Error()), - }, - { - Config: createServiceKeyWithExpiration(terraformResourceName, serviceAccountName, 366), - ExpectError: regexp.MustCompile(resource.ErrInvalidExpirationTime.Error()), - }, + t.Parallel() + + serviceAccountName := test.RandomName() + terraformResourceName := test.TerraformRandName("test_key") + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, + Steps: []sdk.TestStep{ + { + Config: createServiceKeyWithExpiration(terraformResourceName, serviceAccountName, -1), + ExpectError: regexp.MustCompile(resource.ErrInvalidExpirationTime.Error()), + }, + { + Config: createServiceKeyWithExpiration(terraformResourceName, serviceAccountName, 366), + ExpectError: regexp.MustCompile(resource.ErrInvalidExpirationTime.Error()), }, - }) + }, }) } func TestAccTwingateServiceKeyCreateWithExpiration(t *testing.T) { - t.Run("Test Twingate Resource : Acc Service Key Create With Expiration", func(t *testing.T) { - serviceAccountName := test.RandomName() - terraformResourceName := test.TerraformRandName("test_key") - serviceAccount := acctests.TerraformServiceAccount(terraformResourceName) - serviceKey := acctests.TerraformServiceKey(terraformResourceName) - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, - Steps: []sdk.TestStep{ - { - Config: createServiceKeyWithExpiration(terraformResourceName, serviceAccountName, 365), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(serviceAccount), - sdk.TestCheckResourceAttr(serviceAccount, attr.Name, serviceAccountName), - acctests.CheckTwingateResourceExists(serviceKey), - sdk.TestCheckResourceAttr(serviceKey, attr.IsActive, "true"), - sdk.TestCheckResourceAttrWith(serviceKey, attr.Token, nonEmptyValue), - ), - }, + t.Parallel() + + serviceAccountName := test.RandomName() + terraformResourceName := test.TerraformRandName("test_key") + serviceAccount := acctests.TerraformServiceAccount(terraformResourceName) + serviceKey := acctests.TerraformServiceKey(terraformResourceName) + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, + Steps: []sdk.TestStep{ + { + Config: createServiceKeyWithExpiration(terraformResourceName, serviceAccountName, 365), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(serviceAccount), + sdk.TestCheckResourceAttr(serviceAccount, attr.Name, serviceAccountName), + acctests.CheckTwingateResourceExists(serviceKey), + sdk.TestCheckResourceAttr(serviceKey, attr.IsActive, "true"), + sdk.TestCheckResourceAttrWith(serviceKey, attr.Token, nonEmptyValue), + ), }, - }) + }, }) } func TestAccTwingateServiceKeyReCreateAfterChangingExpirationTime(t *testing.T) { - t.Run("Test Twingate Resource : Acc Service Key ReCreate After Changing Expiration Time", func(t *testing.T) { - serviceAccountName := test.RandomName() - terraformResourceName := test.TerraformRandName("test_key") - serviceKey := acctests.TerraformServiceKey(terraformResourceName) - - resourceID := new(string) - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, - Steps: []sdk.TestStep{ - { - Config: createServiceKeyWithExpiration(terraformResourceName, serviceAccountName, 1), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(serviceKey), - acctests.GetTwingateResourceID(serviceKey, &resourceID), - sdk.TestCheckResourceAttrWith(serviceKey, attr.Token, nonEmptyValue), - ), - }, - { - Config: createServiceKeyWithExpiration(terraformResourceName, serviceAccountName, 2), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(serviceKey), - sdk.TestCheckResourceAttrWith(serviceKey, attr.ID, func(value string) error { - if *resourceID == "" { - return errors.New("failed to fetch resource id") - } - - if value == *resourceID { - return errors.New("resource was not re-created") - } - - return nil - }), - ), - }, + t.Parallel() + + serviceAccountName := test.RandomName() + terraformResourceName := test.TerraformRandName("test_key") + serviceKey := acctests.TerraformServiceKey(terraformResourceName) + + resourceID := new(string) + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, + Steps: []sdk.TestStep{ + { + Config: createServiceKeyWithExpiration(terraformResourceName, serviceAccountName, 1), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(serviceKey), + acctests.GetTwingateResourceID(serviceKey, &resourceID), + sdk.TestCheckResourceAttrWith(serviceKey, attr.Token, nonEmptyValue), + ), + }, + { + Config: createServiceKeyWithExpiration(terraformResourceName, serviceAccountName, 2), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(serviceKey), + sdk.TestCheckResourceAttrWith(serviceKey, attr.ID, func(value string) error { + if *resourceID == "" { + return errors.New("failed to fetch resource id") + } + + if value == *resourceID { + return errors.New("resource was not re-created") + } + + return nil + }), + ), }, - }) + }, }) } func TestAccTwingateServiceKeyAndServiceAccountLifecycle(t *testing.T) { - t.Run("Test Twingate Resource : Acc Service Key and Service Account Lifecycle", func(t *testing.T) { - serviceAccountName := test.RandomName() - serviceAccountNameV2 := test.RandomName() - terraformServiceAccountName := test.TerraformRandName("test_acc") - terraformServiceAccountNameV2 := test.TerraformRandName("test_acc_v2") - terraformServiceAccountKeyName := test.TerraformRandName("test_key") - serviceAccount := acctests.TerraformServiceAccount(terraformServiceAccountName) - serviceAccountV2 := acctests.TerraformServiceAccount(terraformServiceAccountNameV2) - serviceKey := acctests.TerraformServiceKey(terraformServiceAccountKeyName) - - serviceKeyResourceID := new(string) - serviceAccountResourceID := new(string) - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, - Steps: []sdk.TestStep{ - { - Config: createServiceKeyV1(terraformServiceAccountName, serviceAccountName, terraformServiceAccountNameV2, serviceAccountNameV2, terraformServiceAccountKeyName, terraformServiceAccountName), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(serviceAccount), - sdk.TestCheckResourceAttr(serviceAccount, attr.Name, serviceAccountName), - acctests.CheckTwingateResourceExists(serviceKey), - sdk.TestCheckResourceAttrWith(serviceKey, attr.Token, nonEmptyValue), - acctests.GetTwingateResourceID(serviceKey, &serviceKeyResourceID), - acctests.GetTwingateResourceID(serviceKey, &serviceAccountResourceID), - ), - }, - { - Config: createServiceKeyV1(terraformServiceAccountName, serviceAccountName, terraformServiceAccountNameV2, serviceAccountNameV2, terraformServiceAccountKeyName, terraformServiceAccountNameV2), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(serviceAccountV2), - sdk.TestCheckResourceAttr(serviceAccountV2, attr.Name, serviceAccountNameV2), - acctests.CheckTwingateResourceExists(serviceKey), - sdk.TestCheckResourceAttrWith(serviceKey, attr.Token, nonEmptyValue), - - // test resources were re-created - sdk.TestCheckResourceAttrWith(serviceKey, attr.ID, func(value string) error { - if *serviceKeyResourceID == "" { - return errors.New("failed to fetch service_key resource id") - } - - if value == *serviceKeyResourceID { - return errors.New("service_key resource was not re-created") - } - - return nil - }), - - sdk.TestCheckResourceAttrWith(serviceAccountV2, attr.ID, func(value string) error { - if *serviceAccountResourceID == "" { - return errors.New("failed to fetch service_account resource id") - } - - if value == *serviceAccountResourceID { - return errors.New("service_account resource was not re-created") - } - - return nil - }), - ), - }, + t.Parallel() + + serviceAccountName := test.RandomName() + serviceAccountNameV2 := test.RandomName() + terraformServiceAccountName := test.TerraformRandName("test_acc") + terraformServiceAccountNameV2 := test.TerraformRandName("test_acc_v2") + terraformServiceAccountKeyName := test.TerraformRandName("test_key") + serviceAccount := acctests.TerraformServiceAccount(terraformServiceAccountName) + serviceAccountV2 := acctests.TerraformServiceAccount(terraformServiceAccountNameV2) + serviceKey := acctests.TerraformServiceKey(terraformServiceAccountKeyName) + + serviceKeyResourceID := new(string) + serviceAccountResourceID := new(string) + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateServiceAccountDestroy, + Steps: []sdk.TestStep{ + { + Config: createServiceKeyV1(terraformServiceAccountName, serviceAccountName, terraformServiceAccountNameV2, serviceAccountNameV2, terraformServiceAccountKeyName, terraformServiceAccountName), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(serviceAccount), + sdk.TestCheckResourceAttr(serviceAccount, attr.Name, serviceAccountName), + acctests.CheckTwingateResourceExists(serviceKey), + sdk.TestCheckResourceAttrWith(serviceKey, attr.Token, nonEmptyValue), + acctests.GetTwingateResourceID(serviceKey, &serviceKeyResourceID), + acctests.GetTwingateResourceID(serviceKey, &serviceAccountResourceID), + ), + }, + { + Config: createServiceKeyV1(terraformServiceAccountName, serviceAccountName, terraformServiceAccountNameV2, serviceAccountNameV2, terraformServiceAccountKeyName, terraformServiceAccountNameV2), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(serviceAccountV2), + sdk.TestCheckResourceAttr(serviceAccountV2, attr.Name, serviceAccountNameV2), + acctests.CheckTwingateResourceExists(serviceKey), + sdk.TestCheckResourceAttrWith(serviceKey, attr.Token, nonEmptyValue), + + // test resources were re-created + sdk.TestCheckResourceAttrWith(serviceKey, attr.ID, func(value string) error { + if *serviceKeyResourceID == "" { + return errors.New("failed to fetch service_key resource id") + } + + if value == *serviceKeyResourceID { + return errors.New("service_key resource was not re-created") + } + + return nil + }), + + sdk.TestCheckResourceAttrWith(serviceAccountV2, attr.ID, func(value string) error { + if *serviceAccountResourceID == "" { + return errors.New("failed to fetch service_account resource id") + } + + if value == *serviceAccountResourceID { + return errors.New("service_account resource was not re-created") + } + + return nil + }), + ), }, - }) + }, }) } diff --git a/twingate/internal/test/acctests/resource/user_test.go b/twingate/internal/test/acctests/resource/user_test.go index 46864d47..74f1ee42 100644 --- a/twingate/internal/test/acctests/resource/user_test.go +++ b/twingate/internal/test/acctests/resource/user_test.go @@ -15,55 +15,55 @@ import ( ) func TestAccTwingateUserCreateUpdate(t *testing.T) { - t.Run("Test Twingate Resource : Acc User Create/Update", func(t *testing.T) { - const terraformResourceName = "test001" - theResource := acctests.TerraformUser(terraformResourceName) - email := test.RandomEmail() - firstName := test.RandomName() - lastName := test.RandomName() - role := model.UserRoleSupport - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateUserDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceTwingateUser(terraformResourceName, email), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - sdk.TestCheckResourceAttr(theResource, attr.Email, email), - ), - }, - { - Config: terraformResourceTwingateUserWithFirstName(terraformResourceName, email, firstName), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - sdk.TestCheckResourceAttr(theResource, attr.Email, email), - sdk.TestCheckResourceAttr(theResource, attr.FirstName, firstName), - ), - }, - { - Config: terraformResourceTwingateUserWithLastName(terraformResourceName, email, lastName), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - sdk.TestCheckResourceAttr(theResource, attr.Email, email), - sdk.TestCheckResourceAttr(theResource, attr.FirstName, firstName), - sdk.TestCheckResourceAttr(theResource, attr.LastName, lastName), - ), - }, - { - Config: terraformResourceTwingateUserWithRole(terraformResourceName, email, role), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - sdk.TestCheckResourceAttr(theResource, attr.Email, email), - sdk.TestCheckResourceAttr(theResource, attr.FirstName, firstName), - sdk.TestCheckResourceAttr(theResource, attr.LastName, lastName), - sdk.TestCheckResourceAttr(theResource, attr.Role, role), - ), - }, + t.Parallel() + + const terraformResourceName = "test001" + theResource := acctests.TerraformUser(terraformResourceName) + email := test.RandomEmail() + firstName := test.RandomName() + lastName := test.RandomName() + role := model.UserRoleSupport + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateUserDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceTwingateUser(terraformResourceName, email), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + sdk.TestCheckResourceAttr(theResource, attr.Email, email), + ), + }, + { + Config: terraformResourceTwingateUserWithFirstName(terraformResourceName, email, firstName), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + sdk.TestCheckResourceAttr(theResource, attr.Email, email), + sdk.TestCheckResourceAttr(theResource, attr.FirstName, firstName), + ), + }, + { + Config: terraformResourceTwingateUserWithLastName(terraformResourceName, email, lastName), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + sdk.TestCheckResourceAttr(theResource, attr.Email, email), + sdk.TestCheckResourceAttr(theResource, attr.FirstName, firstName), + sdk.TestCheckResourceAttr(theResource, attr.LastName, lastName), + ), }, - }) + { + Config: terraformResourceTwingateUserWithRole(terraformResourceName, email, role), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + sdk.TestCheckResourceAttr(theResource, attr.Email, email), + sdk.TestCheckResourceAttr(theResource, attr.FirstName, firstName), + sdk.TestCheckResourceAttr(theResource, attr.LastName, lastName), + sdk.TestCheckResourceAttr(theResource, attr.Role, role), + ), + }, + }, }) } @@ -107,31 +107,31 @@ func terraformResourceTwingateUserWithRole(terraformResourceName, email, role st } func TestAccTwingateUserFullCreate(t *testing.T) { - t.Run("Test Twingate Resource : Acc User Full Create", func(t *testing.T) { - const terraformResourceName = "test002" - theResource := acctests.TerraformUser(terraformResourceName) - email := test.RandomEmail() - firstName := test.RandomName() - lastName := test.RandomName() - role := test.RandomUserRole() - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateUserDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceTwingateUserFull(terraformResourceName, email, firstName, lastName, role), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - sdk.TestCheckResourceAttr(theResource, attr.Email, email), - sdk.TestCheckResourceAttr(theResource, attr.FirstName, firstName), - sdk.TestCheckResourceAttr(theResource, attr.LastName, lastName), - sdk.TestCheckResourceAttr(theResource, attr.Role, role), - ), - }, + t.Parallel() + + const terraformResourceName = "test002" + theResource := acctests.TerraformUser(terraformResourceName) + email := test.RandomEmail() + firstName := test.RandomName() + lastName := test.RandomName() + role := test.RandomUserRole() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateUserDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceTwingateUserFull(terraformResourceName, email, firstName, lastName, role), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + sdk.TestCheckResourceAttr(theResource, attr.Email, email), + sdk.TestCheckResourceAttr(theResource, attr.FirstName, firstName), + sdk.TestCheckResourceAttr(theResource, attr.LastName, lastName), + sdk.TestCheckResourceAttr(theResource, attr.Role, role), + ), }, - }) + }, }) } @@ -148,60 +148,60 @@ func terraformResourceTwingateUserFull(terraformResourceName, email, firstName, } func TestAccTwingateUserReCreation(t *testing.T) { - t.Run("Test Twingate Resource : Acc User ReCreation", func(t *testing.T) { - const terraformResourceName = "test003" - theResource := acctests.TerraformUser(terraformResourceName) - email1 := test.RandomEmail() - email2 := test.RandomEmail() - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateUserDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceTwingateUser(terraformResourceName, email1), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - sdk.TestCheckResourceAttr(theResource, attr.Email, email1), - ), - }, - { - Config: terraformResourceTwingateUser(terraformResourceName, email2), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - sdk.TestCheckResourceAttr(theResource, attr.Email, email2), - ), - }, + t.Parallel() + + const terraformResourceName = "test003" + theResource := acctests.TerraformUser(terraformResourceName) + email1 := test.RandomEmail() + email2 := test.RandomEmail() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateUserDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceTwingateUser(terraformResourceName, email1), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + sdk.TestCheckResourceAttr(theResource, attr.Email, email1), + ), + }, + { + Config: terraformResourceTwingateUser(terraformResourceName, email2), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + sdk.TestCheckResourceAttr(theResource, attr.Email, email2), + ), }, - }) + }, }) } func TestAccTwingateUserUpdateState(t *testing.T) { - t.Run("Test Twingate Resource : Acc User Update State", func(t *testing.T) { - const terraformResourceName = "test004" - theResource := acctests.TerraformUser(terraformResourceName) - email := test.RandomEmail() - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateUserDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceTwingateUser(terraformResourceName, email), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - sdk.TestCheckResourceAttr(theResource, attr.Email, email), - ), - }, - { - Config: terraformResourceTwingateUserDisabled(terraformResourceName, email), - ExpectError: regexp.MustCompile(`User in PENDING state`), - }, + t.Parallel() + + const terraformResourceName = "test004" + theResource := acctests.TerraformUser(terraformResourceName) + email := test.RandomEmail() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateUserDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceTwingateUser(terraformResourceName, email), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + sdk.TestCheckResourceAttr(theResource, attr.Email, email), + ), + }, + { + Config: terraformResourceTwingateUserDisabled(terraformResourceName, email), + ExpectError: regexp.MustCompile(`User in PENDING state`), }, - }) + }, }) } @@ -216,96 +216,96 @@ func terraformResourceTwingateUserDisabled(terraformResourceName, email string) } func TestAccTwingateUserDelete(t *testing.T) { - t.Run("Test Twingate Resource : Acc User Delete", func(t *testing.T) { - const terraformResourceName = "test005" - theResource := acctests.TerraformUser(terraformResourceName) - userEmail := test.RandomEmail() - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateUserDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceTwingateUser(terraformResourceName, userEmail), - Destroy: true, - }, - { - Config: terraformResourceTwingateUser(terraformResourceName, userEmail), - ConfigPlanChecks: sdk.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(theResource, plancheck.ResourceActionCreate), - }, + t.Parallel() + + const terraformResourceName = "test005" + theResource := acctests.TerraformUser(terraformResourceName) + userEmail := test.RandomEmail() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateUserDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceTwingateUser(terraformResourceName, userEmail), + Destroy: true, + }, + { + Config: terraformResourceTwingateUser(terraformResourceName, userEmail), + ConfigPlanChecks: sdk.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(theResource, plancheck.ResourceActionCreate), }, }, }, - }) + }, }) } func TestAccTwingateUserReCreateAfterDeletion(t *testing.T) { - t.Run("Test Twingate Resource : Acc User Create After Deletion", func(t *testing.T) { - const terraformResourceName = "test006" - theResource := acctests.TerraformUser(terraformResourceName) - email := test.RandomEmail() - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateUserDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceTwingateUser(terraformResourceName, email), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - acctests.DeleteTwingateResource(theResource, resource.TwingateUser), - ), - ExpectNonEmptyPlan: true, - }, - { - Config: terraformResourceTwingateUser(terraformResourceName, email), - Check: acctests.ComposeTestCheckFunc( - acctests.CheckTwingateResourceExists(theResource), - ), - }, + t.Parallel() + + const terraformResourceName = "test006" + theResource := acctests.TerraformUser(terraformResourceName) + email := test.RandomEmail() + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateUserDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceTwingateUser(terraformResourceName, email), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + acctests.DeleteTwingateResource(theResource, resource.TwingateUser), + ), + ExpectNonEmptyPlan: true, + }, + { + Config: terraformResourceTwingateUser(terraformResourceName, email), + Check: acctests.ComposeTestCheckFunc( + acctests.CheckTwingateResourceExists(theResource), + ), }, - }) + }, }) } func TestAccTwingateUserCreateWithUnknownRole(t *testing.T) { - t.Run("Test Twingate Resource : Acc User Create With Unknown Role", func(t *testing.T) { - const terraformResourceName = "test007" - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateUserDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceTwingateUserWithRole(terraformResourceName, test.RandomEmail(), "UnknownRole"), - ExpectError: regexp.MustCompile(`Attribute role value must be one of`), - }, + t.Parallel() + + const terraformResourceName = "test007" + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateUserDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceTwingateUserWithRole(terraformResourceName, test.RandomEmail(), "UnknownRole"), + ExpectError: regexp.MustCompile(`Attribute role value must be one of`), }, - }) + }, }) } func TestAccTwingateUserCreateWithoutEmail(t *testing.T) { - t.Run("Test Twingate Resource : Acc User Create Without Email", func(t *testing.T) { - const terraformResourceName = "test008" - - sdk.Test(t, sdk.TestCase{ - ProtoV6ProviderFactories: acctests.ProviderFactories, - PreCheck: func() { acctests.PreCheck(t) }, - CheckDestroy: acctests.CheckTwingateUserDestroy, - Steps: []sdk.TestStep{ - { - Config: terraformResourceTwingateUserWithoutEmail(terraformResourceName), - ExpectError: regexp.MustCompile("Error: Missing required argument"), - }, + t.Parallel() + + const terraformResourceName = "test008" + + sdk.Test(t, sdk.TestCase{ + ProtoV6ProviderFactories: acctests.ProviderFactories, + PreCheck: func() { acctests.PreCheck(t) }, + CheckDestroy: acctests.CheckTwingateUserDestroy, + Steps: []sdk.TestStep{ + { + Config: terraformResourceTwingateUserWithoutEmail(terraformResourceName), + ExpectError: regexp.MustCompile("Error: Missing required argument"), }, - }) + }, }) }