|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | + |
| 4 | +package odb_test |
| 5 | + |
| 6 | +import ( |
| 7 | + "context" |
| 8 | + "errors" |
| 9 | + "fmt" |
| 10 | + "github.com/hashicorp/terraform-plugin-testing/terraform" |
| 11 | + "github.com/hashicorp/terraform-provider-aws/internal/create" |
| 12 | + tfodb "github.com/hashicorp/terraform-provider-aws/internal/service/odb" |
| 13 | + "strconv" |
| 14 | + "testing" |
| 15 | + |
| 16 | + "github.com/aws/aws-sdk-go-v2/service/odb" |
| 17 | + |
| 18 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 19 | + |
| 20 | + "github.com/hashicorp/terraform-provider-aws/internal/acctest" |
| 21 | + "github.com/hashicorp/terraform-provider-aws/internal/conns" |
| 22 | + |
| 23 | + "github.com/hashicorp/terraform-provider-aws/names" |
| 24 | +) |
| 25 | + |
| 26 | +type listExaInfraTest struct { |
| 27 | +} |
| 28 | + |
| 29 | +func TestAccODBCloudExadataInfrastructuresListDataSource_basic(t *testing.T) { |
| 30 | + ctx := acctest.Context(t) |
| 31 | + var listExaInfraDSTest = listExaInfraTest{} |
| 32 | + var infraList odb.ListCloudExadataInfrastructuresOutput |
| 33 | + |
| 34 | + dataSourceName := "data.aws_odb_cloud_exadata_infrastructures_list.test" |
| 35 | + resource.Test(t, resource.TestCase{ |
| 36 | + PreCheck: func() { |
| 37 | + acctest.PreCheck(ctx, t) |
| 38 | + listExaInfraDSTest.testAccPreCheck(ctx, t) |
| 39 | + }, |
| 40 | + ErrorCheck: acctest.ErrorCheck(t, names.ODBServiceID), |
| 41 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, |
| 42 | + Steps: []resource.TestStep{ |
| 43 | + { |
| 44 | + Config: listExaInfraDSTest.basic(), |
| 45 | + Check: resource.ComposeAggregateTestCheckFunc( |
| 46 | + |
| 47 | + resource.ComposeTestCheckFunc(func(s *terraform.State) error { |
| 48 | + listExaInfraDSTest.countExaInfrastructures(ctx, dataSourceName, &infraList) |
| 49 | + resource.TestCheckResourceAttr(dataSourceName, "cloud_exadata_infrastructures.#", strconv.Itoa(len(infraList.CloudExadataInfrastructures))) |
| 50 | + return nil |
| 51 | + }, |
| 52 | + ), |
| 53 | + ), |
| 54 | + }, |
| 55 | + }, |
| 56 | + }) |
| 57 | +} |
| 58 | + |
| 59 | +func (listExaInfraTest) basic() string { |
| 60 | + config := fmt.Sprintf(` |
| 61 | +
|
| 62 | +
|
| 63 | +data "aws_odb_cloud_exadata_infrastructures_list" "test" { |
| 64 | +
|
| 65 | +} |
| 66 | +`) |
| 67 | + return config |
| 68 | +} |
| 69 | + |
| 70 | +/*func (listExaInfraTest) countExaInfrastructures(ctx context.Context, t *testing.T, exaInfraDatalistTest *listExaInfraTest) int { |
| 71 | + conn := acctest.Provider.Meta().(*conns.AWSClient).ODBClient(ctx) |
| 72 | +
|
| 73 | + input := &odb.ListCloudExadataInfrastructuresInput{} |
| 74 | +
|
| 75 | + out, err := conn.ListCloudExadataInfrastructures(ctx, input) |
| 76 | +
|
| 77 | + if acctest.PreCheckSkipError(err) { |
| 78 | + t.Skipf("skipping acceptance testing: %s", err) |
| 79 | + } |
| 80 | + if err != nil { |
| 81 | + t.Fatalf("unexpected PreCheck error: %s", err) |
| 82 | + } |
| 83 | + exaInfraDatalistTest.count = len(out.CloudExadataInfrastructures) |
| 84 | + fmt.Println("----------", exaInfraDatalistTest.count) |
| 85 | + return len(out.CloudExadataInfrastructures) |
| 86 | +}*/ |
| 87 | + |
| 88 | +func (listExaInfraTest) countExaInfrastructures(ctx context.Context, name string, listOfInfra *odb.ListCloudExadataInfrastructuresOutput) resource.TestCheckFunc { |
| 89 | + return func(s *terraform.State) error { |
| 90 | + rs, ok := s.RootModule().Resources[name] |
| 91 | + if !ok { |
| 92 | + return create.Error(names.ODB, create.ErrActionCheckingExistence, tfodb.ResNameCloudVmCluster, name, errors.New("not found")) |
| 93 | + } |
| 94 | + |
| 95 | + conn := acctest.Provider.Meta().(*conns.AWSClient).ODBClient(ctx) |
| 96 | + |
| 97 | + resp, err := conn.ListCloudExadataInfrastructures(ctx, &odb.ListCloudExadataInfrastructuresInput{}) |
| 98 | + if err != nil { |
| 99 | + return create.Error(names.ODB, create.ErrActionCheckingExistence, tfodb.ResNameCloudVmCluster, rs.Primary.ID, err) |
| 100 | + } |
| 101 | + |
| 102 | + listOfInfra.CloudExadataInfrastructures = resp.CloudExadataInfrastructures |
| 103 | + |
| 104 | + return nil |
| 105 | + } |
| 106 | +} |
| 107 | +func (listExaInfraTest) testAccPreCheck(ctx context.Context, t *testing.T) { |
| 108 | + conn := acctest.Provider.Meta().(*conns.AWSClient).ODBClient(ctx) |
| 109 | + |
| 110 | + input := &odb.ListCloudAutonomousVmClustersInput{} |
| 111 | + |
| 112 | + _, err := conn.ListCloudAutonomousVmClusters(ctx, input) |
| 113 | + |
| 114 | + if acctest.PreCheckSkipError(err) { |
| 115 | + t.Skipf("skipping acceptance testing: %s", err) |
| 116 | + } |
| 117 | + if err != nil { |
| 118 | + t.Fatalf("unexpected PreCheck error: %s", err) |
| 119 | + } |
| 120 | +} |
0 commit comments