chore: support locking in tests (#28)
This commit is contained in:
committed by
GitHub
parent
af1aa62b3f
commit
e5e50f98c0
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
||||
"os"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -33,6 +34,7 @@ type AcceptanceTestCase struct {
|
||||
MinVersion *version.Version
|
||||
PreCheck func()
|
||||
Steps Steps
|
||||
Lock *sync.Mutex
|
||||
}
|
||||
|
||||
func AcceptanceTest(t *testing.T, testCase AcceptanceTestCase) {
|
||||
@@ -52,6 +54,12 @@ func AcceptanceTest(t *testing.T, testCase AcceptanceTestCase) {
|
||||
if testCase.PreCheck != nil {
|
||||
testCase.PreCheck()
|
||||
}
|
||||
if testCase.Lock != nil {
|
||||
testCase.Lock.Lock()
|
||||
t.Cleanup(func() {
|
||||
testCase.Lock.Unlock()
|
||||
})
|
||||
}
|
||||
},
|
||||
ProtoV6ProviderFactories: providers,
|
||||
CheckDestroy: testCase.CheckDestroy,
|
||||
|
||||
@@ -11,15 +11,8 @@ import (
|
||||
var settingMgmtLock = sync.Mutex{}
|
||||
|
||||
func TestAccSettingMgmt_basic(t *testing.T) {
|
||||
resource.ParallelTest(t, resource.TestCase{
|
||||
PreCheck: func() {
|
||||
pt.PreCheck(t)
|
||||
settingMgmtLock.Lock()
|
||||
t.Cleanup(func() {
|
||||
settingMgmtLock.Unlock()
|
||||
})
|
||||
},
|
||||
ProtoV6ProviderFactories: providers,
|
||||
AcceptanceTest(t, AcceptanceTestCase{
|
||||
Lock: &settingMgmtLock,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccSettingMgmtConfig_basic(),
|
||||
@@ -31,15 +24,8 @@ func TestAccSettingMgmt_basic(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAccSettingMgmt_site(t *testing.T) {
|
||||
resource.ParallelTest(t, resource.TestCase{
|
||||
PreCheck: func() {
|
||||
pt.PreCheck(t)
|
||||
settingMgmtLock.Lock()
|
||||
t.Cleanup(func() {
|
||||
settingMgmtLock.Unlock()
|
||||
})
|
||||
},
|
||||
ProtoV6ProviderFactories: providers,
|
||||
AcceptanceTest(t, AcceptanceTestCase{
|
||||
Lock: &settingMgmtLock,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccSettingMgmtConfig_site(),
|
||||
@@ -56,15 +42,8 @@ func TestAccSettingMgmt_site(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAccSettingMgmt_sshKeys(t *testing.T) {
|
||||
resource.ParallelTest(t, resource.TestCase{
|
||||
PreCheck: func() {
|
||||
pt.PreCheck(t)
|
||||
settingMgmtLock.Lock()
|
||||
t.Cleanup(func() {
|
||||
settingMgmtLock.Unlock()
|
||||
})
|
||||
},
|
||||
ProtoV6ProviderFactories: providers,
|
||||
AcceptanceTest(t, AcceptanceTestCase{
|
||||
Lock: &settingMgmtLock,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccSettingMgmtConfig_sshKeys(),
|
||||
|
||||
@@ -11,15 +11,8 @@ import (
|
||||
var settingRadiusLock = sync.Mutex{}
|
||||
|
||||
func TestAccSettingRadius_basic(t *testing.T) {
|
||||
resource.ParallelTest(t, resource.TestCase{
|
||||
PreCheck: func() {
|
||||
pt.PreCheck(t)
|
||||
settingRadiusLock.Lock()
|
||||
t.Cleanup(func() {
|
||||
settingRadiusLock.Unlock()
|
||||
})
|
||||
},
|
||||
ProtoV6ProviderFactories: providers,
|
||||
AcceptanceTest(t, AcceptanceTestCase{
|
||||
Lock: &settingRadiusLock,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccSettingRadiusConfig_basic(),
|
||||
@@ -31,15 +24,8 @@ func TestAccSettingRadius_basic(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAccSettingRadius_site(t *testing.T) {
|
||||
resource.ParallelTest(t, resource.TestCase{
|
||||
PreCheck: func() {
|
||||
pt.PreCheck(t)
|
||||
settingRadiusLock.Lock()
|
||||
t.Cleanup(func() {
|
||||
settingRadiusLock.Unlock()
|
||||
})
|
||||
},
|
||||
ProtoV6ProviderFactories: providers,
|
||||
AcceptanceTest(t, AcceptanceTestCase{
|
||||
Lock: &settingRadiusLock,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccSettingRadiusConfig_site(),
|
||||
@@ -56,15 +42,8 @@ func TestAccSettingRadius_site(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAccSettingRadius_full(t *testing.T) {
|
||||
resource.ParallelTest(t, resource.TestCase{
|
||||
PreCheck: func() {
|
||||
pt.PreCheck(t)
|
||||
settingRadiusLock.Lock()
|
||||
t.Cleanup(func() {
|
||||
settingRadiusLock.Unlock()
|
||||
})
|
||||
},
|
||||
ProtoV6ProviderFactories: providers,
|
||||
AcceptanceTest(t, AcceptanceTestCase{
|
||||
Lock: &settingRadiusLock,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccSettingRadiusConfig_full(),
|
||||
@@ -81,15 +60,8 @@ func TestAccSettingRadius_full(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAccSettingRadius_vlan(t *testing.T) {
|
||||
resource.ParallelTest(t, resource.TestCase{
|
||||
PreCheck: func() {
|
||||
pt.PreCheck(t)
|
||||
settingRadiusLock.Lock()
|
||||
t.Cleanup(func() {
|
||||
settingRadiusLock.Unlock()
|
||||
})
|
||||
},
|
||||
ProtoV6ProviderFactories: providers,
|
||||
AcceptanceTest(t, AcceptanceTestCase{
|
||||
Lock: &settingRadiusLock,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccSettingRadiusConfig_vlan(),
|
||||
|
||||
@@ -14,16 +14,9 @@ import (
|
||||
var settingUsgLock = sync.Mutex{}
|
||||
|
||||
func TestAccSettingUsg_mdns_v6(t *testing.T) {
|
||||
resource.ParallelTest(t, resource.TestCase{
|
||||
PreCheck: func() {
|
||||
pt.PreCheck(t)
|
||||
PreCheckVersionConstraint(t, "< 7")
|
||||
settingUsgLock.Lock()
|
||||
t.Cleanup(func() {
|
||||
settingUsgLock.Unlock()
|
||||
})
|
||||
},
|
||||
ProtoV6ProviderFactories: providers,
|
||||
AcceptanceTest(t, AcceptanceTestCase{
|
||||
VersionConstraint: "< 7",
|
||||
Lock: &settingUsgLock,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccSettingUsgConfig_mdns(true),
|
||||
@@ -45,16 +38,9 @@ func TestAccSettingUsg_mdns_v6(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAccSettingUsg_mdns_v7(t *testing.T) {
|
||||
resource.ParallelTest(t, resource.TestCase{
|
||||
PreCheck: func() {
|
||||
pt.PreCheck(t)
|
||||
PreCheckVersionConstraint(t, ">= 7")
|
||||
settingUsgLock.Lock()
|
||||
t.Cleanup(func() {
|
||||
settingUsgLock.Unlock()
|
||||
})
|
||||
},
|
||||
ProtoV6ProviderFactories: providers,
|
||||
AcceptanceTest(t, AcceptanceTestCase{
|
||||
VersionConstraint: ">= 7",
|
||||
Lock: &settingUsgLock,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccSettingUsgConfig_mdns(true),
|
||||
@@ -65,15 +51,8 @@ func TestAccSettingUsg_mdns_v7(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAccSettingUsg_dhcpRelay(t *testing.T) {
|
||||
resource.ParallelTest(t, resource.TestCase{
|
||||
PreCheck: func() {
|
||||
pt.PreCheck(t)
|
||||
settingUsgLock.Lock()
|
||||
t.Cleanup(func() {
|
||||
settingUsgLock.Unlock()
|
||||
})
|
||||
},
|
||||
ProtoV6ProviderFactories: providers,
|
||||
AcceptanceTest(t, AcceptanceTestCase{
|
||||
Lock: &settingUsgLock,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccSettingUsgConfig_dhcpRelay(),
|
||||
@@ -85,15 +64,8 @@ func TestAccSettingUsg_dhcpRelay(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAccSettingUsg_site(t *testing.T) {
|
||||
resource.ParallelTest(t, resource.TestCase{
|
||||
PreCheck: func() {
|
||||
pt.PreCheck(t)
|
||||
settingUsgLock.Lock()
|
||||
t.Cleanup(func() {
|
||||
settingUsgLock.Unlock()
|
||||
})
|
||||
},
|
||||
ProtoV6ProviderFactories: providers,
|
||||
AcceptanceTest(t, AcceptanceTestCase{
|
||||
Lock: &settingUsgLock,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccSettingUsgConfig_site(),
|
||||
|
||||
Reference in New Issue
Block a user