本文整理匯總了Golang中github.com/hashicorp/terraform/helper/acctest.RandString函數的典型用法代碼示例。如果您正苦於以下問題:Golang RandString函數的具體用法?Golang RandString怎麽用?Golang RandString使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了RandString函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestAccInstanceGroupManager_importBasic
func TestAccInstanceGroupManager_importBasic(t *testing.T) {
resourceName1 := "google_compute_instance_group_manager.igm-basic"
resourceName2 := "google_compute_instance_group_manager.igm-no-tp"
template := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
target := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
igm1 := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
igm2 := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckInstanceGroupManagerDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccInstanceGroupManager_basic(template, target, igm1, igm2),
},
resource.TestStep{
ResourceName: resourceName1,
ImportState: true,
ImportStateVerify: true,
},
resource.TestStep{
ResourceName: resourceName2,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
示例2: testAccComputeInstance_subnet_xpn
func testAccComputeInstance_subnet_xpn(instance, xpn_host string) string {
return fmt.Sprintf(`
resource "google_compute_network" "inst-test-network" {
name = "inst-test-network-%s"
auto_create_subnetworks = false
project = "%s"
}
resource "google_compute_subnetwork" "inst-test-subnetwork" {
name = "inst-test-subnetwork-%s"
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
network = "${google_compute_network.inst-test-network.self_link}"
project = "%s"
}
resource "google_compute_instance" "foobar" {
name = "%s"
machine_type = "n1-standard-1"
zone = "us-central1-a"
disk {
image = "debian-8-jessie-v20160803"
}
network_interface {
subnetwork = "${google_compute_subnetwork.inst-test-subnetwork.name}"
subnetwork_project = "${google_compute_subnetwork.inst-test-subnetwork.project}"
access_config { }
}
}`, acctest.RandString(10), xpn_host, acctest.RandString(10), xpn_host, instance)
}
示例3: TestAccFastlyServiceV1_conditional_basic
func TestAccFastlyServiceV1_conditional_basic(t *testing.T) {
var service gofastly.ServiceDetail
name := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
domainName1 := fmt.Sprintf("%s.notadomain.com", acctest.RandString(10))
con1 := gofastly.Condition{
Name: "some amz condition",
Priority: 10,
Type: "REQUEST",
Statement: `req.url ~ "^/yolo/"`,
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckServiceV1Destroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccServiceV1ConditionConfig(name, domainName1),
Check: resource.ComposeTestCheckFunc(
testAccCheckServiceV1Exists("fastly_service_v1.foo", &service),
testAccCheckFastlyServiceV1ConditionalAttributes(&service, name, []*gofastly.Condition{&con1}),
resource.TestCheckResourceAttr(
"fastly_service_v1.foo", "name", name),
resource.TestCheckResourceAttr(
"fastly_service_v1.foo", "condition.#", "1"),
),
},
},
})
}
示例4: TestAccComputeBackendService_withCDNEnabled
func TestAccComputeBackendService_withCDNEnabled(t *testing.T) {
serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
var svc compute.BackendService
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeBackendServiceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeBackendService_withCDNEnabled(
serviceName, checkName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeBackendServiceExists(
"google_compute_backend_service.foobar", &svc),
),
},
},
})
if svc.EnableCDN != true {
t.Errorf("Expected EnableCDN == true, got %t", svc.EnableCDN)
}
}
示例5: TestAccComputeBackendService_withSessionAffinity
func TestAccComputeBackendService_withSessionAffinity(t *testing.T) {
serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
var svc compute.BackendService
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeBackendServiceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeBackendService_withSessionAffinity(
serviceName, checkName, "CLIENT_IP"),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeBackendServiceExists(
"google_compute_backend_service.foobar", &svc),
),
},
resource.TestStep{
Config: testAccComputeBackendService_withSessionAffinity(
serviceName, checkName, "GENERATED_COOKIE"),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeBackendServiceExists(
"google_compute_backend_service.foobar", &svc),
),
},
},
})
if svc.SessionAffinity != "GENERATED_COOKIE" {
t.Errorf("Expected SessionAffinity == \"GENERATED_COOKIE\", got %t", svc.SessionAffinity)
}
}
示例6: TestAccInstanceGroupManager_update
func TestAccInstanceGroupManager_update(t *testing.T) {
var manager compute.InstanceGroupManager
template1 := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
target := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
template2 := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
igm := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckInstanceGroupManagerDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccInstanceGroupManager_update(template1, target, igm),
Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceGroupManagerExists(
"google_compute_instance_group_manager.igm-update", &manager),
),
},
resource.TestStep{
Config: testAccInstanceGroupManager_update2(template1, target, template2, igm),
Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceGroupManagerExists(
"google_compute_instance_group_manager.igm-update", &manager),
testAccCheckInstanceGroupManagerUpdated(
"google_compute_instance_group_manager.igm-update", 3,
"google_compute_target_pool.igm-update", template2),
),
},
},
})
}
示例7: TestAccGoogleSqlUser_update
func TestAccGoogleSqlUser_update(t *testing.T) {
user := acctest.RandString(10)
instance := acctest.RandString(10)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccGoogleSqlUserDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testGoogleSqlUser_basic(instance, user),
Check: resource.ComposeTestCheckFunc(
testAccCheckGoogleSqlUserExists("google_sql_user.user"),
),
},
resource.TestStep{
Config: testGoogleSqlUser_basic2(instance, user),
Check: resource.ComposeTestCheckFunc(
testAccCheckGoogleSqlUserExists("google_sql_user.user"),
),
},
},
})
}
示例8: TestAccAWSWafSizeConstraintSet_changeNameForceNew
func TestAccAWSWafSizeConstraintSet_changeNameForceNew(t *testing.T) {
var before, after waf.SizeConstraintSet
sizeConstraintSet := fmt.Sprintf("sizeConstraintSet-%s", acctest.RandString(5))
sizeConstraintSetNewName := fmt.Sprintf("sizeConstraintSet-%s", acctest.RandString(5))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSWafSizeConstraintSetDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSWafSizeConstraintSetConfig(sizeConstraintSet),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSWafSizeConstraintSetExists("aws_waf_size_constraint_set.size_constraint_set", &before),
resource.TestCheckResourceAttr(
"aws_waf_size_constraint_set.size_constraint_set", "name", sizeConstraintSet),
resource.TestCheckResourceAttr(
"aws_waf_size_constraint_set.size_constraint_set", "size_constraints.#", "1"),
),
},
{
Config: testAccAWSWafSizeConstraintSetConfigChangeName(sizeConstraintSetNewName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSWafSizeConstraintSetExists("aws_waf_size_constraint_set.size_constraint_set", &after),
resource.TestCheckResourceAttr(
"aws_waf_size_constraint_set.size_constraint_set", "name", sizeConstraintSetNewName),
resource.TestCheckResourceAttr(
"aws_waf_size_constraint_set.size_constraint_set", "size_constraints.#", "1"),
),
},
},
})
}
示例9: TestAccAWSWafByteMatchSet_changeNameForceNew
func TestAccAWSWafByteMatchSet_changeNameForceNew(t *testing.T) {
var before, after waf.ByteMatchSet
byteMatchSet := fmt.Sprintf("byteMatchSet-%s", acctest.RandString(5))
byteMatchSetNewName := fmt.Sprintf("byteMatchSet-%s", acctest.RandString(5))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSWafByteMatchSetDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSWafByteMatchSetConfig(byteMatchSet),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSWafByteMatchSetExists("aws_waf_byte_match_set.byte_set", &before),
resource.TestCheckResourceAttr(
"aws_waf_byte_match_set.byte_set", "name", byteMatchSet),
resource.TestCheckResourceAttr(
"aws_waf_byte_match_set.byte_set", "byte_match_tuples.#", "2"),
),
},
{
Config: testAccAWSWafByteMatchSetConfigChangeName(byteMatchSetNewName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSWafByteMatchSetExists("aws_waf_byte_match_set.byte_set", &after),
resource.TestCheckResourceAttr(
"aws_waf_byte_match_set.byte_set", "name", byteMatchSetNewName),
resource.TestCheckResourceAttr(
"aws_waf_byte_match_set.byte_set", "byte_match_tuples.#", "2"),
),
},
},
})
}
示例10: TestAccFastlyServiceV1_updateBackend
func TestAccFastlyServiceV1_updateBackend(t *testing.T) {
var service gofastly.ServiceDetail
name := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
backendName := fmt.Sprintf("%s.aws.amazon.com", acctest.RandString(3))
backendName2 := fmt.Sprintf("%s.aws.amazon.com", acctest.RandString(3))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckServiceV1Destroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccServiceV1Config_backend(name, backendName),
Check: resource.ComposeTestCheckFunc(
testAccCheckServiceV1Exists("fastly_service_v1.foo", &service),
testAccCheckFastlyServiceV1Attributes_backends(&service, name, []string{backendName}),
),
},
resource.TestStep{
Config: testAccServiceV1Config_backend_update(name, backendName, backendName2),
Check: resource.ComposeTestCheckFunc(
testAccCheckServiceV1Exists("fastly_service_v1.foo", &service),
testAccCheckFastlyServiceV1Attributes_backends(&service, name, []string{backendName, backendName2}),
resource.TestCheckResourceAttr(
"fastly_service_v1.foo", "active_version", "2"),
resource.TestCheckResourceAttr(
"fastly_service_v1.foo", "backend.#", "2"),
),
},
},
})
}
示例11: TestAccFastlyServiceV1_basic
func TestAccFastlyServiceV1_basic(t *testing.T) {
var service gofastly.ServiceDetail
name := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
domainName := fmt.Sprintf("%s.notadomain.com", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckServiceV1Destroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccServiceV1Config(name, domainName),
Check: resource.ComposeTestCheckFunc(
testAccCheckServiceV1Exists("fastly_service_v1.foo", &service),
testAccCheckFastlyServiceV1Attributes(&service, name, []string{domainName}),
resource.TestCheckResourceAttr(
"fastly_service_v1.foo", "name", name),
resource.TestCheckResourceAttr(
"fastly_service_v1.foo", "active_version", "1"),
resource.TestCheckResourceAttr(
"fastly_service_v1.foo", "domain.#", "1"),
),
},
},
})
}
示例12: TestAccOpsGenieUserRole_validation
func TestAccOpsGenieUserRole_validation(t *testing.T) {
cases := []struct {
Value string
ErrCount int
}{
{
Value: "hello",
ErrCount: 0,
},
{
Value: acctest.RandString(100),
ErrCount: 0,
},
{
Value: acctest.RandString(511),
ErrCount: 0,
},
{
Value: acctest.RandString(512),
ErrCount: 1,
},
}
for _, tc := range cases {
_, errors := validateOpsGenieUserRole(tc.Value, "opsgenie_team")
if len(errors) != tc.ErrCount {
t.Fatalf("Expected the OpsGenie User Role Validation to trigger a validation error: %v", errors)
}
}
}
示例13: TestAccComputeTargetHttpProxy_update
func TestAccComputeTargetHttpProxy_update(t *testing.T) {
target := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
backend := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
hc := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
urlmap1 := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
urlmap2 := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeTargetHttpProxyDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeTargetHttpProxy_basic1(target, backend, hc, urlmap1, urlmap2),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeTargetHttpProxyExists(
"google_compute_target_http_proxy.foobar"),
),
},
resource.TestStep{
Config: testAccComputeTargetHttpProxy_basic2(target, backend, hc, urlmap1, urlmap2),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeTargetHttpProxyExists(
"google_compute_target_http_proxy.foobar"),
),
},
},
})
}
示例14: TestAccAWSAppautoScalingPolicy_basic
func TestAccAWSAppautoScalingPolicy_basic(t *testing.T) {
var policy applicationautoscaling.ScalingPolicy
randClusterName := fmt.Sprintf("cluster%s", acctest.RandString(10))
randPolicyName := fmt.Sprintf("terraform-test-foobar-%s", acctest.RandString(5))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAppautoscalingPolicyDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSAppautoscalingPolicyConfig(randClusterName, randPolicyName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAppautoscalingPolicyExists("aws_appautoscaling_policy.foobar_simple", &policy),
resource.TestCheckResourceAttr("aws_appautoscaling_policy.foobar_simple", "adjustment_type", "ChangeInCapacity"),
resource.TestCheckResourceAttr("aws_appautoscaling_policy.foobar_simple", "policy_type", "StepScaling"),
resource.TestCheckResourceAttr("aws_appautoscaling_policy.foobar_simple", "cooldown", "60"),
resource.TestCheckResourceAttr("aws_appautoscaling_policy.foobar_simple", "name", randPolicyName),
resource.TestCheckResourceAttr("aws_appautoscaling_policy.foobar_simple", "resource_id", fmt.Sprintf("service/%s/foobar", randClusterName)),
resource.TestCheckResourceAttr("aws_appautoscaling_policy.foobar_simple", "service_namespace", "ecs"),
resource.TestCheckResourceAttr("aws_appautoscaling_policy.foobar_simple", "scalable_dimension", "ecs:service:DesiredCount"),
),
},
},
})
}
示例15: TestAccComputeFirewall_update
func TestAccComputeFirewall_update(t *testing.T) {
var firewall compute.Firewall
networkName := fmt.Sprintf("firewall-test-%s", acctest.RandString(10))
firewallName := fmt.Sprintf("firewall-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeFirewallDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeFirewall_basic(networkName, firewallName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeFirewallExists(
"google_compute_firewall.foobar", &firewall),
),
},
resource.TestStep{
Config: testAccComputeFirewall_update(networkName, firewallName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeFirewallExists(
"google_compute_firewall.foobar", &firewall),
testAccCheckComputeFirewallPorts(
&firewall, "80-255"),
),
},
},
})
}