@@ -19,26 +19,29 @@ type DatasourcePrivateIPTestSuite struct {
1919 Provider terraform.ResourceProvider
2020 Providers map [string ]terraform.ResourceProvider
2121 ResourceName string
22- List * baremetal.ListPrivateIPs
2322}
2423
2524func (s * DatasourcePrivateIPTestSuite ) SetupTest () {
2625 s .Client = testAccClient
2726 s .Provider = testAccProvider
2827 s .Providers = testAccProviders
29- s .Config = vnicConfig + `
30- resource "oci_core_private_ip" "testPrivateIP" {
31- vnic_id = "${lookup(data.oci_core_vnic_attachments.vnics.vnic_attachments[0],"vnic_id")}"
32- ip_address = "10.0.1.23"
33- }
34- `
35- s .Config += testProviderConfig ()
36- s .ResourceName = "data.oci_core_private_ips.testPrivateIPs"
37- }
28+ s .Config = testProvider1 () + testADs () + testVCN1 () + testSubnet1 () + testImage1 () + testInstance1 () + `
29+ data "oci_core_vnic_attachments" "t" {
30+ compartment_id = "${var.compartment_ocid}"
31+ availability_domain = "${data.oci_identity_availability_domains.t.availability_domains.0.name}"
32+ instance_id = "${oci_core_instance.t.id}"
33+ }
34+
35+ resource "oci_core_private_ip" "t" {
36+ vnic_id = "${lookup(data.oci_core_vnic_attachments.t.vnic_attachments[0], "vnic_id")}"
37+ ip_address = "10.0.1.23"
38+ }`
3839
39- func (s * DatasourcePrivateIPTestSuite ) TestListPrivateIPsByVnicID () {
40+ s .ResourceName = "data.oci_core_private_ips.t"
41+ }
4042
41- resource .UnitTest (s .T (), resource.TestCase {
43+ func (s * DatasourcePrivateIPTestSuite ) TestAccCorePrivateIPs_basic () {
44+ resource .Test (s .T (), resource.TestCase {
4245 PreventPostDestroyRefresh : true ,
4346 Providers : s .Providers ,
4447 Steps : []resource.TestStep {
@@ -47,80 +50,48 @@ func (s *DatasourcePrivateIPTestSuite) TestListPrivateIPsByVnicID() {
4750 ImportStateVerify : true ,
4851 Config : s .Config ,
4952 },
53+ // list by ip address
5054 {
5155 Config : s .Config + `
52- data "oci_core_private_ips" "testPrivateIPs " {
53- vnic_id = "${lookup(data.oci_core_vnic_attachments.vnics.vnic_attachments[0],"vnic_id")} "
54- }
55- ` ,
56+ data "oci_core_private_ips" "t " {
57+ ip_address = "10.0.1.23 "
58+ subnet_id = "${oci_core_subnet.t.id}"
59+ } ` ,
5660 Check : resource .ComposeTestCheckFunc (
57- resource .TestCheckResourceAttr (s .ResourceName , "private_ips.#" , "2" ),
5861 resource .TestCheckResourceAttrSet (s .ResourceName , "private_ips.0.id" ),
59- resource .TestCheckResourceAttrSet (s .ResourceName , "private_ips.1.id" ),
62+ resource .TestCheckResourceAttr (s .ResourceName , "private_ips.#" , "1" ),
63+ resource .TestCheckResourceAttr (s .ResourceName , "private_ips.0.ip_address" , "10.0.1.23" ),
6064 ),
6165 },
62- },
63- },
64- )
65- }
66-
67- func (s * DatasourcePrivateIPTestSuite ) TestListPrivateIPsBySubnetID () {
68-
69- resource .UnitTest (s .T (), resource.TestCase {
70- PreventPostDestroyRefresh : true ,
71- Providers : s .Providers ,
72- Steps : []resource.TestStep {
73- {
74- ImportState : true ,
75- ImportStateVerify : true ,
76- Config : s .Config ,
77- },
66+ // list by vnic id
7867 {
7968 Config : s .Config + `
80- data "oci_core_private_ips" "testPrivateIPs" {
81- subnet_id = "${oci_core_subnet.WebSubnetAD1.id}"
82- }
83- ` ,
69+ data "oci_core_private_ips" "t" {
70+ vnic_id = "${lookup(data.oci_core_vnic_attachments.t.vnic_attachments[0],"vnic_id")}"
71+ }` ,
8472 Check : resource .ComposeTestCheckFunc (
8573 resource .TestCheckResourceAttr (s .ResourceName , "private_ips.#" , "2" ),
8674 resource .TestCheckResourceAttrSet (s .ResourceName , "private_ips.0.id" ),
8775 resource .TestCheckResourceAttrSet (s .ResourceName , "private_ips.1.id" ),
8876 ),
8977 },
90- },
91- },
92- )
93- }
94-
95- func (s * DatasourcePrivateIPTestSuite ) TestListPrivateIPsByIPAddress () {
96-
97- resource .UnitTest (s .T (), resource.TestCase {
98- PreventPostDestroyRefresh : true ,
99- Providers : s .Providers ,
100- Steps : []resource.TestStep {
101- {
102- ImportState : true ,
103- ImportStateVerify : true ,
104- Config : s .Config ,
105- },
78+ // list by subnet id
10679 {
10780 Config : s .Config + `
108- data "oci_core_private_ips" "testPrivateIPs" {
109- ip_address = "10.0.1.23"
110- subnet_id = "${oci_core_subnet.WebSubnetAD1.id}"
111- }
112- ` ,
81+ data "oci_core_private_ips" "t" {
82+ subnet_id = "${oci_core_subnet.t.id}"
83+ }` ,
11384 Check : resource .ComposeTestCheckFunc (
85+ resource .TestCheckResourceAttr (s .ResourceName , "private_ips.#" , "2" ),
11486 resource .TestCheckResourceAttrSet (s .ResourceName , "private_ips.0.id" ),
115- resource .TestCheckResourceAttr (s .ResourceName , "private_ips.0.ip_address" , "10.0.1.23" ),
116- resource .TestCheckResourceAttr (s .ResourceName , "private_ips.#" , "1" ),
87+ resource .TestCheckResourceAttrSet (s .ResourceName , "private_ips.1.id" ),
11788 ),
11889 },
11990 },
12091 },
12192 )
12293}
12394
124- func TestDatasourcePrivateIPTestSuite (t * testing.T ) {
95+ func TestDatasourceCorePrivateIPTestSuite (t * testing.T ) {
12596 suite .Run (t , new (DatasourcePrivateIPTestSuite ))
12697}
0 commit comments