missing constraints passed erroniously
ConstrainVersions was documented as returning nil, but it was instead returning an empty set. Use the Count() method to check for nil or empty. Add test to verify failed constraints will show up as missing.
This commit is contained in:
parent
283ae0c7c4
commit
fdbfc17fae
|
@ -10,6 +10,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/copy"
|
||||
"github.com/hashicorp/terraform/plugin/discovery"
|
||||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
||||
|
@ -620,6 +621,40 @@ func TestInit_getProviderMissing(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestInit_getProviderHaveLegacyVersion(t *testing.T) {
|
||||
// Create a temporary working directory that is empty
|
||||
td := tempDir(t)
|
||||
copy.CopyDir(testFixturePath("init-providers-lock"), td)
|
||||
defer os.RemoveAll(td)
|
||||
defer testChdir(t, td)()
|
||||
|
||||
if err := ioutil.WriteFile("terraform-provider-test", []byte("provider bin"), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// provider test has a version constraint in the config, which should
|
||||
// trigger the getProvider error below.
|
||||
ui := new(cli.MockUi)
|
||||
c := &InitCommand{
|
||||
Meta: Meta{
|
||||
testingOverrides: metaOverridesForProvider(testProvider()),
|
||||
Ui: ui,
|
||||
},
|
||||
getProvider: func(dst, provider string, req discovery.Constraints, protoVersion uint) error {
|
||||
return fmt.Errorf("EXPECTED PROVIDER ERROR %s", provider)
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{}
|
||||
if code := c.Run(args); code == 0 {
|
||||
t.Fatalf("expceted error, got output: \n%s", ui.OutputWriter.String())
|
||||
}
|
||||
|
||||
if !strings.Contains(ui.ErrorWriter.String(), "EXPECTED PROVIDER ERROR test") {
|
||||
t.Fatalf("unexpected error output: %s", ui.ErrorWriter)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInit_providerLockFile(t *testing.T) {
|
||||
// Create a temporary working directory that is empty
|
||||
td := tempDir(t)
|
||||
|
|
|
@ -108,6 +108,10 @@ func (m *Meta) providerPluginSet() discovery.PluginMetaSet {
|
|||
plugins := discovery.FindPlugins("provider", m.pluginDirs())
|
||||
plugins, _ = plugins.ValidateVersions()
|
||||
|
||||
for p := range plugins {
|
||||
log.Printf("[DEBUG] found valid plugin: %q", p.Name)
|
||||
}
|
||||
|
||||
return plugins
|
||||
}
|
||||
|
||||
|
@ -121,10 +125,14 @@ func (m *Meta) providerResolver() terraform.ResourceProviderResolver {
|
|||
func (m *Meta) missingPlugins(avail discovery.PluginMetaSet, reqd discovery.PluginRequirements) discovery.PluginRequirements {
|
||||
missing := make(discovery.PluginRequirements)
|
||||
|
||||
for n, r := range reqd {
|
||||
log.Printf("[DEBUG] plugin requirements: %q=%q", n, r.Versions)
|
||||
}
|
||||
|
||||
candidates := avail.ConstrainVersions(reqd)
|
||||
|
||||
for name, versionSet := range reqd {
|
||||
if metas := candidates[name]; metas == nil {
|
||||
if metas := candidates[name]; metas.Count() == 0 {
|
||||
missing[name] = versionSet
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue