2016-04-05 04:11:11 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestMakeProvisionerMap(t *testing.T) {
|
|
|
|
p := makeProvisionerMap([]plugin{
|
|
|
|
{
|
|
|
|
Package: "file",
|
|
|
|
PluginName: "file",
|
2016-12-23 03:17:49 +01:00
|
|
|
TypeName: "Provisioner",
|
2016-04-05 04:11:11 +02:00
|
|
|
Path: "builtin/provisioners/file",
|
2016-12-23 03:17:49 +01:00
|
|
|
ImportName: "fileprovisioner",
|
2016-04-05 04:11:11 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Package: "localexec",
|
|
|
|
PluginName: "local-exec",
|
2016-12-23 03:17:49 +01:00
|
|
|
TypeName: "Provisioner",
|
2016-04-05 04:11:11 +02:00
|
|
|
Path: "builtin/provisioners/local-exec",
|
2016-12-23 03:17:49 +01:00
|
|
|
ImportName: "localexecprovisioner",
|
2016-04-05 04:11:11 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Package: "remoteexec",
|
|
|
|
PluginName: "remote-exec",
|
2016-12-23 03:17:49 +01:00
|
|
|
TypeName: "Provisioner",
|
2016-04-05 04:11:11 +02:00
|
|
|
Path: "builtin/provisioners/remote-exec",
|
2016-12-23 03:17:49 +01:00
|
|
|
ImportName: "remoteexecprovisioner",
|
2016-04-05 04:11:11 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2016-12-23 03:17:49 +01:00
|
|
|
expected := ` "file": fileprovisioner.Provisioner,
|
|
|
|
"local-exec": localexecprovisioner.Provisioner,
|
|
|
|
"remote-exec": remoteexecprovisioner.Provisioner,
|
2016-04-05 04:11:11 +02:00
|
|
|
`
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-06-12 16:00:09 +02:00
|
|
|
//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")
|
|
|
|
// }
|
|
|
|
//}
|
2016-04-05 04:11:11 +02:00
|
|
|
|
|
|
|
func TestDiscoverTypesProvisioners(t *testing.T) {
|
2016-12-23 03:17:49 +01:00
|
|
|
plugins, err := discoverTypesInPath("../builtin/provisioners", "terraform.ResourceProvisioner", "Provisioner")
|
2016-04-05 04:11:11 +02:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|