github.com/nfisher/gitit@v0.0.7-0.20240131193748-bc8dd26542cc/cmd/branch_test.go (about)

     1  package cmd_test
     2  
     3  import (
     4  	"github.com/nfisher/gitit/assert"
     5  	. "github.com/nfisher/gitit/cmd"
     6  	"io"
     7  	"testing"
     8  )
     9  
    10  func Test_branch_outside_repo_should_fail(t *testing.T) {
    11  	tdclose := CreateBareDir(t)
    12  	defer tdclose()
    13  
    14  	i := Exec(Flags{SubCommand: "branch", Name: "ml_fairy"}, io.Discard)
    15  	assert.Int(t, i).Equals(ErrNotRepository)
    16  }
    17  
    18  func Test_branch_on_existing_stack_returns_success(t *testing.T) {
    19  	repo, repoclose := CreateRepo(t)
    20  	defer repoclose()
    21  
    22  	CreateThreeLayerStack(t, repo)
    23  
    24  	i := Exec(Flags{SubCommand: "branch", Name: "ml_fairy"}, io.Discard)
    25  	assert.Int(t, i).Equals(Success)
    26  	assert.Repo(t, repo).Branch("kb1234/004_ml_fairy")
    27  }
    28  
    29  func Test_branch_on_invalid_stack_fails(t *testing.T) {
    30  	repo, repoclose := CreateRepo(t)
    31  	defer repoclose()
    32  
    33  	InitialCommit(t, repo)
    34  
    35  	i := Exec(Flags{SubCommand: "branch", Name: "ml_fairy"}, io.Discard)
    36  	assert.Int(t, i).Equals(ErrInvalidStack)
    37  	assert.Repo(t, repo).Branch("master")
    38  }
    39  
    40  func Test_branch_fails_with_no_name_specified(t *testing.T) {
    41  	repo, repoclose := CreateRepo(t)
    42  	defer repoclose()
    43  
    44  	CreateThreeLayerStack(t, repo)
    45  
    46  	i := Exec(Flags{SubCommand: "branch"}, io.Discard)
    47  	assert.Int(t, i).Equals(ErrMissingArguments)
    48  	assert.Repo(t, repo).Branch("kb1234/003_ui")
    49  }
    50  
    51  func Test_branch_returns_success_with_dirty_branch(t *testing.T) {
    52  	repo, repoclose := CreateRepo(t)
    53  	defer repoclose()
    54  
    55  	CreateThreeLayerStack(t, repo)
    56  	CreateFile(t, ".gitignore", "*.sw?\n.idea")
    57  
    58  	i := Exec(Flags{SubCommand: "branch", Name: "update_ignore"}, io.Discard)
    59  
    60  	assert.Int(t, i).Equals(Success)
    61  	assert.Repo(t, repo).Branch("kb1234/004_update_ignore")
    62  	assert.Exists(t, ".gitignore")
    63  }