github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/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 := t.TempDir()
    16  	os.MkdirAll(td, 0755)
    17  	defer testChdir(t, td)()
    18  
    19  	// make sure a vars file doesn't interfere
    20  	err := ioutil.WriteFile(DefaultVarsFilename, nil, 0644)
    21  	if err != nil {
    22  		t.Fatal(err)
    23  	}
    24  
    25  	ui := new(cli.MockUi)
    26  	meta := &Meta{Ui: ui}
    27  
    28  	predictor := meta.completePredictWorkspaceName()
    29  
    30  	got := predictor.Predict(complete.Args{
    31  		Last: "",
    32  	})
    33  	want := []string{"default"}
    34  	if !reflect.DeepEqual(got, want) {
    35  		t.Errorf("wrong result\ngot:  %#v\nwant: %#v", got, want)
    36  	}
    37  }