forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-plugins_test.go
99 lines (90 loc) · 2.57 KB
/
generate-plugins_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
package main
import "testing"
func TestMakeProvisionerMap(t *testing.T) {
p := makeProvisionerMap([]plugin{
{
Package: "file",
PluginName: "file",
TypeName: "Provisioner",
Path: "builtin/provisioners/file",
ImportName: "fileprovisioner",
},
{
Package: "localexec",
PluginName: "local-exec",
TypeName: "Provisioner",
Path: "builtin/provisioners/local-exec",
ImportName: "localexecprovisioner",
},
{
Package: "remoteexec",
PluginName: "remote-exec",
TypeName: "Provisioner",
Path: "builtin/provisioners/remote-exec",
ImportName: "remoteexecprovisioner",
},
})
expected := ` "file": fileprovisioner.Provisioner,
"local-exec": localexecprovisioner.Provisioner,
"remote-exec": remoteexecprovisioner.Provisioner,
`
if p != expected {
t.Errorf("Provisioner output does not match expected format.\n -- Expected -- \n%s\n -- Found --\n%s\n", expected, p)
}
}
func TestDeriveName(t *testing.T) {
actual := deriveName("builtin/provisioners", "builtin/provisioners/magic/remote-exec")
expected := "magic-remote-exec"
if actual != expected {
t.Errorf("Expected %s; found %s", expected, actual)
}
}
func TestDeriveImport(t *testing.T) {
actual := deriveImport("provider", "magic-aws")
expected := "magicawsprovider"
if actual != expected {
t.Errorf("Expected %s; found %s", expected, actual)
}
}
func contains(plugins []plugin, name string) bool {
for _, plugin := range plugins {
if plugin.PluginName == name {
return true
}
}
return false
}
func TestDiscoverTypesProviders(t *testing.T) {
plugins, err := discoverTypesInPath("../builtin/providers", "terraform.ResourceProvider", "Provider")
if err != nil {
t.Fatalf(err.Error())
}
// We're just going to spot-check, not do this exhaustively
if !contains(plugins, "aws") {
t.Errorf("Expected to find aws provider")
}
if !contains(plugins, "docker") {
t.Errorf("Expected to find docker provider")
}
if !contains(plugins, "dnsimple") {
t.Errorf("Expected to find dnsimple provider")
}
if !contains(plugins, "triton") {
t.Errorf("Expected to find triton provider")
}
if contains(plugins, "file") {
t.Errorf("Found unexpected provider file")
}
}
func TestDiscoverTypesProvisioners(t *testing.T) {
plugins, err := discoverTypesInPath("../builtin/provisioners", "terraform.ResourceProvisioner", "Provisioner")
if err != nil {
t.Fatalf(err.Error())
}
if !contains(plugins, "remote-exec") {
t.Errorf("Expected to find remote-exec provisioner")
}
if contains(plugins, "aws") {
t.Errorf("Found unexpected provisioner aws")
}
}