2014-09-22 12:56:50 -05:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2014-09-22 13:15:27 -05:00
|
|
|
"strings"
|
2014-09-22 12:56:50 -05:00
|
|
|
"testing"
|
|
|
|
|
2017-11-02 14:38:53 -05:00
|
|
|
"github.com/hashicorp/terraform/helper/copy"
|
2014-09-22 12:56:50 -05:00
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGet(t *testing.T) {
|
2017-02-07 11:11:48 -06:00
|
|
|
tmp, cwd := testCwd(t)
|
|
|
|
defer testFixCwd(t, tmp, cwd)
|
|
|
|
|
2014-09-22 12:56:50 -05:00
|
|
|
ui := new(cli.MockUi)
|
|
|
|
c := &GetCommand{
|
|
|
|
Meta: Meta{
|
2017-04-13 20:05:58 -05:00
|
|
|
testingOverrides: metaOverridesForProvider(testProvider()),
|
|
|
|
Ui: ui,
|
|
|
|
dataDir: tempDir(t),
|
2014-09-22 12:56:50 -05:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{
|
2014-09-22 13:15:27 -05:00
|
|
|
testFixturePath("get"),
|
2014-09-22 12:56:50 -05:00
|
|
|
}
|
|
|
|
if code := c.Run(args); code != 0 {
|
|
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
|
|
}
|
2014-09-22 13:15:27 -05:00
|
|
|
|
|
|
|
output := ui.OutputWriter.String()
|
2017-11-03 10:13:31 -05:00
|
|
|
if !strings.Contains(output, "module.foo") {
|
2014-09-22 13:15:27 -05:00
|
|
|
t.Fatalf("doesn't look like get: %s", output)
|
|
|
|
}
|
2014-09-22 13:18:49 -05:00
|
|
|
if strings.Contains(output, "(update)") {
|
|
|
|
t.Fatalf("doesn't look like get: %s", output)
|
|
|
|
}
|
2014-09-22 12:56:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGet_multipleArgs(t *testing.T) {
|
|
|
|
ui := new(cli.MockUi)
|
|
|
|
c := &GetCommand{
|
|
|
|
Meta: Meta{
|
2017-04-13 20:05:58 -05:00
|
|
|
testingOverrides: metaOverridesForProvider(testProvider()),
|
|
|
|
Ui: ui,
|
|
|
|
dataDir: tempDir(t),
|
2014-09-22 12:56:50 -05:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2017-11-02 14:38:53 -05:00
|
|
|
td := tempDir(t)
|
|
|
|
copy.CopyDir(testFixturePath("get"), td)
|
|
|
|
defer os.RemoveAll(td)
|
|
|
|
defer testChdir(t, td)()
|
2014-09-22 12:56:50 -05:00
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
2014-09-22 13:15:27 -05:00
|
|
|
c := &GetCommand{
|
2014-09-22 12:56:50 -05:00
|
|
|
Meta: Meta{
|
2017-04-13 20:05:58 -05:00
|
|
|
testingOverrides: metaOverridesForProvider(testProvider()),
|
|
|
|
Ui: ui,
|
|
|
|
dataDir: tempDir(t),
|
2014-09-22 12:56:50 -05:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{}
|
|
|
|
if code := c.Run(args); code != 0 {
|
|
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
|
|
}
|
2014-09-22 13:15:27 -05:00
|
|
|
|
|
|
|
output := ui.OutputWriter.String()
|
2017-11-03 10:13:31 -05:00
|
|
|
if !strings.Contains(output, "module.foo") {
|
2014-09-22 13:15:27 -05:00
|
|
|
t.Fatalf("doesn't look like get: %s", output)
|
|
|
|
}
|
2014-09-22 13:18:49 -05:00
|
|
|
if strings.Contains(output, "(update)") {
|
|
|
|
t.Fatalf("doesn't look like get: %s", output)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGet_update(t *testing.T) {
|
2017-02-07 11:11:48 -06:00
|
|
|
tmp, cwd := testCwd(t)
|
|
|
|
defer testFixCwd(t, tmp, cwd)
|
|
|
|
|
2014-09-22 13:18:49 -05:00
|
|
|
ui := new(cli.MockUi)
|
|
|
|
c := &GetCommand{
|
|
|
|
Meta: Meta{
|
2017-04-13 20:05:58 -05:00
|
|
|
testingOverrides: metaOverridesForProvider(testProvider()),
|
|
|
|
Ui: ui,
|
|
|
|
dataDir: tempDir(t),
|
2014-09-22 13:18:49 -05:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{
|
|
|
|
"-update",
|
|
|
|
testFixturePath("get"),
|
|
|
|
}
|
|
|
|
if code := c.Run(args); code != 0 {
|
|
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
output := ui.OutputWriter.String()
|
2017-11-03 08:33:30 -05:00
|
|
|
if !strings.Contains(output, `Updating source "./foo"`) {
|
2014-09-22 13:18:49 -05:00
|
|
|
t.Fatalf("doesn't look like get: %s", output)
|
|
|
|
}
|
2014-09-22 12:56:50 -05:00
|
|
|
}
|