From 68db4023bcd429f9679bd082d0da51e33f873b21 Mon Sep 17 00:00:00 2001 From: Volodymyr Manilo <35466116+vmanilo@users.noreply.github.com> Date: Wed, 21 Feb 2024 22:36:06 +0100 Subject: [PATCH] Fix/datasource acctests (#471) * fix tests * enable tests * fix connectors filter by prefix * fix test with long unique name * revert ci changes --- .../acctests/datasource/connectors_test.go | 9 +++---- .../test/acctests/datasource/groups_test.go | 2 +- .../datasource/service-accounts_test.go | 24 +++++++++++-------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/twingate/internal/test/acctests/datasource/connectors_test.go b/twingate/internal/test/acctests/datasource/connectors_test.go index fa17ea70..2e923147 100644 --- a/twingate/internal/test/acctests/datasource/connectors_test.go +++ b/twingate/internal/test/acctests/datasource/connectors_test.go @@ -238,7 +238,6 @@ func testDatasourceTwingateConnectorsFilter(resourceName, networkName, connector func TestAccDatasourceTwingateConnectorsFilterByPrefix(t *testing.T) { t.Parallel() - prefix := test.Prefix() resourceName := test.RandomResourceName() connectorName := test.RandomConnectorName() theDatasource := "data.twingate_connectors." + resourceName @@ -249,7 +248,7 @@ func TestAccDatasourceTwingateConnectorsFilterByPrefix(t *testing.T) { CheckDestroy: acctests.CheckTwingateResourceDestroy, Steps: []resource.TestStep{ { - Config: testDatasourceTwingateConnectorsFilter(resourceName, test.RandomName(), connectorName, attr.FilterByPrefix, prefix), + Config: testDatasourceTwingateConnectorsFilter(resourceName, test.RandomName(), connectorName, attr.FilterByPrefix, connectorName), Check: acctests.ComposeTestCheckFunc( resource.TestCheckResourceAttr(theDatasource, connectorsLen, "1"), resource.TestCheckResourceAttr(theDatasource, connectorNamePath, connectorName), @@ -288,7 +287,6 @@ func TestAccDatasourceTwingateConnectorsFilterByContains(t *testing.T) { t.Parallel() connectorName := test.RandomConnectorName() - contains := connectorName[len(connectorName)/2 : len(connectorName)/2+5] resourceName := test.RandomResourceName() theDatasource := "data.twingate_connectors." + resourceName @@ -298,7 +296,7 @@ func TestAccDatasourceTwingateConnectorsFilterByContains(t *testing.T) { CheckDestroy: acctests.CheckTwingateResourceDestroy, Steps: []resource.TestStep{ { - Config: testDatasourceTwingateConnectorsFilter(resourceName, test.RandomName(), connectorName, attr.FilterByContains, contains), + Config: testDatasourceTwingateConnectorsFilter(resourceName, test.RandomName(), connectorName, attr.FilterByContains, connectorName), Check: acctests.ComposeTestCheckFunc( resource.TestCheckResourceAttr(theDatasource, connectorsLen, "1"), resource.TestCheckResourceAttr(theDatasource, connectorNamePath, connectorName), @@ -312,7 +310,6 @@ func TestAccDatasourceTwingateConnectorsFilterByRegexp(t *testing.T) { t.Parallel() connectorName := test.RandomConnectorName() - contains := connectorName[len(connectorName)/2 : len(connectorName)/2+5] resourceName := test.RandomResourceName() theDatasource := "data.twingate_connectors." + resourceName @@ -322,7 +319,7 @@ func TestAccDatasourceTwingateConnectorsFilterByRegexp(t *testing.T) { CheckDestroy: acctests.CheckTwingateResourceDestroy, Steps: []resource.TestStep{ { - Config: testDatasourceTwingateConnectorsFilter(resourceName, test.RandomName(), connectorName, attr.FilterByRegexp, fmt.Sprintf(".*%s.*", contains)), + Config: testDatasourceTwingateConnectorsFilter(resourceName, test.RandomName(), connectorName, attr.FilterByRegexp, fmt.Sprintf(".*%s.*", connectorName)), Check: acctests.ComposeTestCheckFunc( resource.TestCheckResourceAttr(theDatasource, connectorsLen, "1"), resource.TestCheckResourceAttr(theDatasource, connectorNamePath, connectorName), diff --git a/twingate/internal/test/acctests/datasource/groups_test.go b/twingate/internal/test/acctests/datasource/groups_test.go index f213960c..7758db00 100644 --- a/twingate/internal/test/acctests/datasource/groups_test.go +++ b/twingate/internal/test/acctests/datasource/groups_test.go @@ -253,7 +253,7 @@ func testDatasourceTwingateGroupsWithDatasource(name string) string { func TestAccDatasourceTwingateGroupsWithFilterByPrefix(t *testing.T) { t.Parallel() - prefix := test.Prefix() + prefix := test.Prefix() + "-" + acctest.RandString(5) resourceName := test.RandomResourceName() theDatasource := "data.twingate_groups." + resourceName diff --git a/twingate/internal/test/acctests/datasource/service-accounts_test.go b/twingate/internal/test/acctests/datasource/service-accounts_test.go index 807fc49e..fe42bfd1 100644 --- a/twingate/internal/test/acctests/datasource/service-accounts_test.go +++ b/twingate/internal/test/acctests/datasource/service-accounts_test.go @@ -23,7 +23,7 @@ var ( func TestAccDatasourceTwingateServicesFilterByName(t *testing.T) { t.Run("Test Twingate Datasource : Acc Services - Filter By Name", func(t *testing.T) { - name := test.Prefix("orange") + name := test.Prefix("orange") + acctest.RandString(5) const ( terraformResourceName = "dts_service" theDatasource = "data.twingate_service_accounts.out" @@ -35,7 +35,7 @@ func TestAccDatasourceTwingateServicesFilterByName(t *testing.T) { terraformResourceName: test.TerraformRandName(terraformResourceName), }, { - serviceName: test.Prefix("lemon"), + serviceName: test.Prefix("lemon") + acctest.RandString(5), terraformResourceName: test.TerraformRandName(terraformResourceName), }, } @@ -340,14 +340,15 @@ func TestAccDatasourceTwingateServicesFilterBySuffix(t *testing.T) { theDatasource = "data.twingate_service_accounts.out" ) - name := test.Prefix("orange") + suffix := "orange-" + acctest.RandString(4) + name := test.Prefix() + suffix config := []terraformServiceConfig{ { serviceName: name, terraformResourceName: test.TerraformRandName(terraformResourceName), }, { - serviceName: test.Prefix("lemon"), + serviceName: test.Prefix("lemon") + acctest.RandString(4), terraformResourceName: test.TerraformRandName(terraformResourceName), }, } @@ -360,7 +361,7 @@ func TestAccDatasourceTwingateServicesFilterBySuffix(t *testing.T) { { Config: terraformConfig( createServices(config), - datasourceServicesWithFilter(config, "orange", attr.FilterBySuffix), + datasourceServicesWithFilter(config, suffix, attr.FilterBySuffix), ), Check: acctests.ComposeTestCheckFunc( resource.TestCheckResourceAttr(theDatasource, serviceAccountsLen, "1"), @@ -379,14 +380,16 @@ func TestAccDatasourceTwingateServicesFilterByContains(t *testing.T) { theDatasource = "data.twingate_service_accounts.out" ) - name := test.Prefix("orange") + contains := acctest.RandString(4) + name := test.Prefix("orange") + contains + config := []terraformServiceConfig{ { serviceName: name, terraformResourceName: test.TerraformRandName(terraformResourceName), }, { - serviceName: test.Prefix("lemon"), + serviceName: test.Prefix("lemon") + acctest.RandString(4), terraformResourceName: test.TerraformRandName(terraformResourceName), }, } @@ -399,7 +402,7 @@ func TestAccDatasourceTwingateServicesFilterByContains(t *testing.T) { { Config: terraformConfig( createServices(config), - datasourceServicesWithFilter(config, "rang", attr.FilterByContains), + datasourceServicesWithFilter(config, contains, attr.FilterByContains), ), Check: acctests.ComposeTestCheckFunc( resource.TestCheckResourceAttr(theDatasource, serviceAccountsLen, "1"), @@ -418,7 +421,8 @@ func TestAccDatasourceTwingateServicesFilterByRegexp(t *testing.T) { theDatasource = "data.twingate_service_accounts.out" ) - name := test.Prefix("orange") + contains := acctest.RandString(5) + name := test.Prefix() + "-" + contains + "-" + acctest.RandString(3) config := []terraformServiceConfig{ { serviceName: name, @@ -438,7 +442,7 @@ func TestAccDatasourceTwingateServicesFilterByRegexp(t *testing.T) { { Config: terraformConfig( createServices(config), - datasourceServicesWithFilter(config, ".*ora.*", attr.FilterByRegexp), + datasourceServicesWithFilter(config, ".*"+contains+".*", attr.FilterByRegexp), ), Check: acctests.ComposeTestCheckFunc( resource.TestCheckResourceAttr(theDatasource, serviceAccountsLen, "1"),