Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create test helper function to test resource exists #263

Merged
merged 2 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions routeros/resource_bgp_connection_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package routeros

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

const testBGPConnectionAddress = "routeros_routing_bgp_connection.test"
Expand All @@ -24,7 +22,7 @@ func TestAccBGPConnectionTest_basic(t *testing.T) {
{
Config: testAccBGPConnectionConfig(),
Check: resource.ComposeTestCheckFunc(
testAccCheckBGPConnectionExists(testBGPConnectionAddress),
testResourcePrimaryInstanceId(testBGPConnectionAddress),
resource.TestCheckResourceAttr(testBGPConnectionAddress, "name", "neighbor-test"),
),
},
Expand All @@ -34,21 +32,6 @@ func TestAccBGPConnectionTest_basic(t *testing.T) {
}
}

func testAccCheckBGPConnectionExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
if !ok {
return fmt.Errorf("not found: %s", name)
}

if rs.Primary.ID == "" {
return fmt.Errorf("no id is set")
}

return nil
}
}

func testAccBGPConnectionConfig() string {
return providerConfig + `

Expand Down
19 changes: 1 addition & 18 deletions routeros/resource_bgp_template_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package routeros

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

const testBGPTemplateAddress = "routeros_routing_bgp_template.test"
Expand All @@ -24,7 +22,7 @@ func TestAccBGPTemplateTest_basic(t *testing.T) {
{
Config: testAccBGPTemplateConfig(),
Check: resource.ComposeTestCheckFunc(
testAccCheckBGPTemplateExists(testBGPTemplateAddress),
testResourcePrimaryInstanceId(testBGPTemplateAddress),
resource.TestCheckResourceAttr(testBGPTemplateAddress, "name", "test-template"),
),
},
Expand All @@ -34,21 +32,6 @@ func TestAccBGPTemplateTest_basic(t *testing.T) {
}
}

func testAccCheckBGPTemplateExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
if !ok {
return fmt.Errorf("not found: %s", name)
}

if rs.Primary.ID == "" {
return fmt.Errorf("no id is set")
}

return nil
}
}

func testAccBGPTemplateConfig() string {
return providerConfig + `

Expand Down
19 changes: 1 addition & 18 deletions routeros/resource_capsman_channel_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package routeros

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

const testCapsManChannelAddress = "routeros_capsman_channel.test_channel"
Expand All @@ -24,7 +22,7 @@ func TestAccCapsManChannelTest_basic(t *testing.T) {
{
Config: testAccCapsManChannelConfig(),
Check: resource.ComposeTestCheckFunc(
testAccCheckCapsManChannelExists(testCapsManChannelAddress),
testResourcePrimaryInstanceId(testCapsManChannelAddress),
resource.TestCheckResourceAttr(testCapsManChannelAddress, "name", "test_channel"),
),
},
Expand All @@ -34,21 +32,6 @@ func TestAccCapsManChannelTest_basic(t *testing.T) {
}
}

func testAccCheckCapsManChannelExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
if !ok {
return fmt.Errorf("not found: %s", name)
}

if rs.Primary.ID == "" {
return fmt.Errorf("no id is set")
}

return nil
}
}

func testAccCapsManChannelConfig() string {
return providerConfig + `

Expand Down
19 changes: 1 addition & 18 deletions routeros/resource_capsman_configuration_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package routeros

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

const testCapsManConfigurationAddress = "routeros_capsman_configuration.test_configuration"
Expand All @@ -24,7 +22,7 @@ func TestAccCapsManConfigurationTest_basic(t *testing.T) {
{
Config: testAccCapsManConfigurationConfig(0),
Check: resource.ComposeTestCheckFunc(
testAccCheckCapsManConfigurationExists(testCapsManConfigurationAddress),
testResourcePrimaryInstanceId(testCapsManConfigurationAddress),
resource.TestCheckResourceAttr(testCapsManConfigurationAddress, "name", "test_configuration"),
),
},
Expand All @@ -50,21 +48,6 @@ func TestAccCapsManConfigurationTest_basic(t *testing.T) {
}
}

func testAccCheckCapsManConfigurationExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
if !ok {
return fmt.Errorf("not found: %s", name)
}

if rs.Primary.ID == "" {
return fmt.Errorf("no id is set")
}

return nil
}
}

func testAccCapsManConfigurationConfig(n int) string {
tests := []string{`
resource "routeros_capsman_configuration" "test_configuration" {
Expand Down
19 changes: 1 addition & 18 deletions routeros/resource_capsman_datapath_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package routeros

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

const testCapsManDatapathAddress = "routeros_capsman_datapath.test_datapath"
Expand All @@ -24,7 +22,7 @@ func TestAccCapsManDatapathTest_basic(t *testing.T) {
{
Config: testAccCapsManDatapathConfig(),
Check: resource.ComposeTestCheckFunc(
testAccCheckCapsManDatapathExists(testCapsManDatapathAddress),
testResourcePrimaryInstanceId(testCapsManDatapathAddress),
resource.TestCheckResourceAttr(testCapsManDatapathAddress, "name", "test_datapath"),
),
},
Expand All @@ -34,21 +32,6 @@ func TestAccCapsManDatapathTest_basic(t *testing.T) {
}
}

func testAccCheckCapsManDatapathExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
if !ok {
return fmt.Errorf("not found: %s", name)
}

if rs.Primary.ID == "" {
return fmt.Errorf("no id is set")
}

return nil
}
}

