Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vmanilo committed Dec 14, 2023
1 parent 3fcbb68 commit 1061a10
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 48 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
pull_request:
branches:
- main
- fix/acctests-upgrade-tf-plugin-testing
paths-ignore:
- 'README.md'

Expand All @@ -15,6 +16,7 @@ on:
- 'README.md'
branches:
- main
- fix/acctests-upgrade-tf-plugin-testing

# Ensures only 1 action runs per PR and previous is canceled on new trigger
concurrency:
Expand Down Expand Up @@ -118,7 +120,7 @@ jobs:
name: Matrix Acceptance Tests
needs: build
runs-on: ubuntu-latest
if: "!github.event.pull_request.head.repo.fork"
# if: "!github.event.pull_request.head.repo.fork"
timeout-minutes: 15
strategy:
fail-fast: false
Expand Down Expand Up @@ -169,7 +171,7 @@ jobs:

cleanup:
name: Cleanup
if: "!github.event.pull_request.head.repo.fork"
# if: "!github.event.pull_request.head.repo.fork"
needs: tests-acceptance
runs-on: ubuntu-latest
timeout-minutes: 15
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/hashicorp/terraform-plugin-go v0.19.1
github.com/hashicorp/terraform-plugin-mux v0.12.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.30.0
github.com/hashicorp/terraform-plugin-testing v1.5.1
github.com/hashicorp/terraform-plugin-testing v1.6.0
github.com/hasura/go-graphql-client v0.10.1
github.com/iancoleman/strcase v0.3.0
github.com/jarcoal/httpmock v1.3.1
Expand Down Expand Up @@ -55,7 +55,7 @@ require (
github.com/hashicorp/hcl/v2 v2.19.1 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-exec v0.19.0 // indirect
github.com/hashicorp/terraform-json v0.17.1 // indirect
github.com/hashicorp/terraform-json v0.18.0 // indirect
github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect
github.com/hashicorp/terraform-registry-address v0.2.3 // indirect
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
Expand All @@ -82,13 +82,13 @@ require (
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
github.com/zclconf/go-cty v1.14.1 // indirect
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/term v0.14.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.14.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
github.com/hashicorp/terraform-exec v0.19.0 h1:FpqZ6n50Tk95mItTSS9BjeOVUb4eg81SpgVtZNNtFSM=
github.com/hashicorp/terraform-exec v0.19.0/go.mod h1:tbxUpe3JKruE9Cuf65mycSIT8KiNPZ0FkuTE3H4urQg=
github.com/hashicorp/terraform-json v0.17.1 h1:eMfvh/uWggKmY7Pmb3T85u86E2EQg6EQHgyRwf3RkyA=
github.com/hashicorp/terraform-json v0.17.1/go.mod h1:Huy6zt6euxaY9knPAFKjUITn8QxUFIe9VuSzb4zn/0o=
github.com/hashicorp/terraform-json v0.18.0 h1:pCjgJEqqDESv4y0Tzdqfxr/edOIGkjs8keY42xfNBwU=
github.com/hashicorp/terraform-json v0.18.0/go.mod h1:qdeBs11ovMzo5puhrRibdD6d2Dq6TyE/28JiU4tIQxk=
github.com/hashicorp/terraform-plugin-docs v0.16.0 h1:UmxFr3AScl6Wged84jndJIfFccGyBZn52KtMNsS12dI=
github.com/hashicorp/terraform-plugin-docs v0.16.0/go.mod h1:M3ZrlKBJAbPMtNOPwHicGi1c+hZUh7/g0ifT/z7TVfA=
github.com/hashicorp/terraform-plugin-framework v1.4.2 h1:P7a7VP1GZbjc4rv921Xy5OckzhoiO3ig6SGxwelD2sI=
Expand All @@ -162,8 +162,8 @@ github.com/hashicorp/terraform-plugin-mux v0.12.0 h1:TJlmeslQ11WlQtIFAfth0vXx+gS
github.com/hashicorp/terraform-plugin-mux v0.12.0/go.mod h1:8MR0AgmV+Q03DIjyrAKxXyYlq2EUnYBQP8gxAAA0zeM=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.30.0 h1:X7vB6vn5tON2b49ILa4W7mFAsndeqJ7bZFOGbVO+0Cc=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.30.0/go.mod h1:ydFcxbdj6klCqYEPkPvdvFKiNGKZLUs+896ODUXCyao=
github.com/hashicorp/terraform-plugin-testing v1.5.1 h1:T4aQh9JAhmWo4+t1A7x+rnxAJHCDIYW9kXyo4sVO92c=
github.com/hashicorp/terraform-plugin-testing v1.5.1/go.mod h1:dg8clO6K59rZ8w9EshBmDp1CxTIPu3yA4iaDpX1h5u0=
github.com/hashicorp/terraform-plugin-testing v1.6.0 h1:Wsnfh+7XSVRfwcr2jZYHsnLOnZl7UeaOBvsx6dl/608=
github.com/hashicorp/terraform-plugin-testing v1.6.0/go.mod h1:cJGG0/8j9XhHaJZRC+0sXFI4uzqQZ9Az4vh6C4GJpFE=
github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI=
github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM=
github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ=
Expand Down Expand Up @@ -305,8 +305,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA=
golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g=
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 h1:EDuYyU/MkFXllv9QF9819VlI9a4tzGuCbhG0ExK9o1U=
golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
Expand Down Expand Up @@ -361,8 +361,8 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
Expand All @@ -371,8 +371,8 @@ golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o=
golang.org/x/term v0.14.0 h1:LGK9IlZ8T9jvdy6cTdfKUCltatMFOehAQo9SRC46UQ8=
golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestAccDatasourceTwingateRemoteNetwork_basic(t *testing.T) {
Check: acctests.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.twingate_remote_network.test_dn1_2", attr.Name, networkName),
),
ExpectNonEmptyPlan: true,
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func TestAccDatasourceTwingateServicesAll(t *testing.T) {
Check: acctests.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(theDatasource, attr.ID, "all-services"),
),
ExpectNonEmptyPlan: true,
},
{
Config: filterDatasourceServices(prefix, config),
Expand Down
12 changes: 9 additions & 3 deletions twingate/internal/test/acctests/resource/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/Twingate/terraform-provider-twingate/twingate/internal/test"
"github.com/Twingate/terraform-provider-twingate/twingate/internal/test/acctests"
sdk "github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
)

var (
Expand Down Expand Up @@ -69,9 +70,14 @@ func TestAccTwingateGroupDeleteNonExisting(t *testing.T) {
{
Config: terraformResourceTwingateGroup(terraformResourceName, groupName),
Destroy: true,
Check: acctests.ComposeTestCheckFunc(
acctests.CheckTwingateResourceDoesNotExists(theResource),
),
},
{
Config: terraformResourceTwingateGroup(terraformResourceName, groupName),
ConfigPlanChecks: sdk.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction(theResource, plancheck.ResourceActionCreate),
},
},
},
},
})
Expand Down
16 changes: 11 additions & 5 deletions twingate/internal/test/acctests/resource/remote-network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/Twingate/terraform-provider-twingate/twingate/internal/test"
"github.com/Twingate/terraform-provider-twingate/twingate/internal/test/acctests"
sdk "github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
)

