github.com/iaas-resource-provision/iaas-rpc@v1.0.7-0.20211021023331-ed21f798c408/internal/command/get_test.go (about)

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