github.com/renier/terraform@v0.7.8-0.20161024133817-eb8a9ef5471a/command/remote_push_test.go (about)

     1  package command
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/hashicorp/terraform/terraform"
     9  	"github.com/mitchellh/cli"
    10  )
    11  
    12  func TestRemotePush_noRemote(t *testing.T) {
    13  	tmp, cwd := testCwd(t)
    14  	defer testFixCwd(t, tmp, cwd)
    15  
    16  	ui := new(cli.MockUi)
    17  	c := &RemotePushCommand{
    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 TestRemotePush_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  	statePath := filepath.Join(tmp, DefaultDataDir, DefaultStateFilename)
    45  	if err := os.MkdirAll(filepath.Dir(statePath), 0755); err != nil {
    46  		t.Fatalf("err: %s", err)
    47  	}
    48  	f, err := os.Create(statePath)
    49  	if err != nil {
    50  		t.Fatalf("err: %s", err)
    51  	}
    52  	err = terraform.WriteState(s, f)
    53  	f.Close()
    54  	if err != nil {
    55  		t.Fatalf("err: %s", err)
    56  	}
    57  
    58  	ui := new(cli.MockUi)
    59  	c := &RemotePushCommand{
    60  		Meta: Meta{
    61  			ContextOpts: testCtxConfig(testProvider()),
    62  			Ui:          ui,
    63  		},
    64  	}
    65  	args := []string{}
    66  	if code := c.Run(args); code != 0 {
    67  		t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
    68  	}
    69  }