2014-09-22 19:56:50 +02:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
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) {
|
|
|
|
ui := new(cli.MockUi)
|
|
|
|
c := &GetCommand{
|
|
|
|
Meta: Meta{
|
|
|
|
ContextOpts: testCtxConfig(testProvider()),
|
|
|
|
Ui: ui,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{
|
2014-09-22 20:15:27 +02:00
|
|
|
testFixturePath("get"),
|
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()
|
|
|
|
if !strings.Contains(output, "Get: file://") {
|
|
|
|
t.Fatalf("doesn't look like get: %s", output)
|
|
|
|
}
|
2014-09-22 20:18:49 +02:00
|
|
|
if strings.Contains(output, "(update)") {
|
|
|
|
t.Fatalf("doesn't look like get: %s", output)
|
|
|
|
}
|
2014-09-22 19:56:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGet_multipleArgs(t *testing.T) {
|
|
|
|
ui := new(cli.MockUi)
|
|
|
|
c := &GetCommand{
|
|
|
|
Meta: Meta{
|
|
|
|
ContextOpts: testCtxConfig(testProvider()),
|
|
|
|
Ui: ui,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
cwd, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
2014-09-22 20:15:27 +02:00
|
|
|
if err := os.Chdir(testFixturePath("get")); err != nil {
|
2014-09-22 19:56:50 +02:00
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
defer os.Chdir(cwd)
|
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
2014-09-22 20:15:27 +02:00
|
|
|
c := &GetCommand{
|
2014-09-22 19:56:50 +02:00
|
|
|
Meta: Meta{
|
|
|
|
ContextOpts: testCtxConfig(testProvider()),
|
|
|
|
Ui: ui,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{}
|
|
|
|
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()
|
|
|
|
if !strings.Contains(output, "Get: file://") {
|
|
|
|
t.Fatalf("doesn't look like get: %s", output)
|
|
|
|
}
|
2014-09-22 20:18:49 +02:00
|
|
|
if strings.Contains(output, "(update)") {
|
|
|
|
t.Fatalf("doesn't look like get: %s", output)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGet_update(t *testing.T) {
|
|
|
|
ui := new(cli.MockUi)
|
|
|
|
c := &GetCommand{
|
|
|
|
Meta: Meta{
|
|
|
|
ContextOpts: testCtxConfig(testProvider()),
|
|
|
|
Ui: ui,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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, "Get: file://") {
|
|
|
|
t.Fatalf("doesn't look like get: %s", output)
|
|
|
|
}
|
|
|
|
if !strings.Contains(output, "(update)") {
|
|
|
|
t.Fatalf("doesn't look like get: %s", output)
|
|
|
|
}
|
2014-09-22 19:56:50 +02:00
|
|
|
}
|
2014-09-22 20:18:49 +02:00
|
|
|
|