mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 18:01:01 -06:00
8b094f48f7
We missed this on the initial update pass because this was calling directly into the module package API rather than going through the Meta methods that we updated for the new config loader. m.installModules here is the same method that "terraform init" is using for this purpose, ensuring the two will behave the same way. This changes the output a little compared to the old installer, but it still includes the important information about where each module is coming from.
109 lines
2.1 KiB
Go
109 lines
2.1 KiB
Go
package command
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/helper/copy"
|
|
"github.com/mitchellh/cli"
|
|
)
|
|
|
|
func TestGet(t *testing.T) {
|
|
tmp, cwd := testCwd(t)
|
|
defer testFixCwd(t, tmp, cwd)
|
|
|
|
ui := new(cli.MockUi)
|
|
c := &GetCommand{
|
|
Meta: Meta{
|
|
testingOverrides: metaOverridesForProvider(testProvider()),
|
|
Ui: ui,
|
|
dataDir: tempDir(t),
|
|
},
|
|
}
|
|
|
|
args := []string{
|
|
testFixturePath("get"),
|
|
}
|
|
if code := c.Run(args); code != 0 {
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
}
|
|
|
|
output := ui.OutputWriter.String()
|
|
if !strings.Contains(output, "- foo in") {
|
|
t.Fatalf("doesn't look like get: %s", output)
|
|
}
|
|
}
|
|
|
|
func TestGet_multipleArgs(t *testing.T) {
|
|
ui := new(cli.MockUi)
|
|
c := &GetCommand{
|
|
Meta: Meta{
|
|
testingOverrides: metaOverridesForProvider(testProvider()),
|
|
Ui: ui,
|
|
dataDir: tempDir(t),
|
|
},
|
|
}
|
|
|
|
args := []string{
|
|
"bad",
|
|
"bad",
|
|
}
|
|
if code := c.Run(args); code != 1 {
|
|
t.Fatalf("bad: \n%s", ui.OutputWriter.String())
|
|
}
|
|
}
|
|
|
|
func TestGet_noArgs(t *testing.T) {
|
|
td := tempDir(t)
|
|
copy.CopyDir(testFixturePath("get"), td)
|
|
defer os.RemoveAll(td)
|
|
defer testChdir(t, td)()
|
|
|
|
ui := new(cli.MockUi)
|
|
c := &GetCommand{
|
|
Meta: Meta{
|
|
testingOverrides: metaOverridesForProvider(testProvider()),
|
|
Ui: ui,
|
|
dataDir: tempDir(t),
|
|
},
|
|
}
|
|
|
|
args := []string{}
|
|
if code := c.Run(args); code != 0 {
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
}
|
|
|
|
output := ui.OutputWriter.String()
|
|
if !strings.Contains(output, "- foo in") {
|
|
t.Fatalf("doesn't look like get: %s", output)
|
|
}
|
|
}
|
|
|
|
func TestGet_update(t *testing.T) {
|
|
tmp, cwd := testCwd(t)
|
|
defer testFixCwd(t, tmp, cwd)
|
|
|
|
ui := new(cli.MockUi)
|
|
c := &GetCommand{
|
|
Meta: Meta{
|
|
testingOverrides: metaOverridesForProvider(testProvider()),
|
|
Ui: ui,
|
|
dataDir: tempDir(t),
|
|
},
|
|
}
|
|
|
|
args := []string{
|
|
"-update",
|
|
testFixturePath("get"),
|
|
}
|
|
if code := c.Run(args); code != 0 {
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
}
|
|
|
|
output := ui.OutputWriter.String()
|
|
if !strings.Contains(output, `- foo in`) {
|
|
t.Fatalf("doesn't look like get: %s", output)
|
|
}
|
|
}
|