Skip to content

Commit 840d2e7

Browse files
committed
Switch to acctest.RandInt for acceptance tests
1 parent 316d473 commit 840d2e7

11 files changed

Lines changed: 34 additions & 49 deletions

builtin/providers/aws/resource_aws_directory_service_directory_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/aws/aws-sdk-go/aws/awserr"
99
"github.com/aws/aws-sdk-go/service/directoryservice"
1010

11+
"github.com/hashicorp/terraform/helper/acctest"
1112
"github.com/hashicorp/terraform/helper/resource"
1213
"github.com/hashicorp/terraform/terraform"
1314
)
@@ -316,7 +317,7 @@ resource "aws_subnet" "bar" {
316317
}
317318
`
318319

319-
var randomInteger = genRandInt()
320+
var randomInteger = acctest.RandInt()
320321
var testAccDirectoryServiceDirectoryConfig_withAlias = fmt.Sprintf(`
321322
resource "aws_directory_service_directory" "bar_a" {
322323
name = "corp.notexample.com"

builtin/providers/aws/resource_aws_elasticache_cluster_test.go

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ package aws
22

33
import (
44
"fmt"
5-
"math/rand"
65
"strings"
76
"testing"
8-
"time"
97

108
"github.com/aws/aws-sdk-go/aws"
119
"github.com/aws/aws-sdk-go/aws/awserr"
1210
"github.com/aws/aws-sdk-go/service/elasticache"
11+
"github.com/hashicorp/terraform/helper/acctest"
1312
"github.com/hashicorp/terraform/helper/resource"
1413
"github.com/hashicorp/terraform/terraform"
1514
)
@@ -37,7 +36,7 @@ func TestAccAWSElasticacheCluster_basic(t *testing.T) {
3736
func TestAccAWSElasticacheCluster_snapshotsWithUpdates(t *testing.T) {
3837
var ec elasticache.CacheCluster
3938

40-
ri := genRandInt()
39+
ri := acctest.RandInt()
4140
preConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfig_snapshots, ri, ri, ri)
4241
postConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfig_snapshotsUpdated, ri, ri, ri)
4342

@@ -76,7 +75,7 @@ func TestAccAWSElasticacheCluster_snapshotsWithUpdates(t *testing.T) {
7675
func TestAccAWSElasticacheCluster_decreasingCacheNodes(t *testing.T) {
7776
var ec elasticache.CacheCluster
7877

79-
ri := genRandInt()
78+
ri := acctest.RandInt()
8079
preConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfigDecreasingNodes, ri, ri, ri)
8180
postConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfigDecreasingNodes_update, ri, ri, ri)
8281

@@ -218,10 +217,6 @@ func testAccCheckAWSElasticacheClusterExists(n string, v *elasticache.CacheClust
218217
}
219218
}
220219

