generated from wayfair-incubator/oss-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix > 250 char Branch name issue (#188)
* Fix > 250 char Branch name issue Move brnach name generation to a function. Limit original branch substing to 200 charts Switch target paths substring to sha1 of the target paths. Tests * Address isssus raised in PR reivew Rename a var Used Repeat to avoid hardcoding long string Made some test input **a bit** more realistic
- Loading branch information
Showing
2 changed files
with
86 additions
and
1 deletion.
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,64 @@ | ||
package githubapi | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
func TestGenerateSafePromotionBranchName(t *testing.T) { | ||
t.Parallel() | ||
prNumber := 11 | ||
originBranch := "originBranch" | ||
targetPaths := []string{"targetPath1", "targetPath2"} | ||
result := generateSafePromotionBranchName(prNumber, originBranch, targetPaths) | ||
expectedResult := "promotions/11-originBranch-676f02019f18" | ||
if result != expectedResult { | ||
t.Errorf("Expected %s, got %s", expectedResult, result) | ||
} | ||
} | ||
|
||
// TestGenerateSafePromotionBranchNameLongBranchName tests the case where the original branch name is longer than 250 characters | ||
func TestGenerateSafePromotionBranchNameLongBranchName(t *testing.T) { | ||
t.Parallel() | ||
prNumber := 11 | ||
|
||
originBranch := string(bytes.Repeat([]byte("originBranch"), 100)) | ||
targetPaths := []string{"targetPath1", "targetPath2"} | ||
result := generateSafePromotionBranchName(prNumber, originBranch, targetPaths) | ||
if len(result) > 250 { | ||
t.Errorf("Expected branch name to be less than 250 characters, got %d", len(result)) | ||
} | ||
} | ||
|
||
// TestGenerateSafePromotionBranchNameLongTargets tests the case where the target paths are longer than 250 characters | ||
func TestGenerateSafePromotionBranchNameLongTargets(t *testing.T) { | ||
t.Parallel() | ||
prNumber := 11 | ||
originBranch := "originBranch" | ||
targetPaths := []string{ | ||
"loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong/target/path/1", | ||
"loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong/target/path/2", | ||
"loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong/target/path/3", | ||
"loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong/target/path/4", | ||
"loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong/target/path/5", | ||
"loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong/target/path/6", | ||
"loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong/target/path/7", | ||
"loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong/target/path/8", | ||
"loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong/target/path/9", | ||
"loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong/target/path/10", | ||
"loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong/target/path/11", | ||
"loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong/target/path/12", | ||
"loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong/target/path/13", | ||
"loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong/target/path/14", | ||
"loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong/target/path/15", | ||
"loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong/target/path/16", | ||
"loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong/target/path/17", | ||
"loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong/target/path/18", | ||
"loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong/target/path/19", | ||
"loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong/target/path/20", | ||
} | ||
result := generateSafePromotionBranchName(prNumber, originBranch, targetPaths) | ||
if len(result) > 250 { | ||
t.Errorf("Expected branch name to be less than 250 characters, got %d", len(result)) | ||
} | ||
} |