github.com/sfdevops1/terrra4orm@v0.11.12-beta1/scripts/generate-plugins_test.go (about) 1 package main 2 3 import "testing" 4 5 func TestMakeProvisionerMap(t *testing.T) { 6 p := makeProvisionerMap([]plugin{ 7 { 8 Package: "file", 9 PluginName: "file", 10 TypeName: "Provisioner", 11 Path: "builtin/provisioners/file", 12 ImportName: "fileprovisioner", 13 }, 14 { 15 Package: "localexec", 16 PluginName: "local-exec", 17 TypeName: "Provisioner", 18 Path: "builtin/provisioners/local-exec", 19 ImportName: "localexecprovisioner", 20 }, 21 { 22 Package: "remoteexec", 23 PluginName: "remote-exec", 24 TypeName: "Provisioner", 25 Path: "builtin/provisioners/remote-exec", 26 ImportName: "remoteexecprovisioner", 27 }, 28 }) 29 30 expected := ` "file": fileprovisioner.Provisioner, 31 "local-exec": localexecprovisioner.Provisioner, 32 "remote-exec": remoteexecprovisioner.Provisioner, 33 ` 34 35 if p != expected { 36 t.Errorf("Provisioner output does not match expected format.\n -- Expected -- \n%s\n -- Found --\n%s\n", expected, p) 37 } 38 } 39 40 func TestDeriveName(t *testing.T) { 41 actual := deriveName("builtin/provisioners", "builtin/provisioners/magic/remote-exec") 42 expected := "magic-remote-exec" 43 if actual != expected { 44 t.Errorf("Expected %s; found %s", expected, actual) 45 } 46 } 47 48 func TestDeriveImport(t *testing.T) { 49 actual := deriveImport("provider", "magic-aws") 50 expected := "magicawsprovider" 51 if actual != expected { 52 t.Errorf("Expected %s; found %s", expected, actual) 53 } 54 } 55 56 func contains(plugins []plugin, name string) bool { 57 for _, plugin := range plugins { 58 if plugin.PluginName == name { 59 return true 60 } 61 } 62 return false 63 } 64 65 //func TestDiscoverTypesProviders(t *testing.T) { 66 // plugins, err := discoverTypesInPath("../builtin/providers", "terraform.ResourceProvider", "Provider") 67 // if err != nil { 68 // t.Fatalf(err.Error()) 69 // } 70 // // We're just going to spot-check, not do this exhaustively 71 // if !contains(plugins, "aws") { 72 // t.Errorf("Expected to find aws provider") 73 // } 74 // if !contains(plugins, "docker") { 75 // t.Errorf("Expected to find docker provider") 76 // } 77 // if !contains(plugins, "dnsimple") { 78 // t.Errorf("Expected to find dnsimple provider") 79 // } 80 // if !contains(plugins, "triton") { 81 // t.Errorf("Expected to find triton provider") 82 // } 83 // if contains(plugins, "file") { 84 // t.Errorf("Found unexpected provider file") 85 // } 86 //} 87 88 func TestDiscoverTypesProvisioners(t *testing.T) { 89 plugins, err := discoverTypesInPath("../builtin/provisioners", "terraform.ResourceProvisioner", "Provisioner") 90 if err != nil { 91 t.Fatalf(err.Error()) 92 } 93 if !contains(plugins, "remote-exec") { 94 t.Errorf("Expected to find remote-exec provisioner") 95 } 96 if contains(plugins, "aws") { 97 t.Errorf("Found unexpected provisioner aws") 98 } 99 }