github.com/jaredpalmer/terraform@v1.1.0-alpha20210908.0.20210911170307-88705c943a03/internal/command/get_test.go (about)

     1  package command
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"github.com/mitchellh/cli"
     8  )
     9  
    10  func TestGet(t *testing.T) {
    11  	wd, cleanup := tempWorkingDirFixture(t, "get")
    12  	defer cleanup()
    13  	defer testChdir(t, wd.RootModuleDir())()
    14  
    15  	ui := cli.NewMockUi()
    16  	c := &GetCommand{
    17  		Meta: Meta{
    18  			testingOverrides: metaOverridesForProvider(testProvider()),
    19  			Ui:               ui,
    20  			WorkingDir:       wd,
    21  		},
    22  	}
    23  
    24  	args := []string{}
    25  	if code := c.Run(args); code != 0 {
    26  		t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
    27  	}
    28  
    29  	output := ui.OutputWriter.String()
    30  	if !strings.Contains(output, "- foo in") {
    31  		t.Fatalf("doesn't look like get: %s", output)
    32  	}
    33  }
    34  
    35  func TestGet_multipleArgs(t *testing.T) {
    36  	wd, cleanup := tempWorkingDir(t)
    37  	defer cleanup()
    38  	defer testChdir(t, wd.RootModuleDir())()
    39  
    40  	ui := cli.NewMockUi()
    41  	c := &GetCommand{
    42  		Meta: Meta{
    43  			testingOverrides: metaOverridesForProvider(testProvider()),
    44  			Ui:               ui,
    45  			WorkingDir:       wd,
    46  		},
    47  	}
    48  
    49  	args := []string{
    50  		"bad",
    51  		"bad",
    52  	}
    53  	if code := c.Run(args); code != 1 {
    54  		t.Fatalf("bad: \n%s", ui.OutputWriter.String())
    55  	}
    56  }
    57  
    58  func TestGet_update(t *testing.T) {
    59  	wd, cleanup := tempWorkingDirFixture(t, "get")
    60  	defer cleanup()
    61  	defer testChdir(t, wd.RootModuleDir())()
    62  
    63  	ui := cli.NewMockUi()
    64  	c := &GetCommand{
    65  		Meta: Meta{
    66  			testingOverrides: metaOverridesForProvider(testProvider()),
    67  			Ui:               ui,
    68  			WorkingDir:       wd,
    69  		},
    70  	}
    71  
    72  	args := []string{
    73  		"-update",
    74  	}
    75  	if code := c.Run(args); code != 0 {
    76  		t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
    77  	}
    78  
    79  	output := ui.OutputWriter.String()
    80  	if !strings.Contains(output, `- foo in`) {
    81  		t.Fatalf("doesn't look like get: %s", output)
    82  	}
    83  }