github.com/ezbercih/terraform@v0.1.1-0.20140729011846-3c33865e0839/command/show_test.go (about)

     1  package command
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/hashicorp/terraform/config"
     7  	"github.com/hashicorp/terraform/terraform"
     8  	"github.com/mitchellh/cli"
     9  )
    10  
    11  func TestShow(t *testing.T) {
    12  	ui := new(cli.MockUi)
    13  	c := &ShowCommand{
    14  		Meta: Meta{
    15  			ContextOpts: testCtxConfig(testProvider()),
    16  			Ui:          ui,
    17  		},
    18  	}
    19  
    20  	args := []string{
    21  		"bad",
    22  		"bad",
    23  	}
    24  	if code := c.Run(args); code != 1 {
    25  		t.Fatalf("bad: \n%s", ui.OutputWriter.String())
    26  	}
    27  }
    28  
    29  func TestShow_noArgs(t *testing.T) {
    30  	ui := new(cli.MockUi)
    31  	c := &ShowCommand{
    32  		Meta: Meta{
    33  			ContextOpts: testCtxConfig(testProvider()),
    34  			Ui:          ui,
    35  		},
    36  	}
    37  
    38  	args := []string{}
    39  	if code := c.Run(args); code != 1 {
    40  		t.Fatalf("bad: \n%s", ui.OutputWriter.String())
    41  	}
    42  }
    43  
    44  func TestShow_plan(t *testing.T) {
    45  	planPath := testPlanFile(t, &terraform.Plan{
    46  		Config: new(config.Config),
    47  	})
    48  
    49  	ui := new(cli.MockUi)
    50  	c := &ShowCommand{
    51  		Meta: Meta{
    52  			ContextOpts: testCtxConfig(testProvider()),
    53  			Ui:          ui,
    54  		},
    55  	}
    56  
    57  	args := []string{
    58  		planPath,
    59  	}
    60  	if code := c.Run(args); code != 0 {
    61  		t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
    62  	}
    63  }
    64  
    65  func TestShow_state(t *testing.T) {
    66  	originalState := &terraform.State{
    67  		Resources: map[string]*terraform.ResourceState{
    68  			"test_instance.foo": &terraform.ResourceState{
    69  				ID:   "bar",
    70  				Type: "test_instance",
    71  			},
    72  		},
    73  	}
    74  
    75  	statePath := testStateFile(t, originalState)
    76  
    77  	ui := new(cli.MockUi)
    78  	c := &ShowCommand{
    79  		Meta: Meta{
    80  			ContextOpts: testCtxConfig(testProvider()),
    81  			Ui:          ui,
    82  		},
    83  	}
    84  
    85  	args := []string{
    86  		statePath,
    87  	}
    88  	if code := c.Run(args); code != 0 {
    89  		t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
    90  	}
    91  }