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 authored and philou committed Oct 11, 2024
1 parent b7c981b commit cc60918
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 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 @@ -961,6 +961,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
8 changes: 7 additions & 1 deletion src/vcs/fake/vcs_test_fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ type (
remoteName string
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 @@ -101,6 +102,7 @@ func NewVCSFake(settings Settings) *VCSFake {
remoteName: "vcs-fake-remote-name",
lastCommitSubjects: make([]string, 0),
lastCommands: make([]Command, 0),
supportsEmojis: true,
}
}

Expand Down Expand Up @@ -220,3 +222,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 cc60918

Please sign in to comment.