Skip to content

Commit

Permalink
Fix/datasource acctests (Twingate#471)
Browse files Browse the repository at this point in the history
* fix tests

* enable tests

* fix connectors filter by prefix

* fix test with long unique name

* revert ci changes
  • Loading branch information
vmanilo authored Feb 21, 2024
1 parent 4c7ae9d commit 68db402
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
9 changes: 3 additions & 6 deletions twingate/internal/test/acctests/datasource/connectors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down Expand Up @@ -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

Expand All @@ -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),
Expand All @@ -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

Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion twingate/internal/test/acctests/datasource/groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 14 additions & 10 deletions twingate/internal/test/acctests/datasource/service-accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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),
},
}
Expand Down Expand Up @@ -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),
},
}
Expand All @@ -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"),
Expand All @@ -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),
},
}
Expand All @@ -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"),
Expand All @@ -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,
Expand All @@ -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"),
Expand Down

0 comments on commit 68db402

Please sign in to comment.