func TestAccTwingateRemoteNetworkCreate(t *testing.T) {
Expand Down Expand Up @@ -91,19 +92,24 @@ 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)
remoteNetworkNameBefore := test.RandomName()
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, remoteNetworkNameBefore),
Config: terraformResourceRemoteNetwork(terraformResourceName, networkName),
Destroy: true,
Check: acctests.ComposeTestCheckFunc(
acctests.CheckTwingateResourceDoesNotExists(theResource),
),
},
{
Config: terraformResourceRemoteNetwork(terraformResourceName, networkName),
ConfigPlanChecks: sdk.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction(theResource, plancheck.ResourceActionCreate),
},
},
},
},
})
Expand Down
19 changes: 6 additions & 13 deletions twingate/internal/test/acctests/resource/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1596,9 +1596,7 @@ func TestAccTwingateCreateResourceWithFlagIsVisible(t *testing.T) {
),
},
{
// expecting no changes - default value on the backend side is `true`
PlanOnly: true,
Config: createResourceWithFlagIsVisible(terraformResourceName, remoteNetworkName, resourceName, true),
Config: createResourceWithFlagIsVisible(terraformResourceName, remoteNetworkName, resourceName, true),
Check: acctests.ComposeTestCheckFunc(
sdk.TestCheckResourceAttr(theResource, attr.IsVisible, "true"),
),
Expand Down Expand Up @@ -1675,9 +1673,7 @@ func TestAccTwingateCreateResourceWithFlagIsBrowserShortcutEnabled(t *testing.T)
),
},
{
// expecting no changes - default value on the backend side is `true`
PlanOnly: true,
Config: createResourceWithFlagIsBrowserShortcutEnabled(terraformResourceName, remoteNetworkName, resourceName, true),
Config: createResourceWithFlagIsBrowserShortcutEnabled(terraformResourceName, remoteNetworkName, resourceName, true),
Check: acctests.ComposeTestCheckFunc(
sdk.TestCheckResourceAttr(theResource, attr.IsBrowserShortcutEnabled, "true"),
),
Expand Down Expand Up @@ -2780,17 +2776,14 @@ func TestAccTwingateResourceTestPlanOnDisabledResource(t *testing.T) {
Steps: []sdk.TestStep{
{
Config: createResource(remoteNetworkName, resourceName),
},
{
RefreshState: true,
Check: acctests.ComposeTestCheckFunc(
acctests.CheckTwingateResourceActiveState(theResource, true),
acctests.DeactivateTwingateResource(theResource),
acctests.CheckTwingateResourceActiveState(theResource, false),
),
},
{
Config: createResource(remoteNetworkName, resourceName),
ExpectNonEmptyPlan: true,
ConfigPlanChecks: sdk.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
PostApplyPostRefresh: []plancheck.PlanCheck{
plancheck.ExpectNonEmptyPlan(),
plancheck.ExpectResourceAction(theResource, plancheck.ResourceActionUpdate),
acctests.CheckResourceActiveState(theResource, false),
Expand Down
12 changes: 9 additions & 3 deletions twingate/internal/test/acctests/resource/service-account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/Twingate/terraform-provider-twingate/twingate/internal/test"
"github.com/Twingate/terraform-provider-twingate/twingate/internal/test/acctests"
sdk "github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
)

func createServiceAccount(resourceName, serviceAccountName string) string {
Expand Down Expand Up @@ -64,9 +65,14 @@ func TestAccTwingateServiceAccountDeleteNonExisting(t *testing.T) {
{
Config: createServiceAccount(terraformResourceName, name),
Destroy: true,
Check: acctests.ComposeTestCheckFunc(
acctests.CheckTwingateResourceDoesNotExists(theResource),
),
},
{
Config: createServiceAccount(terraformResourceName, name),
ConfigPlanChecks: sdk.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction(theResource, plancheck.ResourceActionCreate),
},
},
},
},
})
Expand Down
12 changes: 9 additions & 3 deletions twingate/internal/test/acctests/resource/service-key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/Twingate/terraform-provider-twingate/twingate/internal/test"
"github.com/Twingate/terraform-provider-twingate/twingate/internal/test/acctests"
sdk "github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
)

