2017-09-25 21:00:45 -05:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
"github.com/posener/complete"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMetaCompletePredictWorkspaceName(t *testing.T) {
|
|
|
|
// Create a temporary working directory that is empty
|
2022-04-08 11:34:16 -05:00
|
|
|
td := t.TempDir()
|
2017-09-25 21:00:45 -05:00
|
|
|
os.MkdirAll(td, 0755)
|
|
|
|
defer testChdir(t, td)()
|
|
|
|
|
|
|
|
// make sure a vars file doesn't interfere
|
|
|
|
err := ioutil.WriteFile(DefaultVarsFilename, nil, 0644)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
|
|
|
meta := &Meta{Ui: ui}
|
|
|
|
|
|
|
|
predictor := meta.completePredictWorkspaceName()
|
|
|
|
|
2017-12-05 12:24:04 -06:00
|
|
|
got := predictor.Predict(complete.Args{
|
|
|
|
Last: "",
|
2017-09-25 21:00:45 -05:00
|
|
|
})
|
2017-12-05 12:24:04 -06:00
|
|
|
want := []string{"default"}
|
|
|
|
if !reflect.DeepEqual(got, want) {
|
|
|
|
t.Errorf("wrong result\ngot: %#v\nwant: %#v", got, want)
|
|
|
|
}
|
2017-09-25 21:00:45 -05:00
|
|
|
}
|