|
| 1 | +//go:build integration || producerimagesharegroupmember |
| 2 | + |
| 3 | +package producerimagesharegroupmember_test |
| 4 | + |
| 5 | +import ( |
| 6 | + "os" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/hashicorp/terraform-plugin-go/tfprotov6" |
| 10 | + "github.com/hashicorp/terraform-plugin-testing/helper/acctest" |
| 11 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 12 | + "github.com/linode/terraform-provider-linode/v3/linode/acceptance" |
| 13 | + "github.com/linode/terraform-provider-linode/v3/linode/producerimagesharegroupmember/tmpl" |
| 14 | +) |
| 15 | + |
| 16 | +// This test requires two separate Linode API tokens, one for the producer |
| 17 | +// and one for the consumer. |
| 18 | +// |
| 19 | +// These can be set using the LINODE_PRODUCER_TOKEN and LINODE_CONSUMER_TOKEN |
| 20 | +// environment variables. |
| 21 | +// |
| 22 | +// If either is not set,the test will fail. |
| 23 | +func TestAccResourceImageShareGroupMember_basic(t *testing.T) { |
| 24 | + t.Parallel() |
| 25 | + |
| 26 | + producerToken := os.Getenv("LINODE_PRODUCER_TOKEN") |
| 27 | + consumerToken := os.Getenv("LINODE_CONSUMER_TOKEN") |
| 28 | + |
| 29 | + if producerToken == "" || consumerToken == "" { |
| 30 | + t.Skip("Skipping test: both LINODE_PRODUCER_TOKEN and LINODE_CONSUMER_TOKEN must be set") |
| 31 | + } |
| 32 | + |
| 33 | + producerClient, err := acceptance.GetTestClientAlternateToken("LINODE_PRODUCER_TOKEN") |
| 34 | + if err != nil { |
| 35 | + t.Fatalf("Failed to create producer client: %s", err) |
| 36 | + } |
| 37 | + |
| 38 | + consumerClient, err := acceptance.GetTestClientAlternateToken("LINODE_CONSUMER_TOKEN") |
| 39 | + if err != nil { |
| 40 | + t.Fatalf("Failed to create consumer client: %s", err) |
| 41 | + } |
| 42 | + |
| 43 | + producerProvider := acceptance.NewFrameworkProviderWithClient(producerClient) |
| 44 | + consumerProvider := acceptance.NewFrameworkProviderWithClient(consumerClient) |
| 45 | + |
| 46 | + resourceName := "linode_producer_image_share_group_member.foobar" |
| 47 | + shareGroupLabel := acctest.RandomWithPrefix("tf-test") |
| 48 | + tokenLabel := acctest.RandomWithPrefix("tf-test") |
| 49 | + memberLabel := acctest.RandomWithPrefix("tf-test") |
| 50 | + memberLabelUpdated := memberLabel + "-updated" |
| 51 | + |
| 52 | + resource.Test(t, resource.TestCase{ |
| 53 | + PreCheck: func() { acceptance.PreCheck(t) }, |
| 54 | + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ |
| 55 | + "linode-producer": func() (tfprotov6.ProviderServer, error) { |
| 56 | + return acceptance.ProtoV6CustomProviderFactories["linode"](producerProvider) |
| 57 | + }, |
| 58 | + "linode-consumer": func() (tfprotov6.ProviderServer, error) { |
| 59 | + return acceptance.ProtoV6CustomProviderFactories["linode"](consumerProvider) |
| 60 | + }, |
| 61 | + }, |
| 62 | + Steps: []resource.TestStep{ |
| 63 | + { |
| 64 | + Config: tmpl.Basic(t, shareGroupLabel, tokenLabel, memberLabel), |
| 65 | + Check: resource.ComposeTestCheckFunc( |
| 66 | + resource.TestCheckResourceAttrSet(resourceName, "sharegroup_id"), |
| 67 | + resource.TestCheckResourceAttrSet(resourceName, "token"), |
| 68 | + resource.TestCheckResourceAttrSet(resourceName, "token_uuid"), |
| 69 | + resource.TestCheckResourceAttrSet(resourceName, "status"), |
| 70 | + resource.TestCheckResourceAttr(resourceName, "label", memberLabel), |
| 71 | + ), |
| 72 | + }, |
| 73 | + { |
| 74 | + Config: tmpl.Basic(t, shareGroupLabel, tokenLabel, memberLabelUpdated), |
| 75 | + Check: resource.ComposeTestCheckFunc( |
| 76 | + resource.TestCheckResourceAttrSet(resourceName, "sharegroup_id"), |
| 77 | + resource.TestCheckResourceAttrSet(resourceName, "token"), |
| 78 | + resource.TestCheckResourceAttrSet(resourceName, "token_uuid"), |
| 79 | + resource.TestCheckResourceAttrSet(resourceName, "status"), |
| 80 | + resource.TestCheckResourceAttr(resourceName, "label", memberLabelUpdated), |
| 81 | + ), |
| 82 | + }, |
| 83 | + }, |
| 84 | + }) |
| 85 | +} |
0 commit comments