Merge pull request #4997 from hashicorp/f-use-acctest-randint
Switch to acctest.RandInt for acceptance tests
This commit is contained in:
commit
5f1afa3e10
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/service/directoryservice"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
@ -316,7 +317,7 @@ resource "aws_subnet" "bar" {
|
|||
}
|
||||
`
|
||||
|
||||
var randomInteger = genRandInt()
|
||||
var randomInteger = acctest.RandInt()
|
||||
var testAccDirectoryServiceDirectoryConfig_withAlias = fmt.Sprintf(`
|
||||
resource "aws_directory_service_directory" "bar_a" {
|
||||
name = "corp.notexample.com"
|
||||
|
|
|
@ -539,7 +539,7 @@ func resourceAwsElasticacheClusterDelete(d *schema.ResourceData, meta interface{
|
|||
Pending: []string{"creating", "available", "deleting", "incompatible-parameters", "incompatible-network", "restore-failed"},
|
||||
Target: []string{},
|
||||
Refresh: cacheClusterStateRefreshFunc(conn, d.Id(), "", []string{}),
|
||||
Timeout: 10 * time.Minute,
|
||||
Timeout: 20 * time.Minute,
|
||||
Delay: 10 * time.Second,
|
||||
MinTimeout: 3 * time.Second,
|
||||
}
|
||||
|
|
|
@ -2,14 +2,13 @@ package aws
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/service/elasticache"
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
@ -37,9 +36,9 @@ func TestAccAWSElasticacheCluster_basic(t *testing.T) {
|
|||
func TestAccAWSElasticacheCluster_snapshotsWithUpdates(t *testing.T) {
|
||||
var ec elasticache.CacheCluster
|
||||
|
||||
ri := genRandInt()
|
||||
preConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfig_snapshots, ri, ri, ri)
|
||||
postConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfig_snapshotsUpdated, ri, ri, ri)
|
||||
ri := acctest.RandInt()
|
||||
preConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfig_snapshots, ri, ri, acctest.RandString(10))
|
||||
postConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfig_snapshotsUpdated, ri, ri, acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -76,9 +75,9 @@ func TestAccAWSElasticacheCluster_snapshotsWithUpdates(t *testing.T) {
|
|||
func TestAccAWSElasticacheCluster_decreasingCacheNodes(t *testing.T) {
|
||||
var ec elasticache.CacheCluster
|
||||
|
||||
ri := genRandInt()
|
||||
preConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfigDecreasingNodes, ri, ri, ri)
|
||||
postConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfigDecreasingNodes_update, ri, ri, ri)
|
||||
ri := acctest.RandInt()
|
||||
preConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfigDecreasingNodes, ri, ri, acctest.RandString(10))
|
||||
postConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfigDecreasingNodes_update, ri, ri, acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -218,10 +217,6 @@ func testAccCheckAWSElasticacheClusterExists(n string, v *elasticache.CacheClust
|
|||
}
|
||||
}
|
||||
|
||||
func genRandInt() int {
|
||||
return rand.New(rand.NewSource(time.Now().UnixNano())).Int() % 1000
|
||||
}
|
||||
|
||||
var testAccAWSElasticacheClusterConfig = fmt.Sprintf(`
|
||||
provider "aws" {
|
||||
region = "us-east-1"
|
||||
|
@ -244,7 +239,7 @@ resource "aws_elasticache_security_group" "bar" {
|
|||
}
|
||||
|
||||
resource "aws_elasticache_cluster" "bar" {
|
||||
cluster_id = "tf-test-%03d"
|
||||
cluster_id = "tf-%s"
|
||||
engine = "memcached"
|
||||
node_type = "cache.m1.small"
|
||||
num_cache_nodes = 1
|
||||
|
@ -252,7 +247,7 @@ resource "aws_elasticache_cluster" "bar" {
|
|||
parameter_group_name = "default.memcached1.4"
|
||||
security_group_names = ["${aws_elasticache_security_group.bar.name}"]
|
||||
}
|
||||
`, genRandInt(), genRandInt(), genRandInt())
|
||||
`, acctest.RandInt(), acctest.RandInt(), acctest.RandString(10))
|
||||
|
||||
var testAccAWSElasticacheClusterConfig_snapshots = `
|
||||
provider "aws" {
|
||||
|
@ -276,7 +271,7 @@ resource "aws_elasticache_security_group" "bar" {
|
|||
}
|
||||
|
||||
resource "aws_elasticache_cluster" "bar" {
|
||||
cluster_id = "tf-test-%03d"
|
||||
cluster_id = "tf-%s"
|
||||
engine = "redis"
|
||||
node_type = "cache.m1.small"
|
||||
num_cache_nodes = 1
|
||||
|
@ -310,7 +305,7 @@ resource "aws_elasticache_security_group" "bar" {
|
|||
}
|
||||
|
||||
resource "aws_elasticache_cluster" "bar" {
|
||||
cluster_id = "tf-test-%03d"
|
||||
cluster_id = "tf-%s"
|
||||
engine = "redis"
|
||||
node_type = "cache.m1.small"
|
||||
num_cache_nodes = 1
|
||||
|
@ -345,7 +340,7 @@ resource "aws_elasticache_security_group" "bar" {
|
|||
}
|
||||
|
||||
resource "aws_elasticache_cluster" "bar" {
|
||||
cluster_id = "tf-test-%03d"
|
||||
cluster_id = "tf-%s"
|
||||
engine = "memcached"
|
||||
node_type = "cache.m1.small"
|
||||
num_cache_nodes = 3
|
||||
|
@ -377,7 +372,7 @@ resource "aws_elasticache_security_group" "bar" {
|
|||
}
|
||||
|
||||
resource "aws_elasticache_cluster" "bar" {
|
||||
cluster_id = "tf-test-%03d"
|
||||
cluster_id = "tf-%s"
|
||||
engine = "memcached"
|
||||
node_type = "cache.m1.small"
|
||||
num_cache_nodes = 1
|
||||
|
@ -427,7 +422,7 @@ resource "aws_elasticache_cluster" "bar" {
|
|||
// Including uppercase letters in this name to ensure
|
||||
// that we correctly handle the fact that the API
|
||||
// normalizes names to lowercase.
|
||||
cluster_id = "tf-TEST-%03d"
|
||||
cluster_id = "tf-%s"
|
||||
node_type = "cache.m1.small"
|
||||
num_cache_nodes = 1
|
||||
engine = "redis"
|
||||
|
@ -443,7 +438,7 @@ resource "aws_elasticache_cluster" "bar" {
|
|||
resource "aws_sns_topic" "topic_example" {
|
||||
name = "tf-ecache-cluster-test"
|
||||
}
|
||||
`, genRandInt(), genRandInt(), genRandInt())
|
||||
`, acctest.RandInt(), acctest.RandInt(), acctest.RandString(10))
|
||||
|
||||
var testAccAWSElasticacheClusterMultiAZInVPCConfig = fmt.Sprintf(`
|
||||
resource "aws_vpc" "foo" {
|
||||
|
@ -493,7 +488,7 @@ resource "aws_security_group" "bar" {
|
|||
}
|
||||
|
||||
resource "aws_elasticache_cluster" "bar" {
|
||||
cluster_id = "tf-test-%03d"
|
||||
cluster_id = "tf-%s"
|
||||
engine = "memcached"
|
||||
node_type = "cache.m1.small"
|
||||
num_cache_nodes = 2
|
||||
|
@ -507,4 +502,4 @@ resource "aws_elasticache_cluster" "bar" {
|
|||
"us-west-2b"
|
||||
]
|
||||
}
|
||||
`, genRandInt(), genRandInt(), genRandInt(), genRandInt(), genRandInt())
|
||||
`, acctest.RandInt(), acctest.RandInt(), acctest.RandInt(), acctest.RandInt(), acctest.RandString(10))
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/service/elasticache"
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
@ -91,4 +92,4 @@ resource "aws_elasticache_security_group" "bar" {
|
|||
description = "tf-test-security-group-descr"
|
||||
security_group_names = ["${aws_security_group.bar.name}"]
|
||||
}
|
||||
`, genRandInt(), genRandInt())
|
||||
`, acctest.RandInt(), acctest.RandInt())
|
||||
|
|
|
@ -7,13 +7,14 @@ import (
|
|||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/service/elasticache"
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
func TestAccAWSElasticacheSubnetGroup_basic(t *testing.T) {
|
||||
var csg elasticache.CacheSubnetGroup
|
||||
config := fmt.Sprintf(testAccAWSElasticacheSubnetGroupConfig, genRandInt())
|
||||
config := fmt.Sprintf(testAccAWSElasticacheSubnetGroupConfig, acctest.RandInt())
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -33,7 +34,7 @@ func TestAccAWSElasticacheSubnetGroup_basic(t *testing.T) {
|
|||
func TestAccAWSElasticacheSubnetGroup_update(t *testing.T) {
|
||||
var csg elasticache.CacheSubnetGroup
|
||||
rn := "aws_elasticache_subnet_group.bar"
|
||||
ri := genRandInt()
|
||||
ri := acctest.RandInt()
|
||||
preConfig := fmt.Sprintf(testAccAWSElasticacheSubnetGroupUpdateConfigPre, ri)
|
||||
postConfig := fmt.Sprintf(testAccAWSElasticacheSubnetGroupUpdateConfigPost, ri)
|
||||
|
||||
|
|
|
@ -333,7 +333,7 @@ resource "aws_subnet" "foo" {
|
|||
cidr_block = "172.16.10.0/24"
|
||||
availability_zone = "us-west-2a"
|
||||
tags {
|
||||
Name = "tf-eni-test"
|
||||
Name = "tf-foo-eni-test"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -342,7 +342,7 @@ resource "aws_subnet" "bar" {
|
|||
cidr_block = "172.16.11.0/24"
|
||||
availability_zone = "us-west-2a"
|
||||
tags {
|
||||
Name = "tf-eni-test"
|
||||
Name = "tf-bar-eni-test"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -359,7 +359,7 @@ resource "aws_instance" "foo" {
|
|||
associate_public_ip_address = false
|
||||
private_ip = "172.16.11.50"
|
||||
tags {
|
||||
Name = "tf-eni-test"
|
||||
Name = "foo-tf-eni-test"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ func TestAccAWSS3Bucket_Policy(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAccAWSS3Bucket_UpdateAcl(t *testing.T) {
|
||||
ri := genRandInt()
|
||||
ri := acctest.RandInt()
|
||||
preConfig := fmt.Sprintf(testAccAWSS3BucketConfigWithAcl, ri)
|
||||
postConfig := fmt.Sprintf(testAccAWSS3BucketConfigWithAclUpdate, ri)
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
@ -750,7 +751,7 @@ var testAccAWSSecurityGroupRuleRace = func() string {
|
|||
name = "tf-sg-rule-race-group-%d"
|
||||
vpc_id = "${aws_vpc.default.id}"
|
||||
}
|
||||
`, genRandInt()))
|
||||
`, acctest.RandInt()))
|
||||
for i := 1; i < iterations; i++ {
|
||||
b.WriteString(fmt.Sprintf(`
|
||||
resource "aws_security_group_rule" "ingress%d" {
|
||||
|
|
|
@ -3,11 +3,9 @@ package azure
|
|||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/terraform/config"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
|
@ -154,10 +152,6 @@ func TestAzure_providerConfigure(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func genRandInt() int {
|
||||
return rand.New(rand.NewSource(time.Now().UnixNano())).Int() % 100000
|
||||
}
|
||||
|
||||
// testAzurePublishSettingsStr is a revoked publishsettings file
|
||||
const testAzurePublishSettingsStr = `
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
|
|
@ -7,13 +7,14 @@ import (
|
|||
|
||||
"github.com/Azure/azure-sdk-for-go/management"
|
||||
"github.com/Azure/azure-sdk-for-go/management/virtualmachinedisk"
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
func TestAccAzureDataDisk_basic(t *testing.T) {
|
||||
var disk virtualmachinedisk.DataDiskResponse
|
||||
name := fmt.Sprintf("terraform-test%d", genRandInt())
|
||||
name := fmt.Sprintf("terraform-test%d", acctest.RandInt())
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -38,7 +39,7 @@ func TestAccAzureDataDisk_basic(t *testing.T) {
|
|||
|
||||
func TestAccAzureDataDisk_update(t *testing.T) {
|
||||
var disk virtualmachinedisk.DataDiskResponse
|
||||
name := fmt.Sprintf("terraform-test%d", genRandInt())
|
||||
name := fmt.Sprintf("terraform-test%d", acctest.RandInt())
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
|
||||
|
@ -20,7 +21,7 @@ import (
|
|||
|
||||
func TestAccGoogleSqlDatabaseInstance_basic(t *testing.T) {
|
||||
var instance sqladmin.DatabaseInstance
|
||||
databaseID := genRandInt()
|
||||
databaseID := acctest.RandInt()
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -64,7 +65,7 @@ func TestAccGoogleSqlDatabaseInstance_basic2(t *testing.T) {
|
|||
|
||||
func TestAccGoogleSqlDatabaseInstance_settings_basic(t *testing.T) {
|
||||
var instance sqladmin.DatabaseInstance
|
||||
databaseID := genRandInt()
|
||||
databaseID := acctest.RandInt()
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -87,7 +88,7 @@ func TestAccGoogleSqlDatabaseInstance_settings_basic(t *testing.T) {
|
|||
|
||||
func TestAccGoogleSqlDatabaseInstance_settings_upgrade(t *testing.T) {
|
||||
var instance sqladmin.DatabaseInstance
|
||||
databaseID := genRandInt()
|
||||
databaseID := acctest.RandInt()
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -120,7 +121,7 @@ func TestAccGoogleSqlDatabaseInstance_settings_upgrade(t *testing.T) {
|
|||
|
||||
func TestAccGoogleSqlDatabaseInstance_settings_downgrade(t *testing.T) {
|
||||
var instance sqladmin.DatabaseInstance
|
||||
databaseID := genRandInt()
|
||||
databaseID := acctest.RandInt()
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
package google
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
func genRandInt() int {
|
||||
return rand.New(rand.NewSource(time.Now().UnixNano())).Int()
|
||||
}
|
Loading…
Reference in New Issue