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

     1  package command
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"github.com/mitchellh/cli"
     8  )
     9  
    10  func TestStatePull(t *testing.T) {
    11  	tmp, cwd := testCwd(t)
    12  	defer testFixCwd(t, tmp, cwd)
    13  
    14  	// Create some legacy remote state
    15  	legacyState := testState()
    16  	_, srv := testRemoteState(t, legacyState, 200)
    17  	defer srv.Close()
    18  	testStateFileRemote(t, legacyState)
    19  
    20  	p := testProvider()
    21  	ui := new(cli.MockUi)
    22  	c := &StatePullCommand{
    23  		Meta: Meta{
    24  			testingOverrides: metaOverridesForProvider(p),
    25  			Ui:               ui,
    26  		},
    27  	}
    28  
    29  	args := []string{}
    30  	if code := c.Run(args); code != 0 {
    31  		t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
    32  	}
    33  
    34  	expected := "test_instance.foo"
    35  	actual := ui.OutputWriter.String()
    36  	if !strings.Contains(actual, expected) {
    37  		t.Fatalf("expected:\n%s\n\nto include: %q", actual, expected)
    38  	}
    39  }
    40  
    41  func TestStatePull_noState(t *testing.T) {
    42  	tmp, cwd := testCwd(t)
    43  	defer testFixCwd(t, tmp, cwd)
    44  
    45  	p := testProvider()
    46  	ui := new(cli.MockUi)
    47  	c := &StatePullCommand{
    48  		Meta: Meta{
    49  			testingOverrides: metaOverridesForProvider(p),
    50  			Ui:               ui,
    51  		},
    52  	}
    53  
    54  	args := []string{}
    55  	if code := c.Run(args); code != 0 {
    56  		t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
    57  	}
    58  
    59  	actual := ui.OutputWriter.String()
    60  	if actual != "" {
    61  		t.Fatalf("bad: %s", actual)
    62  	}
    63  }