|
1 | 1 | package acctest
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "fmt" |
5 |
| - "math/rand" |
6 |
| - "os" |
7 |
| - "testing" |
| 4 | + "fmt" |
| 5 | + "math/rand" |
| 6 | + "os" |
| 7 | + "testing" |
8 | 8 |
|
9 |
| - "github.com/hashicorp/terraform-plugin-framework/providerserver" |
10 |
| - "github.com/hashicorp/terraform-plugin-go/tfprotov6" |
11 |
| - "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 9 | + "github.com/hashicorp/terraform-plugin-framework/providerserver" |
| 10 | + "github.com/hashicorp/terraform-plugin-go/tfprotov6" |
| 11 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
12 | 12 |
|
13 |
| - bloxoneclient "github.com/infobloxopen/bloxone-go-client/client" |
14 |
| - "github.com/infobloxopen/bloxone-go-client/option" |
15 |
| - "github.com/infobloxopen/terraform-provider-bloxone/internal/provider" |
| 13 | + bloxoneclient "github.com/infobloxopen/bloxone-go-client/client" |
| 14 | + "github.com/infobloxopen/bloxone-go-client/option" |
| 15 | + "github.com/infobloxopen/terraform-provider-bloxone/internal/provider" |
16 | 16 | )
|
17 | 17 |
|
18 | 18 | const (
|
19 |
| - letterBytes = "abcdefghijklmnopqrstuvwxyz" |
20 |
| - defaultKey = "managed_by" |
21 |
| - defaultValue = "terraform" |
| 19 | + letterBytes = "abcdefghijklmnopqrstuvwxyz" |
| 20 | + defaultKey = "managed_by" |
| 21 | + defaultValue = "terraform" |
22 | 22 | )
|
23 | 23 |
|
24 | 24 | var (
|
25 |
| - // BloxOneClient will be used to do verification tests |
26 |
| - BloxOneClient *bloxoneclient.APIClient |
| 25 | + // BloxOneClient will be used to do verification tests |
| 26 | + BloxOneClient *bloxoneclient.APIClient |
27 | 27 |
|
28 |
| - // ProtoV6ProviderFactories are used to instantiate a provider during |
29 |
| - // acceptance testing. The factory function will be invoked for every Terraform |
30 |
| - // CLI command executed to create a provider server to which the CLI can |
31 |
| - // reattach. |
32 |
| - ProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){ |
33 |
| - "bloxone": providerserver.NewProtocol6WithError(provider.New("test", "test")()), |
34 |
| - } |
35 |
| - ProtoV6ProviderFactoriesWithTags = map[string]func() (tfprotov6.ProviderServer, error){ |
36 |
| - "bloxone": providerserver.NewProtocol6WithError(provider.NewWithTags(map[string]string{defaultKey: defaultValue})()), |
37 |
| - } |
| 28 | + // ProtoV6ProviderFactories are used to instantiate a provider during |
| 29 | + // acceptance testing. The factory function will be invoked for every Terraform |
| 30 | + // CLI command executed to create a provider server to which the CLI can |
| 31 | + // reattach. |
| 32 | + ProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){ |
| 33 | + "bloxone": providerserver.NewProtocol6WithError(provider.New("test", "test")()), |
| 34 | + } |
| 35 | + ProtoV6ProviderFactoriesWithTags = map[string]func() (tfprotov6.ProviderServer, error){ |
| 36 | + "bloxone": providerserver.NewProtocol6WithError(provider.NewWithTags(map[string]string{defaultKey: defaultValue})()), |
| 37 | + } |
38 | 38 | )
|
39 | 39 |
|
40 | 40 | // RandomNameWithPrefix generates a random name with the given prefix.
|
41 | 41 | // This is used in the acceptance tests where a unique name is required for the resource.
|
42 | 42 | func RandomNameWithPrefix(prefix string) string {
|
43 |
| - return fmt.Sprintf("%s-%s", prefix, RandomName()) |
| 43 | + return fmt.Sprintf("%s-%s", prefix, RandomName()) |
44 | 44 | }
|
45 | 45 |
|
46 | 46 | func RandomIP() string {
|
47 |
| - return fmt.Sprintf("%d.%d.%d.%d", rand.Intn(255), rand.Intn(255), rand.Intn(255), rand.Intn(255)) |
| 47 | + return fmt.Sprintf("%d.%d.%d.%d", rand.Intn(255), rand.Intn(255), rand.Intn(255), rand.Intn(255)) |
48 | 48 | }
|
49 | 49 |
|
50 | 50 | func RandomName() string {
|
51 |
| - b := make([]byte, 6) |
52 |
| - for i := range b { |
53 |
| - b[i] = letterBytes[rand.Intn(len(letterBytes))] |
54 |
| - } |
55 |
| - return string(b) |
| 51 | + b := make([]byte, 6) |
| 52 | + for i := range b { |
| 53 | + b[i] = letterBytes[rand.Intn(len(letterBytes))] |
| 54 | + } |
| 55 | + return string(b) |
56 | 56 | }
|
57 | 57 |
|
58 | 58 | func PreCheck(t *testing.T) {
|
59 |
| - cspURL := os.Getenv("BLOXONE_CSP_URL") |
60 |
| - if cspURL == "" { |
61 |
| - t.Fatal("BLOXONE_CSP_URL must be set for acceptance tests") |
62 |
| - } |
| 59 | + cspURL := os.Getenv("BLOXONE_CSP_URL") |
| 60 | + if cspURL == "" { |
| 61 | + t.Fatal("BLOXONE_CSP_URL must be set for acceptance tests") |
| 62 | + } |
63 | 63 |
|
64 |
| - apiKey := os.Getenv("BLOXONE_API_KEY") |
65 |
| - if apiKey == "" { |
66 |
| - t.Fatal("BLOXONE_API_KEY must be set for acceptance tests") |
67 |
| - } |
| 64 | + apiKey := os.Getenv("BLOXONE_API_KEY") |
| 65 | + if apiKey == "" { |
| 66 | + t.Fatal("BLOXONE_API_KEY must be set for acceptance tests") |
| 67 | + } |
68 | 68 |
|
69 |
| - BloxOneClient = bloxoneclient.NewAPIClient( |
70 |
| - option.WithClientName("terraform-acceptance-tests"), |
71 |
| - option.WithCSPUrl(cspURL), |
72 |
| - option.WithAPIKey(apiKey), |
73 |
| - option.WithDebug(true), |
74 |
| - ) |
| 69 | + BloxOneClient = bloxoneclient.NewAPIClient( |
| 70 | + option.WithClientName("terraform-acceptance-tests"), |
| 71 | + option.WithCSPUrl(cspURL), |
| 72 | + option.WithAPIKey(apiKey), |
| 73 | + option.WithDebug(true), |
| 74 | + ) |
75 | 75 | }
|
76 | 76 |
|
77 | 77 | func VerifyDefaultTag(resourceName string) resource.TestCheckFunc {
|
78 |
| - return resource.TestCheckResourceAttr(resourceName, fmt.Sprintf("tags_all.%s", defaultKey), defaultValue) |
| 78 | + return resource.TestCheckResourceAttr(resourceName, fmt.Sprintf("tags_all.%s", defaultKey), defaultValue) |
79 | 79 | }
|
80 | 80 |
|
81 | 81 | // TestAccBase_DhcpHosts creates a Terraform datasource config that allows you to filter by tags
|
82 | 82 | func TestAccBase_DhcpHosts() string {
|
83 |
| - return ` |
| 83 | + return ` |
84 | 84 | data "bloxone_dhcp_hosts" "test" {
|
85 | 85 | tag_filters = {
|
86 | 86 | used_for = "Terraform Provider Acceptance Tests"
|
|
0 commit comments