forked from oracle/terraform-provider-oci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider_test.go
113 lines (96 loc) · 3.75 KB
/
provider_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
// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
package main
import (
"testing"
"errors"
"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/assert"
)
const testProviderConfig = `
provider "baremetal" {
tenancy_ocid = "ocid.tenancy.aaaa"
user_ocid = "ocid.user.bbbbb"
fingerprint = "xxxxxxxxxx"
private_key_path = "/home/foo/private_key.pem"
private_key_password = "password"
}
`
// This test runs the Provider sanity checks.
func TestProvider(t *testing.T) {
// Real client for the sanity check. Makes this more of an acceptance test.
client := &baremetal.Client{}
if err := Provider(func(d *schema.ResourceData) (interface{}, error) {
return client, nil
}).(*schema.Provider).InternalValidate(); err != nil {
t.Fatalf("err: %s", err)
}
}
// Don't worry, this key is NOT a valid API key
var testPrivateKey = `-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,9F4D00DEF02B2B75
IbSQEhNjPeRt49jUhZbhAEaAIG4L9IokDksw/P/QdCPXzZT008xzYK/zmxkz7so1
ZwvIYHn07E0Ul6fIHR6kjw/+MD7AWluCN1FLHs3PHc4XF4THUCKFCC90FvGJ2PEs
kEh7oJ4azZA/PH51g4rSgWpYtH5B/S6ioE2eZ9jJ/prH+34pCuOpX4AvXEFl5zue
pjFm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ndOM+6hQzD5CZKeL948pXRn
G7nqbG9D44wLklOz6mkIvqLn3qxEFWapl9UK7yfzjoezGoqeNFweadZ10Kp2+Umu
Sa759/2YDCZLDzaVVoLDTHLzi9ejpAkUIXgEFaPNGzQ8DYiL8N2klRozLSlnDEMr
xTHuOMkklNO7SiTluAUBvXrjxfGqe/gwJOHxXQGHC8W6vyhR2BdVx9PKFVebWjlr
gzRMpGgWnjsaz0ldu3uO7ozRxZg8FgdToIzAIaTytpHKI8HvONvPJlYywOMC1gRi
KwX6p26xaVtCV8PbDpF3RHuEJV1NU6PDIhaIHhdL374BiX/KmcJ6yv7tbkczpK+V
-----END RSA PRIVATE KEY-----`
var testKeyFingerPrint = "b4:8a:7d:54:e6:81:04:b2:fa:ce:ba:55:34:dd:00:00"
var testTenancyOCID = "ocid1.tenancy.oc1..faketenancy"
var testUserOCID = "ocid1.user.oc1..fakeuser"
func TestProviderConfig(t *testing.T) {
r := &schema.Resource{
Schema: schemaMap(),
}
d := r.Data(nil)
d.SetId("tenancy_ocid")
d.Set("tenancy_ocid", testTenancyOCID)
d.Set("user_ocid", testUserOCID)
d.Set("fingerprint", testKeyFingerPrint)
d.Set("private_key", testPrivateKey)
//d.Set("private_key_path", "")
d.Set("private_key_password", "password")
client, err := providerConfig(d)
assert.Nil(t, err)
assert.NotNil(t, client)
_, ok := client.(*baremetal.Client)
assert.True(t, ok)
}
// TestNoInstanceState determines if there is any state for a given name.
func testNoInstanceState(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
ms := s.RootModule()
rs, ok := ms.Resources[name]
if !ok {
return nil
}
is := rs.Primary
if is == nil {
return nil
}
return errors.New("State exists for primary resource " + name)
}
}