fix(git): tests covering revert/sequencer

This commit is contained in:
Chris Donnelly 2021-07-29 15:06:56 -05:00 committed by Jan De Dobbeleer
parent 3dd512f2c2
commit 27654dbd56

View file

@ -80,6 +80,10 @@ type detachedContext struct {
tagName string tagName string
cherryPick bool cherryPick bool
cherryPickSHA string cherryPickSHA string
revert bool
revertSHA string
sequencer bool
sequencerTodo string
merge bool merge bool
mergeHEAD string mergeHEAD string
status string status string
@ -97,8 +101,12 @@ func setupHEADContextEnv(context *detachedContext) *git {
env.On("getFileContent", "/rebase-apply/last").Return(context.total) env.On("getFileContent", "/rebase-apply/last").Return(context.total)
env.On("getFileContent", "/rebase-apply/head-name").Return(context.origin) env.On("getFileContent", "/rebase-apply/head-name").Return(context.origin)
env.On("getFileContent", "/CHERRY_PICK_HEAD").Return(context.cherryPickSHA) env.On("getFileContent", "/CHERRY_PICK_HEAD").Return(context.cherryPickSHA)
env.On("getFileContent", "/REVERT_HEAD").Return(context.revertSHA)
env.On("getFileContent", "/MERGE_MSG").Return(fmt.Sprintf("Merge branch '%s' into %s", context.mergeHEAD, context.onto)) env.On("getFileContent", "/MERGE_MSG").Return(fmt.Sprintf("Merge branch '%s' into %s", context.mergeHEAD, context.onto))
env.On("hasFilesInDir", "", "CHERRY_PICK_HEAD").Return(context.cherryPick) env.On("hasFilesInDir", "", "CHERRY_PICK_HEAD").Return(context.cherryPick)
env.On("hasFilesInDir", "", "REVERT_HEAD").Return(context.revert)
env.On("hasFolder", "sequencer").Return(context.sequencer)
env.On("getFileContent", "/sequencer/todo").Return(context.sequencerTodo)
env.On("hasFilesInDir", "", "MERGE_MSG").Return(context.merge) env.On("hasFilesInDir", "", "MERGE_MSG").Return(context.merge)
env.On("hasFilesInDir", "", "MERGE_HEAD").Return(context.merge) env.On("hasFilesInDir", "", "MERGE_HEAD").Return(context.merge)
env.mockGitCommand(context.currentCommit, "rev-parse", "--short", "HEAD") env.mockGitCommand(context.currentCommit, "rev-parse", "--short", "HEAD")
@ -211,6 +219,84 @@ func TestGetGitHEADContextCherryPickOnTag(t *testing.T) {
assert.Equal(t, want, got) assert.Equal(t, want, got)
} }
func TestGetGitHEADContextRevertOnBranch(t *testing.T) {
want := "\uf0e2 pickme onto \ue0a0main"
context := &detachedContext{
currentCommit: "whatever",
branchName: "main",
revert: true,
revertSHA: "pickme",
}
g := setupHEADContextEnv(context)
got := g.getGitHEADContext("main")
assert.Equal(t, want, got)
}
func TestGetGitHEADContextRevertOnTag(t *testing.T) {
want := "\uf0e2 pickme onto \uf412v3.4.6"
context := &detachedContext{
currentCommit: "whatever",
tagName: "v3.4.6",
revert: true,
revertSHA: "pickme",
}
g := setupHEADContextEnv(context)
got := g.getGitHEADContext("")
assert.Equal(t, want, got)
}
func TestGetGitHEADContextSequencerCherryPickOnBranch(t *testing.T) {
want := "\ue29b pickme onto \ue0a0main"
context := &detachedContext{
currentCommit: "whatever",
branchName: "main",
sequencer: true,
sequencerTodo: "pick pickme",
}
g := setupHEADContextEnv(context)
got := g.getGitHEADContext("main")
assert.Equal(t, want, got)
}
func TestGetGitHEADContextSequencerCherryPickOnTag(t *testing.T) {
want := "\ue29b pickme onto \uf412v3.4.6"
context := &detachedContext{
currentCommit: "whatever",
tagName: "v3.4.6",
sequencer: true,
sequencerTodo: "pick pickme",
}
g := setupHEADContextEnv(context)
got := g.getGitHEADContext("")
assert.Equal(t, want, got)
}
func TestGetGitHEADContextSequencerRevertOnBranch(t *testing.T) {
want := "\ue29b pickme onto \ue0a0main"
context := &detachedContext{
currentCommit: "whatever",
branchName: "main",
sequencer: true,
sequencerTodo: "revert pickme",
}
g := setupHEADContextEnv(context)
got := g.getGitHEADContext("main")
assert.Equal(t, want, got)
}
func TestGetGitHEADContextSequencerRevertOnTag(t *testing.T) {
want := "\ue29b pickme onto \uf412v3.4.6"
context := &detachedContext{
currentCommit: "whatever",
tagName: "v3.4.6",
sequencer: true,
sequencerTodo: "revert pickme",
}
g := setupHEADContextEnv(context)
got := g.getGitHEADContext("")
assert.Equal(t, want, got)
}
func TestGetGitHEADContextMerge(t *testing.T) { func TestGetGitHEADContextMerge(t *testing.T) {
want := "\ue727 \ue0a0feat into \ue0a0main" want := "\ue727 \ue0a0feat into \ue0a0main"
context := &detachedContext{ context := &detachedContext{