2016-04-05 04:11:11 +02:00
|
|
|
package command
|
|
|
|
|
2019-12-04 17:30:20 +01:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
2016-04-05 04:11:11 +02:00
|
|
|
|
2018-01-05 16:59:30 +01:00
|
|
|
func TestInternalPlugin_InternalProviders(t *testing.T) {
|
|
|
|
m := new(Meta)
|
|
|
|
providers := m.internalProviders()
|
|
|
|
// terraform is the only provider moved back to internal
|
|
|
|
for _, name := range []string{"terraform"} {
|
2020-03-31 23:02:40 +02:00
|
|
|
pf, ok := providers[name]
|
2018-01-05 16:59:30 +01:00
|
|
|
if !ok {
|
|
|
|
t.Errorf("Expected to find %s in InternalProviders", name)
|
|
|
|
}
|
|
|
|
|
|
|
|
provider, err := pf()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if provider == nil {
|
|
|
|
t.Fatal("provider factory returned a nil provider")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-05 04:11:11 +02:00
|
|
|
|
|
|
|
func TestInternalPlugin_InternalProvisioners(t *testing.T) {
|
2020-11-16 20:15:03 +01:00
|
|
|
for _, name := range []string{"file", "local-exec", "remote-exec"} {
|
2016-04-05 04:11:11 +02:00
|
|
|
if _, ok := InternalProvisioners[name]; !ok {
|
|
|
|
t.Errorf("Expected to find %s in InternalProvisioners", name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInternalPlugin_BuildPluginCommandString(t *testing.T) {
|
|
|
|
actual, err := BuildPluginCommandString("provisioner", "remote-exec")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := "-TFSPACE-internal-plugin-TFSPACE-provisioner-TFSPACE-remote-exec"
|
|
|
|
if actual[len(actual)-len(expected):] != expected {
|
|
|
|
t.Errorf("Expected command to end with %s; got:\n%s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
2019-12-06 00:00:51 +01:00
|
|
|
|
|
|
|
func TestInternalPlugin_StripArgFlags(t *testing.T) {
|
|
|
|
actual := StripArgFlags([]string{"provisioner", "remote-exec", "-var-file=my_vars.tfvars", "-flag"})
|
|
|
|
expected := []string{"provisioner", "remote-exec"}
|
|
|
|
// Must be same length and order.
|
|
|
|
if len(actual) != len(expected) || expected[0] != actual[0] || actual[1] != actual[1] {
|
|
|
|
t.Fatalf("Expected args to be exactly '%s', got '%s'", expected, actual)
|
|
|
|
}
|
|
|
|
}
|