github.com/developest/gtm-enhanced@v1.0.4-0.20220111132249-cc80a3372c3f/command/rewrite_test.go (about)

     1  package command
     2  
     3  import (
     4  	"github.com/DEVELOPEST/gtm-core/util"
     5  	"github.com/mitchellh/cli"
     6  	"log"
     7  	"os"
     8  	"strings"
     9  	"testing"
    10  )
    11  
    12  func TestRewriteDefaultOptions(t *testing.T) {
    13  	repo := util.NewTestRepo(t, false)
    14  	defer repo.Remove()
    15  	repo.Seed()
    16  	err := os.Chdir(repo.Workdir())
    17  	if err != nil {
    18  		log.Fatal(err)
    19  	}
    20  
    21  	(RewriteCmd{UI: new(cli.MockUi)}).Run([]string{})
    22  
    23  	ui := new(cli.MockUi)
    24  	c := RewriteCmd{UI: ui}
    25  
    26  	var args []string
    27  	rc := c.Run(args)
    28  
    29  	// TODO: Write to stdin
    30  
    31  	if rc != 0 {
    32  		t.Errorf("gtm rewrite(%+v), want 0 got %d, %s", args, rc, ui.ErrorWriter.String())
    33  	}
    34  }
    35  
    36  func TestRewriteInvalidOption(t *testing.T) {
    37  	ui := new(cli.MockUi)
    38  	c := RewriteCmd{UI: ui}
    39  
    40  	args := []string{"-invalid"}
    41  	rc := c.Run(args)
    42  
    43  	// TODO: Write to stdin
    44  
    45  	if rc != 1 {
    46  		t.Errorf("gtm rewrite(%+v), want 0 got %d, %s", args, rc, ui.ErrorWriter)
    47  	}
    48  	if !strings.Contains(ui.OutputWriter.String(), "Usage:") {
    49  		t.Errorf("gtm rewrite(%+v), want 'Usage:'  got %d, %s", args, rc, ui.OutputWriter.String())
    50  	}
    51  }