github.com/kilpkonn/gtm-enhanced@v1.3.5/command/commit_test.go (about)

     1  // Copyright 2016 Michael Schenk. All rights reserved.
     2  // Use of this source code is governed by a MIT-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package command
     6  
     7  import (
     8  	"os"
     9  	"strings"
    10  	"testing"
    11  
    12  	"github.com/git-time-metric/gtm/util"
    13  	"github.com/mitchellh/cli"
    14  )
    15  
    16  func TestCommitDefaultOptions(t *testing.T) {
    17  	repo := util.NewTestRepo(t, false)
    18  	defer repo.Remove()
    19  	repo.Seed()
    20  	os.Chdir(repo.Workdir())
    21  
    22  	(InitCmd{UI: new(cli.MockUi)}).Run([]string{})
    23  
    24  	ui := new(cli.MockUi)
    25  	c := CommitCmd{UI: ui}
    26  
    27  	args := []string{"-yes"}
    28  	rc := c.Run(args)
    29  
    30  	if rc != 0 {
    31  		t.Errorf("gtm commit(%+v), want 0 got %d, %s", args, rc, ui.ErrorWriter.String())
    32  	}
    33  }
    34  
    35  func TestCommitInvalidOption(t *testing.T) {
    36  	ui := new(cli.MockUi)
    37  	c := CommitCmd{UI: ui}
    38  
    39  	args := []string{"-invalid"}
    40  	rc := c.Run(args)
    41  
    42  	if rc != 1 {
    43  		t.Errorf("gtm commit(%+v), want 0 got %d, %s", args, rc, ui.ErrorWriter)
    44  	}
    45  	if !strings.Contains(ui.OutputWriter.String(), "Usage:") {
    46  		t.Errorf("gtm commit(%+v), want 'Usage:'  got %d, %s", args, rc, ui.OutputWriter.String())
    47  	}
    48  }