221-
func genRandInt() int {
222-
return rand.New(rand.NewSource(time.Now().UnixNano())).Int() % 1000
223-
}
224-
225220
var testAccAWSElasticacheClusterConfig = fmt.Sprintf(`
226221
provider "aws" {
227222
region = "us-east-1"
@@ -244,15 +239,15 @@ resource "aws_elasticache_security_group" "bar" {
244239
}
245240
246241
resource "aws_elasticache_cluster" "bar" {
247-
cluster_id = "tf-test-%03d"
242+
cluster_id = "tf-%s"
248243
engine = "memcached"
249244
node_type = "cache.m1.small"
250245
num_cache_nodes = 1
251246
port = 11211
252247
parameter_group_name = "default.memcached1.4"
253248
security_group_names = ["${aws_elasticache_security_group.bar.name}"]
254249
}
255-
`, genRandInt(), genRandInt(), genRandInt())
250+
`, acctest.RandInt(), acctest.RandInt(), acctest.RandString(10))
256251

257252
var testAccAWSElasticacheClusterConfig_snapshots = `
258253
provider "aws" {
@@ -276,7 +271,7 @@ resource "aws_elasticache_security_group" "bar" {
276271
}
277272
278273
resource "aws_elasticache_cluster" "bar" {
279-
cluster_id = "tf-test-%03d"
274+
cluster_id = "tf-%03d"
280275
engine = "redis"
281276
node_type = "cache.m1.small"
282277
num_cache_nodes = 1
@@ -310,7 +305,7 @@ resource "aws_elasticache_security_group" "bar" {
310305
}
311306
312307
resource "aws_elasticache_cluster" "bar" {
313-
cluster_id = "tf-test-%03d"
308+
cluster_id = "tf-%03d"
314309
engine = "redis"
315310
node_type = "cache.m1.small"
316311
num_cache_nodes = 1
@@ -345,7 +340,7 @@ resource "aws_elasticache_security_group" "bar" {
345340
}
346341
347342
resource "aws_elasticache_cluster" "bar" {
348-
cluster_id = "tf-test-%03d"
343+
cluster_id = "tf-%03d"
349344
engine = "memcached"
350345
node_type = "cache.m1.small"
351346
num_cache_nodes = 3
@@ -377,7 +372,7 @@ resource "aws_elasticache_security_group" "bar" {
377372
}
378373
379374
resource "aws_elasticache_cluster" "bar" {
380-
cluster_id = "tf-test-%03d"
375+
cluster_id = "tf-%03d"
381376
engine = "memcached"
382377
node_type = "cache.m1.small"
383378
num_cache_nodes = 1
@@ -427,7 +422,7 @@ resource "aws_elasticache_cluster" "bar" {
427422
// Including uppercase letters in this name to ensure
428423
// that we correctly handle the fact that the API
429424
// normalizes names to lowercase.
430-
cluster_id = "tf-TEST-%03d"
425+
cluster_id = "tf-%s"
431426
node_type = "cache.m1.small"
432427
num_cache_nodes = 1
433428
engine = "redis"
@@ -443,7 +438,7 @@ resource "aws_elasticache_cluster" "bar" {
443438
resource "aws_sns_topic" "topic_example" {
444439
name = "tf-ecache-cluster-test"
445440
}
446-
`, genRandInt(), genRandInt(), genRandInt())
441+
`, acctest.RandInt(), acctest.RandInt(), acctest.RandString(10))
447442

448443
var testAccAWSElasticacheClusterMultiAZInVPCConfig = fmt.Sprintf(`
449444
resource "aws_vpc" "foo" {
@@ -493,7 +488,7 @@ resource "aws_security_group" "bar" {
493488
}
494489
495490
resource "aws_elasticache_cluster" "bar" {
496-
cluster_id = "tf-test-%03d"
491+
cluster_id = "tf-%s"
497492
engine = "memcached"
498493
node_type = "cache.m1.small"
499494
num_cache_nodes = 2
@@ -507,4 +502,4 @@ resource "aws_elasticache_cluster" "bar" {
507502
"us-west-2b"
508503
]
509504
}
510-
`, genRandInt(), genRandInt(), genRandInt(), genRandInt(), genRandInt())
505+
`, acctest.RandInt(), acctest.RandInt(), acctest.RandInt(), acctest.RandInt(), acctest.RandString(10))

builtin/providers/aws/resource_aws_elasticache_security_group_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/aws/aws-sdk-go/aws"
88
"github.com/aws/aws-sdk-go/aws/awserr"
99
"github.com/aws/aws-sdk-go/service/elasticache"
10+
"github.com/hashicorp/terraform/helper/acctest"
1011
"github.com/hashicorp/terraform/helper/resource"
1112
"github.com/hashicorp/terraform/terraform"
1213
)
@@ -91,4 +92,4 @@ resource "aws_elasticache_security_group" "bar" {
9192
description = "tf-test-security-group-descr"
9293
security_group_names = ["${aws_security_group.bar.name}"]
9394
}
94-
`, genRandInt(), genRandInt())
95+
`, acctest.RandInt(), acctest.RandInt())

builtin/providers/aws/resource_aws_elasticache_subnet_group_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import (
77
"github.com/aws/aws-sdk-go/aws"
88
"github.com/aws/aws-sdk-go/aws/awserr"
99
"github.com/aws/aws-sdk-go/service/elasticache"
10+
"github.com/hashicorp/terraform/helper/acctest"
1011
"github.com/hashicorp/terraform/helper/resource"
1112
"github.com/hashicorp/terraform/terraform"
1213
)
1314

1415
func TestAccAWSElasticacheSubnetGroup_basic(t *testing.T) {
1516
var csg elasticache.CacheSubnetGroup
16-
config := fmt.Sprintf(testAccAWSElasticacheSubnetGroupConfig, genRandInt())
17+
config := fmt.Sprintf(testAccAWSElasticacheSubnetGroupConfig, acctest.RandInt())
1718

1819
resource.Test(t, resource.TestCase{
1920
PreCheck: func() { testAccPreCheck(t) },
@@ -33,7 +34,7 @@ func TestAccAWSElasticacheSubnetGroup_basic(t *testing.T) {
3334
func TestAccAWSElasticacheSubnetGroup_update(t *testing.T) {
3435
var csg elasticache.CacheSubnetGroup
3536
rn := "aws_elasticache_subnet_group.bar"
36-
ri := genRandInt()
37+
ri := acctest.RandInt()
3738
preConfig := fmt.Sprintf(testAccAWSElasticacheSubnetGroupUpdateConfigPre, ri)
3839
postConfig := fmt.Sprintf(testAccAWSElasticacheSubnetGroupUpdateConfigPost, ri)
3940

builtin/providers/aws/resource_aws_network_interface_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ resource "aws_subnet" "foo" {
333333
cidr_block = "172.16.10.0/24"
334334
availability_zone = "us-west-2a"
335335
tags {
336-
Name = "tf-eni-test"
336+
Name = "tf-foo-eni-test"
337337
}
338338
}
339339
@@ -342,7 +342,7 @@ resource "aws_subnet" "bar" {
342342
cidr_block = "172.16.11.0/24"
343343
availability_zone = "us-west-2a"
344344
tags {
345-
Name = "tf-eni-test"
345+
Name = "tf-bar-eni-test"
346346
}
347347
}
348348
@@ -359,7 +359,7 @@ resource "aws_instance" "foo" {
359359
associate_public_ip_address = false
360360
private_ip = "172.16.11.50"
361361
tags {
362-
Name = "tf-eni-test"
362+
Name = "foo-tf-eni-test"
363363
}
364364
}
365365

builtin/providers/aws/resource_aws_s3_bucket_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestAccAWSS3Bucket_Policy(t *testing.T) {
7474
}
7575

7676
func TestAccAWSS3Bucket_UpdateAcl(t *testing.T) {
77-
ri := genRandInt()
77+
ri := acctest.RandInt()
7878
preConfig := fmt.Sprintf(testAccAWSS3BucketConfigWithAcl, ri)
7979
postConfig := fmt.Sprintf(testAccAWSS3BucketConfigWithAclUpdate, ri)
8080

builtin/providers/aws/resource_aws_security_group_rule_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/aws/aws-sdk-go/aws"
1010
"github.com/aws/aws-sdk-go/aws/awserr"
1111
"github.com/aws/aws-sdk-go/service/ec2"
12+
"github.com/hashicorp/terraform/helper/acctest"
1213
"github.com/hashicorp/terraform/helper/resource"
1314
"github.com/hashicorp/terraform/terraform"
1415
)
@@ -750,7 +751,7 @@ var testAccAWSSecurityGroupRuleRace = func() string {
750751
name = "tf-sg-rule-race-group-%d"
751752
vpc_id = "${aws_vpc.default.id}"
752753
}
753-
`, genRandInt()))
754+
`, acctest.RandInt()))
754755
for i := 1; i < iterations; i++ {
755756
b.WriteString(fmt.Sprintf(`
756757
resource "aws_security_group_rule" "ingress%d" {

builtin/providers/azure/provider_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ package azure
33
import (
44
"io"
55
"io/ioutil"
6-
"math/rand"
76
"os"
87
"strings"
98
"testing"
10-
"time"
119

1210
"github.com/hashicorp/terraform/config"
1311
"github.com/hashicorp/terraform/helper/schema"
@@ -154,10 +152,6 @@ func TestAzure_providerConfigure(t *testing.T) {
154152
}
155153
}
156154

157-
func genRandInt() int {
158-
return rand.New(rand.NewSource(time.Now().UnixNano())).Int() % 100000
159-
}
160-
161155
// testAzurePublishSettingsStr is a revoked publishsettings file
162156
const testAzurePublishSettingsStr = `
163157
<?xml version="1.0" encoding="utf-8"?>

builtin/providers/azure/resource_azure_data_disk_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import (
77

88
"github.com/Azure/azure-sdk-for-go/management"
99
"github.com/Azure/azure-sdk-for-go/management/virtualmachinedisk"
10+
"github.com/hashicorp/terraform/helper/acctest"
1011
"github.com/hashicorp/terraform/helper/resource"
1112
"github.com/hashicorp/terraform/terraform"
1213
)
1314

1415
func TestAccAzureDataDisk_basic(t *testing.T) {
1516
var disk virtualmachinedisk.DataDiskResponse
16-
name := fmt.Sprintf("terraform-test%d", genRandInt())
17+
name := fmt.Sprintf("terraform-test%d", acctest.RandInt())
1718

1819
resource.Test(t, resource.TestCase{
1920
PreCheck: func() { testAccPreCheck(t) },
@@ -38,7 +39,7 @@ func TestAccAzureDataDisk_basic(t *testing.T) {
3839

3940
func TestAccAzureDataDisk_update(t *testing.T) {
4041
var disk virtualmachinedisk.DataDiskResponse
41-
name := fmt.Sprintf("terraform-test%d", genRandInt())
42+
name := fmt.Sprintf("terraform-test%d", acctest.RandInt())
4243

4344
resource.Test(t, resource.TestCase{
4445
PreCheck: func() { testAccPreCheck(t) },

builtin/providers/google/resource_sql_database_instance_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strconv"
1313
"testing"
1414

15+
"github.com/hashicorp/terraform/helper/acctest"
1516
"github.com/hashicorp/terraform/helper/resource"
1617
"github.com/hashicorp/terraform/terraform"
1718

@@ -20,7 +21,7 @@ import (
2021

2122
func TestAccGoogleSqlDatabaseInstance_basic(t *testing.T) {
2223
var instance sqladmin.DatabaseInstance
23-
databaseID := genRandInt()
24+
databaseID := acctest.RandInt()
2425

2526
resource.Test(t, resource.TestCase{
2627
PreCheck: func() { testAccPreCheck(t) },
@@ -64,7 +65,7 @@ func TestAccGoogleSqlDatabaseInstance_basic2(t *testing.T) {
6465

6566
func TestAccGoogleSqlDatabaseInstance_settings_basic(t *testing.T) {
6667
var instance sqladmin.DatabaseInstance
67-
databaseID := genRandInt()
68+
databaseID := acctest.RandInt()
6869

6970
resource.Test(t, resource.TestCase{
7071
PreCheck: func() { testAccPreCheck(t) },
@@ -87,7 +88,7 @@ func TestAccGoogleSqlDatabaseInstance_settings_basic(t *testing.T) {
8788

8889
func TestAccGoogleSqlDatabaseInstance_settings_upgrade(t *testing.T) {
8990
var instance sqladmin.DatabaseInstance
90-
databaseID := genRandInt()
91+
databaseID := acctest.RandInt()
9192

9293
resource.Test(t, resource.TestCase{
9394
PreCheck: func() { testAccPreCheck(t) },
@@ -120,7 +121,7 @@ func TestAccGoogleSqlDatabaseInstance_settings_upgrade(t *testing.T) {
120121

121122
func TestAccGoogleSqlDatabaseInstance_settings_downgrade(t *testing.T) {
122123
var instance sqladmin.DatabaseInstance
123-
databaseID := genRandInt()
124+
databaseID := acctest.RandInt()
124125

125126
resource.Test(t, resource.TestCase{
126127
PreCheck: func() { testAccPreCheck(t) },

0 commit comments

Comments
 (0)