-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from runatlantis/comment-size
Split GitHub comments into multiple if over max.
- Loading branch information
Showing
3 changed files
with
117 additions
and
3 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
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,65 @@ | ||
package vcs | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/runatlantis/atlantis/testing" | ||
) | ||
|
||
func TestSplitAtMaxChars(t *testing.T) { | ||
cases := []struct { | ||
comment string | ||
max int | ||
exp []string | ||
}{ | ||
// Test when comment is <= max length. | ||
{ | ||
"", | ||
5, | ||
[]string{""}, | ||
}, | ||
{ | ||
"1", | ||
5, | ||
[]string{"1"}, | ||
}, | ||
{ | ||
"12345", | ||
5, | ||
[]string{"12345"}, | ||
}, | ||
// Now test when we need to join. | ||
{ | ||
"123456", | ||
5, | ||
[]string{"1join", "2join", "3join", "4join", "5join", "6"}, | ||
}, | ||
{ | ||
"123456", | ||
10, | ||
[]string{"123456"}, | ||
}, | ||
{ | ||
"12345678901", | ||
10, | ||
[]string{"123456join", "78901"}, | ||
}, | ||
// Test the edge case of max < len("join") | ||
{ | ||
"abc", | ||
2, | ||
nil, | ||
}, | ||
{ | ||
"abcde", | ||
4, | ||
nil, | ||
}, | ||
} | ||
for _, c := range cases { | ||
client := GithubClient{} | ||
t.Run(c.comment, func(t *testing.T) { | ||
Equals(t, c.exp, client.splitAtMaxChars(c.comment, c.max, "join")) | ||
}) | ||
} | ||
} |
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