mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-02 12:17:39 -06:00
d0993b0e80
Cleanup some more test fixtures to use t.TempDir Use EvalSymlinks with temp dir paths to help with MacOS errors from various terraform components.
82 lines
1.6 KiB
Go
82 lines
1.6 KiB
Go
package command
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/mitchellh/cli"
|
|
)
|
|
|
|
func TestGet(t *testing.T) {
|
|
wd := tempWorkingDirFixture(t, "get")
|
|
defer testChdir(t, wd.RootModuleDir())()
|
|
|
|
ui := cli.NewMockUi()
|
|
c := &GetCommand{
|
|
Meta: Meta{
|
|
testingOverrides: metaOverridesForProvider(testProvider()),
|
|
Ui: ui,
|
|
WorkingDir: wd,
|
|
},
|
|
}
|
|
|
|
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_multipleArgs(t *testing.T) {
|
|
wd, cleanup := tempWorkingDir(t)
|
|
defer cleanup()
|
|
defer testChdir(t, wd.RootModuleDir())()
|
|
|
|
ui := cli.NewMockUi()
|
|
c := &GetCommand{
|
|
Meta: Meta{
|
|
testingOverrides: metaOverridesForProvider(testProvider()),
|
|
Ui: ui,
|
|
WorkingDir: wd,
|
|
},
|
|
}
|
|
|
|
args := []string{
|
|
"bad",
|
|
"bad",
|
|
}
|
|
if code := c.Run(args); code != 1 {
|
|
t.Fatalf("bad: \n%s", ui.OutputWriter.String())
|
|
}
|
|
}
|
|
|
|
func TestGet_update(t *testing.T) {
|
|
wd := tempWorkingDirFixture(t, "get")
|
|
defer testChdir(t, wd.RootModuleDir())()
|
|
|
|
ui := cli.NewMockUi()
|
|
c := &GetCommand{
|
|
Meta: Meta{
|
|
testingOverrides: metaOverridesForProvider(testProvider()),
|
|
Ui: ui,
|
|
WorkingDir: wd,
|
|
},
|
|
}
|
|
|
|
args := []string{
|
|
"-update",
|
|
}
|
|
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)
|
|
}
|
|
}
|