command: apply and most of import tests passing
This commit is contained in:
parent
fe9105abfe
commit
0af09b23ca
|
@ -30,7 +30,7 @@ func TestApply_destroy(t *testing.T) {
|
||||||
Status: states.ObjectReady,
|
Status: states.ObjectReady,
|
||||||
},
|
},
|
||||||
addrs.AbsProviderConfig{
|
addrs.AbsProviderConfig{
|
||||||
Provider: addrs.NewLegacyProvider("test"),
|
Provider: addrs.NewDefaultProvider("test"),
|
||||||
Module: addrs.RootModule,
|
Module: addrs.RootModule,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -126,7 +126,7 @@ func TestApply_destroyLockedState(t *testing.T) {
|
||||||
Status: states.ObjectReady,
|
Status: states.ObjectReady,
|
||||||
},
|
},
|
||||||
addrs.AbsProviderConfig{
|
addrs.AbsProviderConfig{
|
||||||
Provider: addrs.NewLegacyProvider("test"),
|
Provider: addrs.NewDefaultProvider("test"),
|
||||||
Module: addrs.RootModule,
|
Module: addrs.RootModule,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -201,7 +201,7 @@ func TestApply_destroyTargeted(t *testing.T) {
|
||||||
Status: states.ObjectReady,
|
Status: states.ObjectReady,
|
||||||
},
|
},
|
||||||
addrs.AbsProviderConfig{
|
addrs.AbsProviderConfig{
|
||||||
Provider: addrs.NewLegacyProvider("test"),
|
Provider: addrs.NewDefaultProvider("test"),
|
||||||
Module: addrs.RootModule,
|
Module: addrs.RootModule,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -217,7 +217,7 @@ func TestApply_destroyTargeted(t *testing.T) {
|
||||||
Status: states.ObjectReady,
|
Status: states.ObjectReady,
|
||||||
},
|
},
|
||||||
addrs.AbsProviderConfig{
|
addrs.AbsProviderConfig{
|
||||||
Provider: addrs.NewLegacyProvider("test"),
|
Provider: addrs.NewDefaultProvider("test"),
|
||||||
Module: addrs.RootModule,
|
Module: addrs.RootModule,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -203,7 +203,7 @@ func TestApply_parallelism(t *testing.T) {
|
||||||
NewState: cty.EmptyObjectVal,
|
NewState: cty.EmptyObjectVal,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
providerFactories[addrs.NewLegacyProvider(name)] = providers.FactoryFixed(provider)
|
providerFactories[addrs.NewDefaultProvider(name)] = providers.FactoryFixed(provider)
|
||||||
}
|
}
|
||||||
testingOverrides := &testingOverrides{
|
testingOverrides := &testingOverrides{
|
||||||
Providers: providerFactories,
|
Providers: providerFactories,
|
||||||
|
@ -834,7 +834,7 @@ func TestApply_refresh(t *testing.T) {
|
||||||
Status: states.ObjectReady,
|
Status: states.ObjectReady,
|
||||||
},
|
},
|
||||||
addrs.AbsProviderConfig{
|
addrs.AbsProviderConfig{
|
||||||
Provider: addrs.NewLegacyProvider("test"),
|
Provider: addrs.NewDefaultProvider("test"),
|
||||||
Module: addrs.RootModule,
|
Module: addrs.RootModule,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -991,7 +991,7 @@ func TestApply_state(t *testing.T) {
|
||||||
Status: states.ObjectReady,
|
Status: states.ObjectReady,
|
||||||
},
|
},
|
||||||
addrs.AbsProviderConfig{
|
addrs.AbsProviderConfig{
|
||||||
Provider: addrs.NewLegacyProvider("test"),
|
Provider: addrs.NewDefaultProvider("test"),
|
||||||
Module: addrs.RootModule,
|
Module: addrs.RootModule,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -1358,7 +1358,7 @@ func TestApply_backup(t *testing.T) {
|
||||||
Status: states.ObjectReady,
|
Status: states.ObjectReady,
|
||||||
},
|
},
|
||||||
addrs.AbsProviderConfig{
|
addrs.AbsProviderConfig{
|
||||||
Provider: addrs.NewLegacyProvider("test"),
|
Provider: addrs.NewDefaultProvider("test"),
|
||||||
Module: addrs.RootModule,
|
Module: addrs.RootModule,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -1662,7 +1662,7 @@ func applyFixturePlanFile(t *testing.T) string {
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance),
|
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance),
|
||||||
ProviderAddr: addrs.AbsProviderConfig{
|
ProviderAddr: addrs.AbsProviderConfig{
|
||||||
Provider: addrs.NewLegacyProvider("test"),
|
Provider: addrs.NewDefaultProvider("test"),
|
||||||
Module: addrs.RootModule,
|
Module: addrs.RootModule,
|
||||||
},
|
},
|
||||||
ChangeSrc: plans.ChangeSrc{
|
ChangeSrc: plans.ChangeSrc{
|
||||||
|
|
|
@ -120,7 +120,7 @@ func testFixturePath(name string) string {
|
||||||
func metaOverridesForProvider(p providers.Interface) *testingOverrides {
|
func metaOverridesForProvider(p providers.Interface) *testingOverrides {
|
||||||
return &testingOverrides{
|
return &testingOverrides{
|
||||||
Providers: map[addrs.Provider]providers.Factory{
|
Providers: map[addrs.Provider]providers.Factory{
|
||||||
addrs.NewLegacyProvider("test"): providers.FactoryFixed(p),
|
addrs.NewDefaultProvider("test"): providers.FactoryFixed(p),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ func metaOverridesForProvider(p providers.Interface) *testingOverrides {
|
||||||
func metaOverridesForProviderAndProvisioner(p providers.Interface, pr provisioners.Interface) *testingOverrides {
|
func metaOverridesForProviderAndProvisioner(p providers.Interface, pr provisioners.Interface) *testingOverrides {
|
||||||
return &testingOverrides{
|
return &testingOverrides{
|
||||||
Providers: map[addrs.Provider]providers.Factory{
|
Providers: map[addrs.Provider]providers.Factory{
|
||||||
addrs.NewLegacyProvider("test"): providers.FactoryFixed(p),
|
addrs.NewDefaultProvider("test"): providers.FactoryFixed(p),
|
||||||
},
|
},
|
||||||
Provisioners: map[string]provisioners.Factory{
|
Provisioners: map[string]provisioners.Factory{
|
||||||
"shell": provisioners.FactoryFixed(pr),
|
"shell": provisioners.FactoryFixed(pr),
|
||||||
|
@ -268,7 +268,7 @@ func testState() *states.State {
|
||||||
DependsOn: []addrs.Referenceable{},
|
DependsOn: []addrs.Referenceable{},
|
||||||
},
|
},
|
||||||
addrs.AbsProviderConfig{
|
addrs.AbsProviderConfig{
|
||||||
Provider: addrs.NewLegacyProvider("test"),
|
Provider: addrs.NewDefaultProvider("test"),
|
||||||
Module: addrs.RootModule,
|
Module: addrs.RootModule,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,7 +2,6 @@ package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -835,90 +834,20 @@ func TestImport_targetIsModule(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure we search the full plugin path during import
|
|
||||||
func TestImport_pluginDir(t *testing.T) {
|
|
||||||
td := tempDir(t)
|
|
||||||
copy.CopyDir(testFixturePath("import-provider"), td)
|
|
||||||
defer os.RemoveAll(td)
|
|
||||||
defer testChdir(t, td)()
|
|
||||||
|
|
||||||
// make a fake provider in a custom plugin directory
|
|
||||||
if err := os.Mkdir("plugins", 0755); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if err := ioutil.WriteFile("plugins/terraform-provider-test_v1.1.1_x4", []byte("invalid binary"), 0755); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
providerSource, close := newMockProviderSource(t, map[string][]string{
|
|
||||||
"test": []string{"1.2.3"},
|
|
||||||
})
|
|
||||||
defer close()
|
|
||||||
|
|
||||||
ui := new(cli.MockUi)
|
|
||||||
c := &ImportCommand{
|
|
||||||
Meta: Meta{
|
|
||||||
Ui: ui,
|
|
||||||
ProviderSource: providerSource,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// store our custom plugin path, which would normally happen during init
|
|
||||||
if err := c.storePluginPath([]string{"./plugins"}); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now we need to go through some plugin init.
|
|
||||||
// This discovers our fake plugin and writes the lock file.
|
|
||||||
initUi := new(cli.MockUi)
|
|
||||||
initCmd := &InitCommand{
|
|
||||||
Meta: Meta{
|
|
||||||
pluginPath: []string{"./plugins"},
|
|
||||||
Ui: initUi,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if code := initCmd.Run(nil); code != 0 {
|
|
||||||
t.Fatal(initUi.ErrorWriter.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
args := []string{
|
|
||||||
"test_instance.foo",
|
|
||||||
"bar",
|
|
||||||
}
|
|
||||||
if code := c.Run(args); code == 0 {
|
|
||||||
t.Fatalf("expected error, got: %s", ui.OutputWriter)
|
|
||||||
}
|
|
||||||
|
|
||||||
outMsg := ui.OutputWriter.String()
|
|
||||||
// if we were missing a plugin, the output will have some explanation
|
|
||||||
// about requirements. If discovery starts verifying binary compatibility,
|
|
||||||
// we will need to write a dummy provider above.
|
|
||||||
if strings.Contains(outMsg, "requirements") {
|
|
||||||
t.Fatal("unexpected output:", outMsg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// We wanted a plugin execution error, rather than a requirement error.
|
|
||||||
// Looking for "exec" in the error should suffice for now.
|
|
||||||
errMsg := ui.ErrorWriter.String()
|
|
||||||
if !strings.Contains(errMsg, "exec") {
|
|
||||||
t.Fatal("unexpected error:", errMsg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const testImportStr = `
|
const testImportStr = `
|
||||||
test_instance.foo:
|
test_instance.foo:
|
||||||
ID = yay
|
ID = yay
|
||||||
provider = provider["registry.terraform.io/-/test"]
|
provider = provider["registry.terraform.io/hashicorp/test"]
|
||||||
`
|
`
|
||||||
|
|
||||||
const testImportCustomProviderStr = `
|
const testImportCustomProviderStr = `
|
||||||
test_instance.foo:
|
test_instance.foo:
|
||||||
ID = yay
|
ID = yay
|
||||||
provider = provider["registry.terraform.io/-/test"].alias
|
provider = provider["registry.terraform.io/hashicorp/test"].alias
|
||||||
`
|
`
|
||||||
|
|
||||||
const testImportProviderMismatchStr = `
|
const testImportProviderMismatchStr = `
|
||||||
test_instance.foo:
|
test_instance.foo:
|
||||||
ID = yay
|
ID = yay
|
||||||
provider = provider["registry.terraform.io/-/test-beta"]
|
provider = provider["registry.terraform.io/hashicorp/test-beta"]
|
||||||
`
|
`
|
||||||
|
|
Loading…
Reference in New Issue