github.com/paultyng/terraform@v0.6.11-0.20180227224804-66ff8f8bed40/command/autocomplete_test.go (about)

     1  package command
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"reflect"
     7  	"testing"
     8  
     9  	"github.com/mitchellh/cli"
    10  	"github.com/posener/complete"
    11  )
    12  
    13  func TestMetaCompletePredictWorkspaceName(t *testing.T) {
    14  	// Create a temporary working directory that is empty
    15  	td := tempDir(t)
    16  	os.MkdirAll(td, 0755)
    17  	defer os.RemoveAll(td)
    18  	defer testChdir(t, td)()
    19  
    20  	// make sure a vars file doesn't interfere
    21  	err := ioutil.WriteFile(DefaultVarsFilename, nil, 0644)
    22  	if err != nil {
    23  		t.Fatal(err)
    24  	}
    25  
    26  	ui := new(cli.MockUi)
    27  	meta := &Meta{Ui: ui}
    28  
    29  	predictor := meta.completePredictWorkspaceName()
    30  
    31  	got := predictor.Predict(complete.Args{
    32  		Last: "",
    33  	})
    34  	want := []string{"default"}
    35  	if !reflect.DeepEqual(got, want) {
    36  		t.Errorf("wrong result\ngot:  %#v\nwant: %#v", got, want)
    37  	}
    38  }