github.com/nfisher/gitit@v0.0.7-0.20240131193748-bc8dd26542cc/cmd/checkout_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_checkout_outside_repo_should_fail(t *testing.T) {
    11  	tdclose := CreateBareDir(t)
    12  	defer tdclose()
    13  
    14  	i := Exec(Flags{SubCommand: "checkout", Name: "001"}, io.Discard)
    15  	assert.Int(t, i).Equals(ErrNotRepository)
    16  }
    17  
    18  func Test_checkout_returns_unknown_branch_with_absent_branch_id(t *testing.T) {
    19  	repo, repoclose := CreateRepo(t)
    20  	defer repoclose()
    21  
    22  	CreateThreeLayerStack(t, repo)
    23  
    24  	i := Exec(Flags{SubCommand: "checkout", Name: "004"}, io.Discard)
    25  	assert.Int(t, i).Equals(ErrUnknownBranch)
    26  	assert.Repo(t, repo).Branch("kb1234/003_ui")
    27  }
    28  
    29  func Test_checkout_returns_success_with_known_branch_id(t *testing.T) {
    30  	repo, repoclose := CreateRepo(t)
    31  	defer repoclose()
    32  
    33  	CreateThreeLayerStack(t, repo)
    34  
    35  	i := Exec(Flags{SubCommand: "checkout", Name: "001"}, io.Discard)
    36  	assert.Int(t, i).Equals(Success)
    37  	assert.Repo(t, repo).Branch("kb1234/001_docs")
    38  }
    39  
    40  func Test_checkout_returns_not_found_with_invalid_stack(t *testing.T) {
    41  	repo, repoclose := CreateRepo(t)
    42  	defer repoclose()
    43  
    44  	InitialCommit(t, repo)
    45  
    46  	i := Exec(Flags{SubCommand: "checkout", Name: "002"}, io.Discard)
    47  	assert.Int(t, i).Equals(ErrInvalidStack)
    48  	assert.Repo(t, repo).Branch("master")
    49  }
    50  
    51  func Test_checkout_returns_missing_args_with_no_branch_id(t *testing.T) {
    52  	repo, repoclose := CreateRepo(t)
    53  	defer repoclose()
    54  
    55  	InitialCommit(t, repo)
    56  
    57  	i := Exec(Flags{SubCommand: "checkout"}, io.Discard)
    58  	assert.Int(t, i).Equals(ErrMissingArguments)
    59  }