github.com/ns1/terraform@v0.7.10-0.20161109153551-8949419bef40/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:   "ResourceProvisioner",
    11  			Path:       "builtin/provisioners/file",
    12  			ImportName: "fileresourceprovisioner",
    13  		},
    14  		{
    15  			Package:    "localexec",
    16  			PluginName: "local-exec",
    17  			TypeName:   "ResourceProvisioner",
    18  			Path:       "builtin/provisioners/local-exec",
    19  			ImportName: "localexecresourceprovisioner",
    20  		},
    21  		{
    22  			Package:    "remoteexec",
    23  			PluginName: "remote-exec",
    24  			TypeName:   "ResourceProvisioner",
    25  			Path:       "builtin/provisioners/remote-exec",
    26  			ImportName: "remoteexecresourceprovisioner",
    27  		},
    28  	})
    29  
    30  	expected := `	"file": func() terraform.ResourceProvisioner { return new(fileresourceprovisioner.ResourceProvisioner) },
    31  	"local-exec": func() terraform.ResourceProvisioner { return new(localexecresourceprovisioner.ResourceProvisioner) },
    32  	"remote-exec": func() terraform.ResourceProvisioner { return new(remoteexecresourceprovisioner.ResourceProvisioner) },
    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", "ResourceProvisioner", "")
    90  	if err != nil {
    91  		t.Fatalf(err.Error())
    92  	}
    93  	if !contains(plugins, "chef") {
    94  		t.Errorf("Expected to find chef provisioner")
    95  	}
    96  	if !contains(plugins, "remote-exec") {
    97  		t.Errorf("Expected to find remote-exec provisioner")
    98  	}
    99  	if contains(plugins, "aws") {
   100  		t.Errorf("Found unexpected provisioner aws")
   101  	}
   102  }