func testAccCapsManDatapathConfig() string {
return providerConfig + `

Expand Down
23 changes: 3 additions & 20 deletions routeros/resource_capsman_manager_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package routeros

import (
"fmt"
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

const testCapsManAaaAddress = "routeros_capsman_aaa.test_3a"
Expand All @@ -26,21 +24,21 @@ func TestAccCapsManManagerTest_basic(t *testing.T) {
{
Config: testAccCapsManManagerUnitConfig(name, "routeros_capsman_manager"),
Check: resource.ComposeTestCheckFunc(
testAccCheckCapsManResourceExists(testCapsManManagerAddress),
testResourcePrimaryInstanceId(testCapsManManagerAddress),
resource.TestCheckResourceAttr(testCapsManManagerAddress, "id", "caps-man.manager"),
),
},
{
Config: testAccCapsManManagerUnitConfig(name, "routeros_capsman_aaa"),
Check: resource.ComposeTestCheckFunc(
testAccCheckCapsManResourceExists(testCapsManAaaAddress),
testResourcePrimaryInstanceId(testCapsManAaaAddress),
resource.TestCheckResourceAttr(testCapsManAaaAddress, "id", "caps-man.aaa"),
),
},
{
Config: testAccCapsManManagerUnitConfig(name, "routeros_capsman_manager_interface"),
Check: resource.ComposeTestCheckFunc(
testAccCheckCapsManResourceExists(testCapsManManagerInterfaceAddress),
testResourcePrimaryInstanceId(testCapsManManagerInterfaceAddress),
resource.TestCheckResourceAttr(testCapsManManagerInterfaceAddress, "interface", "ether1"),
),
},
Expand All @@ -50,21 +48,6 @@ func TestAccCapsManManagerTest_basic(t *testing.T) {
}
}

func testAccCheckCapsManResourceExists(address string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[address]
if !ok {
return fmt.Errorf("not found: %s", address)
}

if rs.Primary.ID == "" {
return fmt.Errorf("no id is set")
}

return nil
}
}

func testAccCapsManManagerUnitConfig(testName, resourceName string) string {
conf := `
provider "routeros" {
Expand Down
19 changes: 1 addition & 18 deletions routeros/resource_capsman_provisioning_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package routeros

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

const testCapsManProvisioningAddress = "routeros_capsman_provisioning.test_provisioning"
Expand All @@ -24,7 +22,7 @@ func TestAccCapsManProvisioningTest_basic(t *testing.T) {
{
Config: testAccCapsManProvisioningConfig(),
Check: resource.ComposeTestCheckFunc(
testAccCheckCapsManProvisioningExists(testCapsManProvisioningAddress),
testResourcePrimaryInstanceId(testCapsManProvisioningAddress),
resource.TestCheckResourceAttr(testCapsManProvisioningAddress, "name_prefix", "cap-"),
),
},
Expand All @@ -35,21 +33,6 @@ func TestAccCapsManProvisioningTest_basic(t *testing.T) {
}
}

func testAccCheckCapsManProvisioningExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
if !ok {
return fmt.Errorf("not found: %s", name)
}

if rs.Primary.ID == "" {
return fmt.Errorf("no id is set")
}

return nil
}
}

func testAccCapsManProvisioningConfig() string {
return providerConfig + `

Expand Down
19 changes: 1 addition & 18 deletions routeros/resource_capsman_rates_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package routeros

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

const testCapsManRatesAddress = "routeros_capsman_rates.test_rates"
Expand All @@ -24,7 +22,7 @@ func TestAccCapsManRatesTest_basic(t *testing.T) {
{
Config: testAccCapsManRatesConfig(),
Check: resource.ComposeTestCheckFunc(
testAccCheckCapsManRatesExists(testCapsManRatesAddress),
testResourcePrimaryInstanceId(testCapsManRatesAddress),
resource.TestCheckResourceAttr(testCapsManRatesAddress, "name", "test_rates"),
),
},
Expand All @@ -35,21 +33,6 @@ func TestAccCapsManRatesTest_basic(t *testing.T) {
}
}

func testAccCheckCapsManRatesExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
if !ok {
return fmt.Errorf("not found: %s", name)
}

if rs.Primary.ID == "" {
return fmt.Errorf("no id is set")
}

return nil
}
}

func testAccCapsManRatesConfig() string {
return providerConfig + `

Expand Down
Loading
Loading