Switch to acctest.RandInt for acceptance tests
This commit is contained in:
parent
316d4734ee
commit
840d2e7ccc
|
@ -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"
|
||||
|
|
|
@ -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,7 +36,7 @@ func TestAccAWSElasticacheCluster_basic(t *testing.T) {
|
|||
func TestAccAWSElasticacheCluster_snapshotsWithUpdates(t *testing.T) {
|
||||
var ec elasticache.CacheCluster
|
||||
|
||||
ri := genRandInt()
|
||||
ri := acctest.RandInt()
|
||||
preConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfig_snapshots, ri, ri, ri)
|
||||
postConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfig_snapshotsUpdated, ri, ri, ri)
|
||||
|
||||
|
@ -76,7 +75,7 @@ func TestAccAWSElasticacheCluster_snapshotsWithUpdates(t *testing.T) {
|
|||
func TestAccAWSElasticacheCluster_decreasingCacheNodes(t *testing.T) {
|
||||
var ec elasticache.CacheCluster
|
||||
|
||||
ri := genRandInt()
|
||||
ri := acctest.RandInt()
|
||||
preConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfigDecreasingNodes, ri, ri, ri)
|
||||
postConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfigDecreasingNodes_update, ri, ri, ri)
|
||||
|
||||
|
@ -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-%03d"
|
||||
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-%03d"
|
||||
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-%03d"
|
||||
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-%03d"
|
||||
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