forked from oracle/terraform-provider-oci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadbalancer_certificate_resource_test.go
133 lines (115 loc) · 3.7 KB
/
loadbalancer_certificate_resource_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// 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/stretchr/testify/suite"
"github.com/oracle/terraform-provider-baremetal/client/mocks"
)
type ResourceLoadBalancerCertificateTestSuite struct {
suite.Suite
Client *mocks.BareMetalClient
Providers map[string]terraform.ResourceProvider
TimeCreated baremetal.Time
}
func (s *ResourceLoadBalancerCertificateTestSuite) SetupTest() {
s.Client = &mocks.BareMetalClient{}
s.Providers = map[string]terraform.ResourceProvider{
"baremetal": Provider(
func(d *schema.ResourceData) (interface{}, error) {
return s.Client, nil
},
),
}
s.TimeCreated = baremetal.Time{Time: time.Now()}
}
func (s *ResourceLoadBalancerCertificateTestSuite) TestCreateResourceLoadBalancerCertificateMaximal() {
resourceName := "baremetal_load_balancer_certificate.t"
config := `
resource "baremetal_load_balancer_certificate" "t" {
load_balancer_id = "ocid1.loadbalancer.stub_id"
ca_certificate = "stub_ca_certificate"
certificate_name = "stub_certificate_name"
passphrase = "stub_passphrase"
private_key = "stub_private_key"
public_certificate = "stub_public_certificate"
}
`
config += testProviderConfig
loadBalancerID := "ocid1.loadbalancer.stub_id"
res := &baremetal.Certificate{
CACertificate: "stub_ca_certificate",
CertificateName: "stub_certificate_name",
Passphrase: "stub_passphrase",
PrivateKey: "stub_private_key",
PublicCertificate: "stub_public_certificate",
}
res.RequestID = "stub_opc_request_id"
opts := &baremetal.LoadBalancerOptions{}
// opts := (*baremetal.LoadBalancerOptions)(nil)
deletedRes := &baremetal.Certificate{}
*deletedRes = *res
workReqID := "stub_work_req_id"
s.Client.On(
"CreateCertificate",
loadBalancerID,
res.CertificateName,
res.CACertificate,
res.PrivateKey,
res.Passphrase,
res.PublicCertificate,
opts,
).Return(workReqID, nil)
workReqCreated := &baremetal.WorkRequest{
ID: workReqID,
LoadBalancerID: loadBalancerID,
State: baremetal.WorkRequestSucceeded,
}
s.Client.On(
"GetWorkRequest",
workReqID,
(*baremetal.ClientRequestOptions)(nil),
).Return(workReqCreated, nil)
certs := &baremetal.ListCertificates{
Certificates: []baremetal.Certificate{*res},
}
s.Client.On(
"ListCertificates",
loadBalancerID,
(*baremetal.ClientRequestOptions)(nil),
).Return(certs, nil)
s.Client.On(
"DeleteCertificate",
loadBalancerID,
res.CertificateName,
(*baremetal.ClientRequestOptions)(nil),
).Return(workReqID, nil)
s.Client.On(
"GetWorkRequest",
workReqID,
(*baremetal.ClientRequestOptions)(nil),
).Return(workReqCreated, nil)
resource.UnitTest(s.T(), resource.TestCase{
Providers: s.Providers,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "load_balancer_id", loadBalancerID),
resource.TestCheckResourceAttr(resourceName, "certificate_name", res.CertificateName),
resource.TestCheckResourceAttr(resourceName, "ca_certificate", res.CACertificate),
resource.TestCheckResourceAttr(resourceName, "private_key", res.PrivateKey),
resource.TestCheckResourceAttr(resourceName, "passphrase", res.Passphrase),
resource.TestCheckResourceAttr(resourceName, "public_certificate", res.PublicCertificate),
),
},
},
})
}
func TestResourceLoadBalancerCertificateTestSuite(t *testing.T) {
suite.Run(t, new(ResourceLoadBalancerCertificateTestSuite))
}