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