forked from oracle/terraform-provider-oci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_balancers_datasource_test.go
70 lines (61 loc) · 2.02 KB
/
load_balancers_datasource_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
package main
import (
"testing"
"time"
"github.com/MustWin/baremetal-sdk-go"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"github.com/oracle/terraform-provider-baremetal/client/mocks"
)
func TestLoadBalancersDatasource(t *testing.T) {
client := &mocks.BareMetalClient{}
provider := Provider(func(d *schema.ResourceData) (interface{}, error) {
return client, nil
})
providers := map[string]terraform.ResourceProvider{
"baremetal": provider,
}
resourceName := "data.baremetal_load_balancers.t"
config := `
data "baremetal_load_balancers" "t" {
compartment_id = "ocid1.compartment.stub_id"
}
`
config += testProviderConfig
compartmentID := "ocid1.compartment.stub_id"
lb1 := baremetal.LoadBalancer{
CompartmentID: compartmentID,
ID: "ocid1.loadbalancer.stub_id1",
IPAddresses: []baremetal.IPAddress{{IPAddress: "1.2.3.4"}},
Shape: "stub_shape",
State: baremetal.ResourceActive,
TimeCreated: baremetal.Time{Time: time.Now()}, // FIXME: use baremetal.Time
}
lb2 := lb1
lb2.ID = "ocid1.loadbalancer.stub_id2"
list := &baremetal.ListLoadBalancers{
LoadBalancers: []baremetal.LoadBalancer{lb1, lb2},
}
client.On(
"ListLoadBalancers",
compartmentID,
(*baremetal.ListOptions)(nil),
).Return(list, nil)
resource.UnitTest(t, resource.TestCase{
PreventPostDestroyRefresh: true,
Providers: providers,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentID),
resource.TestCheckResourceAttr(resourceName, "load_balancers.#", "2"),
resource.TestCheckResourceAttr(resourceName, "load_balancers.0.id", "ocid1.loadbalancer.stub_id1"),
resource.TestCheckResourceAttr(resourceName, "load_balancers.1.id", "ocid1.loadbalancer.stub_id2"),
),
},
},
})
}