forked from oracle/terraform-provider-oci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
identity_ui_password_test.go
116 lines (98 loc) · 2.79 KB
/
identity_ui_password_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
// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
package main
import (
"testing"
"time"
"github.com/MustWin/baremetal-sdk-go"
"github.com/MustWin/terraform-Oracle-BareMetal-Provider/client/mocks"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"github.com/stretchr/testify/suite"
)
type ResourceIdentityUIPasswordTestSuite struct {
suite.Suite
Client *mocks.BareMetalClient
Provider terraform.ResourceProvider
Providers map[string]terraform.ResourceProvider
TimeCreated baremetal.Time
Config string
ResourceName string
Res *baremetal.UIPassword
}
func (s *ResourceIdentityUIPasswordTestSuite) SetupTest() {
s.Client = &mocks.BareMetalClient{}
s.Provider = Provider(
func(d *schema.ResourceData) (interface{}, error) {
return s.Client, nil
},
)
s.Providers = map[string]terraform.ResourceProvider{
"baremetal": s.Provider,
}
s.Config = `
resource "baremetal_identity_ui_password" "t" {
user_id = "user_id"
version = "1"
}
`
s.Config += testProviderConfig
s.TimeCreated = baremetal.Time{Time: time.Now()}
s.ResourceName = "baremetal_identity_ui_password.t"
s.Res = &baremetal.UIPassword{
Password: "password",
TimeCreated: s.TimeCreated,
UserID: "user_id",
}
s.Res.ETag = "etag"
s.Res.RequestID = "opcrequestid"
s.Client.On("CreateOrResetUIPassword", "user_id", (*baremetal.RetryTokenOptions)(nil)).
Return(s.Res, nil).Once()
}
func (s *ResourceIdentityUIPasswordTestSuite) TestCreateUIPassword() {
resource.UnitTest(s.T(), resource.TestCase{
Providers: s.Providers,
Steps: []resource.TestStep{
{
Config: s.Config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(s.ResourceName, "user_id", "user_id"),
resource.TestCheckResourceAttr(s.ResourceName, "password", "password"),
),
},
},
})
}
func (s ResourceIdentityUIPasswordTestSuite) TestUpdateVersionForcesNewUIPassword() {
config := `
resource "baremetal_identity_ui_password" "t" {
user_id = "user_id"
version = "2"
}
`
config += testProviderConfig
res := &baremetal.UIPassword{
Password: "new_password",
TimeCreated: s.TimeCreated,
UserID: "user_id",
}
s.Client.On("CreateOrResetUIPassword", "user_id", (*baremetal.RetryTokenOptions)(nil)).
Return(res, nil)
resource.UnitTest(s.T(), resource.TestCase{
Providers: s.Providers,
Steps: []resource.TestStep{
{
Config: s.Config,
},
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(s.ResourceName, "password", "new_password"),
),
},
},
})
}
func TestResourceIdentityUIPasswordTestSuite(t *testing.T) {
suite.Run(t, new(ResourceIdentityUIPasswordTestSuite))
}