Skip to content

Commit

Permalink
[#805] Update tcr.wrapCommitMessage() so that it includes or not the …
Browse files Browse the repository at this point in the history
…emoji depending on the VCS support for emojis

- Added a property in the vcs_test_fake for the emojis
- Added a test for the two variance of the method
  • Loading branch information
aatwi committed Oct 11, 2024
1 parent 002635c commit 1ace24f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/engine/tcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func (tcr *TCREngine) setMessageSuffix(suffix string) {
}

func (tcr *TCREngine) wrapCommitMessages(header CommitMessage, event *events.TCREvent) []string {
messages := []string{header.toString(true)}
messages := []string{header.toString(tcr.vcs.SupportsEmojis())}
if event != nil {
messages = append(messages, event.ToYAML())
}
Expand Down
19 changes: 19 additions & 0 deletions src/engine/tcr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,25 @@ func Test_adding_suffix_to_tcr_commit_messages(t *testing.T) {
}
}

func Test_building_the_commit_message_depending_on_the_vcs(t *testing.T) {
tests := []struct {
desc string
supportsEmoji bool
}{
{"with vcs supporting emoji", true},
{"with vcs not supporting emoji", false},
}
for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
p := params.AParamSet(params.WithRunMode(runmode.OneShot{}))
tcr, vcsFake := initTCREngineWithFakes(p, nil, nil, nil)
vcsFake.SetSupportsEmojis(test.supportsEmoji)
result := tcr.wrapCommitMessages(messagePassed, events.ATcrEvent())
assert.Equal(t, test.supportsEmoji, strings.ContainsRune(result[0], messagePassed.Emoji))
})
}
}

func Test_count_files(t *testing.T) {
tests := []struct {
desc string
Expand Down
9 changes: 7 additions & 2 deletions src/vcs/fake/vcs_test_fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ type (
pushEnabled bool
lastCommands []Command
lastCommitSubjects []string
supportsEmojis bool
}
)

func (vf *VCSFake) SupportsEmojis() bool {
return true
return vf.supportsEmojis
}

func (vf *VCSFake) fakeCommand(cmd Command) (err error) {
Expand All @@ -95,7 +96,7 @@ func (vf *VCSFake) fakeCommand(cmd Command) (err error) {
// NewVCSFake initializes a fake VCS implementation which does nothing
// apart from emulating errors on VCS operations
func NewVCSFake(settings Settings) *VCSFake {
return &VCSFake{settings: settings, lastCommitSubjects: make([]string, 0), lastCommands: make([]Command, 0)}
return &VCSFake{settings: settings, lastCommitSubjects: make([]string, 0), lastCommands: make([]Command, 0), supportsEmojis: true}
}

// Name returns VCS name
Expand Down Expand Up @@ -214,3 +215,7 @@ func (vf *VCSFake) CheckRemoteAccess() bool {
func (vf *VCSFake) GetLastCommitSubjects() []string {
return vf.lastCommitSubjects
}

func (vf *VCSFake) SetSupportsEmojis(flag bool) {
vf.supportsEmojis = flag
}

0 comments on commit 1ace24f

Please sign in to comment.