|
| 1 | +// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
| 2 | + |
| 3 | +package main |
| 4 | + |
| 5 | +import ( |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/MustWin/baremetal-sdk-go" |
| 9 | + "github.com/hashicorp/terraform/helper/resource" |
| 10 | + "github.com/hashicorp/terraform/helper/schema" |
| 11 | + "github.com/hashicorp/terraform/terraform" |
| 12 | + |
| 13 | + "github.com/stretchr/testify/suite" |
| 14 | +) |
| 15 | + |
| 16 | +type DatasourcePrivateIPTestSuite struct { |
| 17 | + suite.Suite |
| 18 | + Client *baremetal.Client |
| 19 | + Config string |
| 20 | + Provider terraform.ResourceProvider |
| 21 | + Providers map[string]terraform.ResourceProvider |
| 22 | + ResourceName string |
| 23 | + List *baremetal.ListPrivateIPs |
| 24 | +} |
| 25 | + |
| 26 | +func (s *DatasourcePrivateIPTestSuite) SetupTest() { |
| 27 | + s.Client = GetTestProvider() |
| 28 | + s.Provider = Provider(func(d *schema.ResourceData) (interface{}, error) { |
| 29 | + return s.Client, nil |
| 30 | + }) |
| 31 | + |
| 32 | + s.Providers = map[string]terraform.ResourceProvider{ |
| 33 | + "oci": s.Provider, |
| 34 | + } |
| 35 | + s.Config = vnicConfig + ` |
| 36 | +resource "oci_core_private_ip" "testPrivateIP" { |
| 37 | + vnic_id = "${lookup(data.oci_core_vnic_attachments.vnics.vnic_attachments[0],"vnic_id")}" |
| 38 | + ip_address = "10.0.1.23" |
| 39 | +} |
| 40 | + ` |
| 41 | + s.Config += testProviderConfig() |
| 42 | + s.ResourceName = "data.oci_core_private_ips.testPrivateIPs" |
| 43 | +} |
| 44 | + |
| 45 | +func (s *DatasourcePrivateIPTestSuite) TestListPrivateIPsByVnicID() { |
| 46 | + |
| 47 | + resource.UnitTest(s.T(), resource.TestCase{ |
| 48 | + PreventPostDestroyRefresh: true, |
| 49 | + Providers: s.Providers, |
| 50 | + Steps: []resource.TestStep{ |
| 51 | + { |
| 52 | + ImportState: true, |
| 53 | + ImportStateVerify: true, |
| 54 | + Config: s.Config, |
| 55 | + }, |
| 56 | + { |
| 57 | + Config: s.Config + ` |
| 58 | +data "oci_core_private_ips" "testPrivateIPs" { |
| 59 | + vnic_id = "${lookup(data.oci_core_vnic_attachments.vnics.vnic_attachments[0],"vnic_id")}" |
| 60 | +} |
| 61 | + `, |
| 62 | + Check: resource.ComposeTestCheckFunc( |
| 63 | + resource.TestCheckResourceAttr(s.ResourceName, "private_ips.#", "2"), |
| 64 | + resource.TestCheckResourceAttrSet(s.ResourceName, "private_ips.0.id"), |
| 65 | + resource.TestCheckResourceAttrSet(s.ResourceName, "private_ips.1.id"), |
| 66 | + ), |
| 67 | + }, |
| 68 | + }, |
| 69 | + }, |
| 70 | + ) |
| 71 | +} |
| 72 | + |
| 73 | +func (s *DatasourcePrivateIPTestSuite) TestListPrivateIPsBySubnetID() { |
| 74 | + |
| 75 | + resource.UnitTest(s.T(), resource.TestCase{ |
| 76 | + PreventPostDestroyRefresh: true, |
| 77 | + Providers: s.Providers, |
| 78 | + Steps: []resource.TestStep{ |
| 79 | + { |
| 80 | + ImportState: true, |
| 81 | + ImportStateVerify: true, |
| 82 | + Config: s.Config, |
| 83 | + }, |
| 84 | + { |
| 85 | + Config: s.Config + ` |
| 86 | +data "oci_core_private_ips" "testPrivateIPs" { |
| 87 | + subnet_id = "${oci_core_subnet.WebSubnetAD1.id}" |
| 88 | +} |
| 89 | + `, |
| 90 | + Check: resource.ComposeTestCheckFunc( |
| 91 | + resource.TestCheckResourceAttr(s.ResourceName, "private_ips.#", "2"), |
| 92 | + resource.TestCheckResourceAttrSet(s.ResourceName, "private_ips.0.id"), |
| 93 | + resource.TestCheckResourceAttrSet(s.ResourceName, "private_ips.1.id"), |
| 94 | + ), |
| 95 | + }, |
| 96 | + }, |
| 97 | + }, |
| 98 | + ) |
| 99 | +} |
| 100 | + |
| 101 | +func (s *DatasourcePrivateIPTestSuite) TestListPrivateIPsByIPAddress() { |
| 102 | + |
| 103 | + resource.UnitTest(s.T(), resource.TestCase{ |
| 104 | + PreventPostDestroyRefresh: true, |
| 105 | + Providers: s.Providers, |
| 106 | + Steps: []resource.TestStep{ |
| 107 | + { |
| 108 | + ImportState: true, |
| 109 | + ImportStateVerify: true, |
| 110 | + Config: s.Config, |
| 111 | + }, |
| 112 | + { |
| 113 | + Config: s.Config + ` |
| 114 | +data "oci_core_private_ips" "testPrivateIPs" { |
| 115 | + ip_address = "10.0.1.23" |
| 116 | + subnet_id = "${oci_core_subnet.WebSubnetAD1.id}" |
| 117 | +} |
| 118 | + `, |
| 119 | + Check: resource.ComposeTestCheckFunc( |
| 120 | + resource.TestCheckResourceAttrSet(s.ResourceName, "private_ips.0.id"), |
| 121 | + resource.TestCheckResourceAttr(s.ResourceName, "private_ips.0.ip_address", "10.0.1.23"), |
| 122 | + resource.TestCheckResourceAttr(s.ResourceName, "private_ips.#", "1"), |
| 123 | + ), |
| 124 | + }, |
| 125 | + }, |
| 126 | + }, |
| 127 | + ) |
| 128 | +} |
| 129 | + |
| 130 | +func TestDatasourcePrivateIPTestSuite(t *testing.T) { |
| 131 | + suite.Run(t, new(DatasourcePrivateIPTestSuite)) |
| 132 | +} |
0 commit comments