var ErrEmptyValue = errors.New("empty value")
Expand Down Expand Up @@ -193,9 +194,14 @@ func TestAccTwingateServiceKeyDelete(t *testing.T) {
{
Config: createServiceKey(terraformResourceName, serviceAccountName),
Destroy: true,
Check: acctests.ComposeTestCheckFunc(
acctests.CheckTwingateResourceDoesNotExists(serviceKey),
),
},
{
Config: createServiceKey(terraformResourceName, serviceAccountName),
ConfigPlanChecks: sdk.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction(serviceKey, plancheck.ResourceActionCreate),
},
},
},
},
})
Expand Down
15 changes: 11 additions & 4 deletions twingate/internal/test/acctests/resource/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/Twingate/terraform-provider-twingate/twingate/internal/test"
"github.com/Twingate/terraform-provider-twingate/twingate/internal/test/acctests"
sdk "github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
)

func TestAccTwingateUserCreateUpdate(t *testing.T) {
Expand Down Expand Up @@ -218,18 +219,24 @@ 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, test.RandomEmail()),
Config: terraformResourceTwingateUser(terraformResourceName, userEmail),
Destroy: true,
Check: acctests.ComposeTestCheckFunc(
acctests.CheckTwingateResourceDoesNotExists(theResource),
),
},
{
Config: terraformResourceTwingateUser(terraformResourceName, userEmail),
ConfigPlanChecks: sdk.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction(theResource, plancheck.ResourceActionCreate),
},
},
},
},
})
Expand Down

0 comments on commit 1061a10

Please sign in to comment.