github.com/chalford/terraform@v0.3.7-0.20150113080010-a78c69a8c81f/command/push_test.go (about)

     1  package command
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/terraform/remote"
     8  	"github.com/hashicorp/terraform/terraform"
     9  	"github.com/mitchellh/cli"
    10  )
    11  
    12  func TestPush_noRemote(t *testing.T) {
    13  	tmp, cwd := testCwd(t)
    14  	defer testFixCwd(t, tmp, cwd)
    15  
    16  	ui := new(cli.MockUi)
    17  	c := &PushCommand{
    18  		Meta: Meta{
    19  			ContextOpts: testCtxConfig(testProvider()),
    20  			Ui:          ui,
    21  		},
    22  	}
    23  
    24  	args := []string{}
    25  	if code := c.Run(args); code != 1 {
    26  		t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
    27  	}
    28  }
    29  
    30  func TestPush_local(t *testing.T) {
    31  	tmp, cwd := testCwd(t)
    32  	defer testFixCwd(t, tmp, cwd)
    33  
    34  	s := terraform.NewState()
    35  	s.Serial = 5
    36  	conf, srv := testRemoteState(t, s, 200)
    37  	defer srv.Close()
    38  
    39  	s = terraform.NewState()
    40  	s.Serial = 10
    41  	s.Remote = conf
    42  
    43  	// Store the local state
    44  	buf := bytes.NewBuffer(nil)
    45  	terraform.WriteState(s, buf)
    46  	remote.EnsureDirectory()
    47  	remote.Persist(buf)
    48  
    49  	ui := new(cli.MockUi)
    50  	c := &PushCommand{
    51  		Meta: Meta{
    52  			ContextOpts: testCtxConfig(testProvider()),
    53  			Ui:          ui,
    54  		},
    55  	}
    56  	args := []string{}
    57  	if code := c.Run(args); code != 0 {
    58  		t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
    59  	}
    60  }