generated from sonatype-nexus-community/community-project-template
-
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.
Merge pull request #12 from sonatype-nexus-community/feat/handle-unsu…
…pported-branch-names feat: only create SCM Configuration when Default Branch and Repository URL meet IQ requirements
- Loading branch information
Showing
3 changed files
with
180 additions
and
32 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
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 |
---|---|---|
|
@@ -23,6 +23,103 @@ import ( | |
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSafeBranchNameNil(t *testing.T) { | ||
var nil string | ||
assert.Equal(t, false, safeBranchName(nil)) | ||
} | ||
|
||
func TestSafeBranchName(t *testing.T) { | ||
|
||
cases := []struct { | ||
input string | ||
permitted bool | ||
}{ | ||
{ | ||
input: "main", | ||
permitted: true, | ||
}, | ||
{ | ||
input: "master", | ||
permitted: true, | ||
}, | ||
{ | ||
input: "with(bracket", | ||
permitted: false, | ||
}, | ||
{ | ||
input: "with&mpersand", | ||
permitted: false, | ||
}, | ||
{ | ||
input: "ma?in", | ||
permitted: false, | ||
}, | ||
{ | ||
input: "pi|pe", | ||
permitted: false, | ||
}, | ||
{ | ||
input: "give;injection", | ||
permitted: false, | ||
}, | ||
{ | ||
input: "give~injection", | ||
permitted: false, | ||
}, | ||
{ | ||
input: "give%injection", | ||
permitted: false, | ||
}, | ||
{ | ||
input: "give'injection", | ||
permitted: false, | ||
}, | ||
{ | ||
input: ".start-period", | ||
permitted: false, | ||
}, | ||
{ | ||
input: "end-period.", | ||
permitted: false, | ||
}, | ||
{ | ||
input: "end-slash/", | ||
permitted: false, | ||
}, | ||
} | ||
|
||
for i, tc := range cases { | ||
t.Run(fmt.Sprintf("TestSafeBranchName-%d-%s", i, tc.input), func(t *testing.T) { | ||
assert.Equal(t, tc.permitted, safeBranchName(tc.input)) | ||
}) | ||
} | ||
} | ||
|
||
func TestSafeRepositoryUrl(t *testing.T) { | ||
|
||
cases := []struct { | ||
input string | ||
permitted bool | ||
}{ | ||
{ | ||
input: "https://[email protected]/REDACTED/Scan-Test-1/_git/main", | ||
permitted: true, | ||
}, { | ||
input: "https://[email protected]/REDACTED/Scan-Test-1/_git/Craz%28%29y%20Repo", | ||
permitted: false, | ||
}, { | ||
input: "https://dev.azure.com/PHorton0655/Scan-Test-1/_git/Craz%28%29y%20Repo", | ||
permitted: false, | ||
}, | ||
} | ||
|
||
for i, tc := range cases { | ||
t.Run(fmt.Sprintf("TestSafeRepositoryUrl-%d-%s", i, tc.input), func(t *testing.T) { | ||
assert.Equal(t, tc.permitted, safeRepositoryUrl(tc.input)) | ||
}) | ||
} | ||
} | ||
|
||
func TestScmSafeName(t *testing.T) { | ||
|
||
cases := []struct { | ||
|