backend/azure: Bring randString test helper into this package

We've been keeping around the whole legacy "acctest" package just for this
one function, used only by the Azure provider.

Instead we'll inline the function into this package, so that we can delete
the acctest package in a future commit.
pull/34810/head
Martin Atkins 2 years ago
parent 049093a3ad
commit c0943fdd2a

@ -9,7 +9,6 @@ import (
"testing"
"github.com/hashicorp/terraform/internal/backend"
"github.com/hashicorp/terraform/internal/legacy/helper/acctest"
)
func TestBackend_impl(t *testing.T) {
@ -44,7 +43,7 @@ func TestBackendConfig(t *testing.T) {
func TestAccBackendAccessKeyBasic(t *testing.T) {
testAccAzureBackend(t)
rs := acctest.RandString(4)
rs := randString(4)
res := testResourceNames(rs, "testState")
armClient := buildTestClient(t, res)
@ -70,7 +69,7 @@ func TestAccBackendAccessKeyBasic(t *testing.T) {
func TestAccBackendSASTokenBasic(t *testing.T) {
testAccAzureBackend(t)
rs := acctest.RandString(4)
rs := randString(4)
res := testResourceNames(rs, "testState")
armClient := buildTestClient(t, res)
@ -100,7 +99,7 @@ func TestAccBackendSASTokenBasic(t *testing.T) {
func TestAccBackendOIDCBasic(t *testing.T) {
testAccAzureBackend(t)
rs := acctest.RandString(4)
rs := randString(4)
res := testResourceNames(rs, "testState")
armClient := buildTestClient(t, res)
@ -128,7 +127,7 @@ func TestAccBackendOIDCBasic(t *testing.T) {
func TestAccBackendAzureADAuthBasic(t *testing.T) {
testAccAzureBackend(t)
rs := acctest.RandString(4)
rs := randString(4)
res := testResourceNames(rs, "testState")
res.useAzureADAuth = true
armClient := buildTestClient(t, res)
@ -156,7 +155,7 @@ func TestAccBackendAzureADAuthBasic(t *testing.T) {
func TestAccBackendManagedServiceIdentityBasic(t *testing.T) {
testAccAzureBackendRunningInAzure(t)
rs := acctest.RandString(4)
rs := randString(4)
res := testResourceNames(rs, "testState")
armClient := buildTestClient(t, res)
@ -191,7 +190,7 @@ func TestAccBackendServicePrincipalClientCertificateBasic(t *testing.T) {
t.Skip("Skipping since `ARM_CLIENT_CERTIFICATE_PATH` is not specified!")
}
rs := acctest.RandString(4)
rs := randString(4)
res := testResourceNames(rs, "testState")
armClient := buildTestClient(t, res)
@ -221,7 +220,7 @@ func TestAccBackendServicePrincipalClientCertificateBasic(t *testing.T) {
func TestAccBackendServicePrincipalClientSecretBasic(t *testing.T) {
testAccAzureBackend(t)
rs := acctest.RandString(4)
rs := randString(4)
res := testResourceNames(rs, "testState")
armClient := buildTestClient(t, res)
@ -257,7 +256,7 @@ func TestAccBackendServicePrincipalClientSecretCustomEndpoint(t *testing.T) {
t.Skip("Skipping as ARM_ENDPOINT isn't configured")
}
rs := acctest.RandString(4)
rs := randString(4)
res := testResourceNames(rs, "testState")
armClient := buildTestClient(t, res)
@ -286,7 +285,7 @@ func TestAccBackendServicePrincipalClientSecretCustomEndpoint(t *testing.T) {
func TestAccBackendAccessKeyLocked(t *testing.T) {
testAccAzureBackend(t)
rs := acctest.RandString(4)
rs := randString(4)
res := testResourceNames(rs, "testState")
armClient := buildTestClient(t, res)
@ -324,7 +323,7 @@ func TestAccBackendAccessKeyLocked(t *testing.T) {
func TestAccBackendServicePrincipalLocked(t *testing.T) {
testAccAzureBackend(t)
rs := acctest.RandString(4)
rs := randString(4)
res := testResourceNames(rs, "testState")
armClient := buildTestClient(t, res)

@ -8,10 +8,10 @@ import (
"os"
"testing"
"github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/blobs"
"github.com/hashicorp/terraform/internal/backend"
"github.com/hashicorp/terraform/internal/legacy/helper/acctest"
"github.com/hashicorp/terraform/internal/states/remote"
"github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/blobs"
)
func TestRemoteClient_impl(t *testing.T) {
@ -21,7 +21,7 @@ func TestRemoteClient_impl(t *testing.T) {
func TestRemoteClientAccessKeyBasic(t *testing.T) {
testAccAzureBackend(t)
rs := acctest.RandString(4)
rs := randString(4)
res := testResourceNames(rs, "testState")
armClient := buildTestClient(t, res)
@ -51,7 +51,7 @@ func TestRemoteClientAccessKeyBasic(t *testing.T) {
func TestRemoteClientManagedServiceIdentityBasic(t *testing.T) {
testAccAzureBackendRunningInAzure(t)
rs := acctest.RandString(4)
rs := randString(4)
res := testResourceNames(rs, "testState")
armClient := buildTestClient(t, res)
@ -84,7 +84,7 @@ func TestRemoteClientManagedServiceIdentityBasic(t *testing.T) {
func TestRemoteClientSasTokenBasic(t *testing.T) {
testAccAzureBackend(t)
rs := acctest.RandString(4)
rs := randString(4)
res := testResourceNames(rs, "testState")
armClient := buildTestClient(t, res)
@ -119,7 +119,7 @@ func TestRemoteClientSasTokenBasic(t *testing.T) {
func TestRemoteClientServicePrincipalBasic(t *testing.T) {
testAccAzureBackend(t)
rs := acctest.RandString(4)
rs := randString(4)
res := testResourceNames(rs, "testState")
armClient := buildTestClient(t, res)
@ -153,7 +153,7 @@ func TestRemoteClientServicePrincipalBasic(t *testing.T) {
func TestRemoteClientAccessKeyLocks(t *testing.T) {
testAccAzureBackend(t)
rs := acctest.RandString(4)
rs := randString(4)
res := testResourceNames(rs, "testState")
armClient := buildTestClient(t, res)
@ -197,7 +197,7 @@ func TestRemoteClientAccessKeyLocks(t *testing.T) {
func TestRemoteClientServicePrincipalLocks(t *testing.T) {
testAccAzureBackend(t)
rs := acctest.RandString(4)
rs := randString(4)
res := testResourceNames(rs, "testState")
armClient := buildTestClient(t, res)
@ -249,7 +249,7 @@ func TestRemoteClientServicePrincipalLocks(t *testing.T) {
func TestPutMaintainsMetaData(t *testing.T) {
testAccAzureBackend(t)
rs := acctest.RandString(4)
rs := randString(4)
res := testResourceNames(rs, "testState")
armClient := buildTestClient(t, res)
@ -296,7 +296,7 @@ func TestPutMaintainsMetaData(t *testing.T) {
giovanniBlobClient: *client,
}
bytes := []byte(acctest.RandString(20))
bytes := []byte(randString(20))
err = remoteClient.Put(bytes)
if err != nil {
t.Fatalf("Error putting data: %+v", err)

@ -7,6 +7,7 @@ import (
"context"
"fmt"
"log"
"math/rand"
"os"
"strings"
"testing"
@ -229,3 +230,13 @@ func (c ArmClient) destroyTestResources(ctx context.Context, resources resourceN
return nil
}
// randString generates a random alphanumeric string of the length specified
func randString(strlen int) string {
const charSet = "abcdefghijklmnopqrstuvwxyz012346789"
result := make([]byte, strlen)
for i := 0; i < strlen; i++ {
result[i] = charSet[rand.Intn(len(charSet))]
}
return string(result)
}

Loading…
Cancel
Save