2014-09-22 19:56:50 +02:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
2014-09-22 20:15:27 +02:00
|
|
|
"strings"
|
2014-09-22 19:56:50 +02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGet(t *testing.T) {
|
2021-09-13 19:22:36 +02:00
|
|
|
wd := tempWorkingDirFixture(t, "get")
|
2021-09-02 02:01:44 +02:00
|
|
|
defer testChdir(t, wd.RootModuleDir())()
|
2017-02-07 18:11:48 +01:00
|
|
|
|
2021-09-02 02:01:44 +02:00
|
|
|
ui := cli.NewMockUi()
|
2014-09-22 19:56:50 +02:00
|
|
|
c := &GetCommand{
|
|
|
|
Meta: Meta{
|
2017-04-14 03:05:58 +02:00
|
|
|
testingOverrides: metaOverridesForProvider(testProvider()),
|
|
|
|
Ui: ui,
|
2021-09-02 02:01:44 +02:00
|
|
|
WorkingDir: wd,
|
2014-09-22 19:56:50 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-02-02 16:35:45 +01:00
|
|
|
args := []string{}
|
2014-09-22 19:56:50 +02:00
|
|
|
if code := c.Run(args); code != 0 {
|
|
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
|
|
}
|
2014-09-22 20:15:27 +02:00
|
|
|
|
|
|
|
output := ui.OutputWriter.String()
|
2019-01-18 00:56:53 +01:00
|
|
|
if !strings.Contains(output, "- foo in") {
|
2014-09-22 20:18:49 +02:00
|
|
|
t.Fatalf("doesn't look like get: %s", output)
|
|
|
|
}
|
2014-09-22 19:56:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGet_multipleArgs(t *testing.T) {
|
2021-09-02 02:01:44 +02:00
|
|
|
wd, cleanup := tempWorkingDir(t)
|
|
|
|
defer cleanup()
|
|
|
|
defer testChdir(t, wd.RootModuleDir())()
|
|
|
|
|
|
|
|
ui := cli.NewMockUi()
|
2014-09-22 19:56:50 +02:00
|
|
|
c := &GetCommand{
|
|
|
|
Meta: Meta{
|
2017-04-14 03:05:58 +02:00
|
|
|
testingOverrides: metaOverridesForProvider(testProvider()),
|
|
|
|
Ui: ui,
|
2021-09-02 02:01:44 +02:00
|
|
|
WorkingDir: wd,
|
2014-09-22 19:56:50 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{
|
|
|
|
"bad",
|
|
|
|
"bad",
|
|
|
|
}
|
|
|
|
if code := c.Run(args); code != 1 {
|
|
|
|
t.Fatalf("bad: \n%s", ui.OutputWriter.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-02 16:35:45 +01:00
|
|
|
func TestGet_update(t *testing.T) {
|
2021-09-13 19:22:36 +02:00
|
|
|
wd := tempWorkingDirFixture(t, "get")
|
2021-09-02 02:01:44 +02:00
|
|
|
defer testChdir(t, wd.RootModuleDir())()
|
2014-09-22 19:56:50 +02:00
|
|
|
|
2021-09-02 02:01:44 +02:00
|
|
|
ui := cli.NewMockUi()
|
2014-09-22 20:15:27 +02:00
|
|
|
c := &GetCommand{
|
2014-09-22 19:56:50 +02:00
|
|
|
Meta: Meta{
|
2017-04-14 03:05:58 +02:00
|
|
|
testingOverrides: metaOverridesForProvider(testProvider()),
|
|
|
|
Ui: ui,
|
2021-09-02 02:01:44 +02:00
|
|
|
WorkingDir: wd,
|
2014-09-22 19:56:50 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2014-09-22 20:18:49 +02:00
|
|
|
args := []string{
|
|
|
|
"-update",
|
|
|
|
}
|
|
|
|
if code := c.Run(args); code != 0 {
|
|
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
output := ui.OutputWriter.String()
|
2019-01-18 00:56:53 +01:00
|
|
|
if !strings.Contains(output, `- foo in`) {
|
2014-09-22 20:18:49 +02:00
|
|
|
t.Fatalf("doesn't look like get: %s", output)
|
|
|
|
}
|
2014-09-22 19:56:50 +02:00
|
|
|
}
|