github.com/nfisher/gitit@v0.0.7-0.20240131193748-bc8dd26542cc/cmd/init_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_init_returns_missing_arguments_without_branch_arg(t *testing.T) {
    11  	i := Exec(Flags{SubCommand: "init"}, io.Discard)
    12  	assert.Int(t, i).Equals(ErrMissingArguments)
    13  }
    14  
    15  func Test_init_outside_repo_should_fail(t *testing.T) {
    16  	tdclose := CreateBareDir(t)
    17  	defer tdclose()
    18  
    19  	i := Exec(Flags{SubCommand: "init", Name: "123/migration"}, io.Discard)
    20  	assert.Int(t, i).Equals(ErrNotRepository)
    21  }
    22  
    23  func Test_init_returns_success_with_branch_specified(t *testing.T) {
    24  	repo, repoclose := CreateRepo(t)
    25  	defer repoclose()
    26  	InitialCommit(t, repo)
    27  
    28  	i := Exec(Flags{SubCommand: "init", Name: "123/migration"}, io.Discard)
    29  	assert.Int(t, i).Equals(Success)
    30  	assert.Repo(t, repo).Branch("123/001_migration")
    31  }
    32  
    33  func Test_init_returns_failure_with_invalid_branch_specification(t *testing.T) {
    34  	repo, repoclose := CreateRepo(t)
    35  	defer repoclose()
    36  	InitialCommit(t, repo)
    37  
    38  	i := Exec(Flags{SubCommand: "init", Name: "migration"}, io.Discard)
    39  	assert.Int(t, i).Equals(ErrInvalidArgument)
    40  }
    41  
    42  func Test_init_returns_success_with_dirty_branch(t *testing.T) {
    43  	repo, repoclose := CreateRepo(t)
    44  	defer repoclose()
    45  
    46  	InitialCommit(t, repo)
    47  	CreateFile(t, ".gitignore", "*.sw?\n.idea")
    48  
    49  	i := Exec(Flags{SubCommand: "init", Name: "123/migration"}, io.Discard)
    50  
    51  	assert.Int(t, i).Equals(Success)
    52  	assert.Repo(t, repo).Branch("123/001_migration")
    53  	assert.Exists(t, ".gitignore")
    54  }