forked from openshift/enhancements
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move title cleanup to its own testable function
Signed-off-by: Doug Hellmann <[email protected]>
- Loading branch information
Showing
5 changed files
with
64 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package enhancements | ||
|
||
import "strings" | ||
|
||
func CleanTitle(title string) string { | ||
// Sometimes we have a superfluous "enhancement:" prefix in | ||
// the PR title | ||
if strings.HasPrefix(strings.ToLower(title), "enhancement:") { | ||
title = strings.TrimLeft(title[12:], " ") | ||
} | ||
return title | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package enhancements | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCleanTitle(t *testing.T) { | ||
for _, tc := range []struct { | ||
Scenario string | ||
Input string | ||
Expected string | ||
}{ | ||
{ | ||
Scenario: "empty-string", | ||
Input: "", | ||
Expected: "", | ||
}, | ||
{ | ||
Scenario: "no-changes", | ||
Input: "this is a perfectly nice title", | ||
Expected: "this is a perfectly nice title", | ||
}, | ||
{ | ||
Scenario: "enhancement-prefix", | ||
Input: "enhancement: remove the prefix", | ||
Expected: "remove the prefix", | ||
}, | ||
{ | ||
Scenario: "enhancement-prefix-caps", | ||
Input: "Enhancement: Remove the prefix", | ||
Expected: "Remove the prefix", | ||
}, | ||
} { | ||
t.Run(tc.Scenario, func(t *testing.T) { | ||
actual := CleanTitle(tc.Input) | ||
assert.Equal(t, tc.Expected, actual) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters