1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

Add slash backslash compatibility (#2425)

Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
This commit is contained in:
Sven Merk 2020-11-26 09:18:01 +01:00 committed by GitHub
parent 104435c8dd
commit 26af83b1fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -622,7 +622,7 @@ func (sys *SystemInstance) DownloadReport(reportID int) ([]byte, error) {
// FilterTeamByName filters a team by its name
func (sys *SystemInstance) FilterTeamByName(teams []Team, teamName string) Team {
for _, team := range teams {
if team.FullName == teamName {
if team.FullName == teamName || strings.ReplaceAll(team.FullName, `\`, `/`) == teamName {
return team
}
}

View File

@ -167,17 +167,18 @@ func TestGetTeams(t *testing.T) {
logger := log.Entry().WithField("package", "SAP/jenkins-library/pkg/checkmarx_test")
opts := piperHttp.ClientOptions{}
t.Run("test success", func(t *testing.T) {
myTestClient := senderMock{responseBody: `[{"id":"1", "fullName":"Team1"}, {"id":2, "fullName":"Team2"}, {"id":3, "fullName":"Team3"}]`, httpStatusCode: 200}
myTestClient := senderMock{responseBody: `[{"id":"1", "fullName":"Team1"}, {"id":2, "fullName":"Team2"}, {"id":3, "fullName":"Team3"}, {"id":4, "fullName":"Team\\4"}]`, httpStatusCode: 200}
sys := SystemInstance{serverURL: "https://cx.server.com", client: &myTestClient, logger: logger}
myTestClient.SetOptions(opts)
teams := sys.GetTeams()
assert.Equal(t, "https://cx.server.com/cxrestapi/auth/teams", myTestClient.urlCalled, "Called url incorrect")
assert.Equal(t, 3, len(teams), "Number of Teams incorrect")
assert.Equal(t, 4, len(teams), "Number of Teams incorrect")
assert.Equal(t, "Team1", teams[0].FullName, "Team name 1 incorrect")
assert.Equal(t, "Team2", teams[1].FullName, "Team name 2 incorrect")
assert.Equal(t, "Team3", teams[2].FullName, "Team name 3 incorrect")
assert.Equal(t, "Team\\4", teams[3].FullName, "Team name 4 incorrect")
t.Run("test filter teams by name", func(t *testing.T) {
team2 := sys.FilterTeamByName(teams, "Team2")
@ -185,6 +186,12 @@ func TestGetTeams(t *testing.T) {
assert.Equal(t, json.RawMessage([]byte(strconv.Itoa(2))), team2.ID, "Team id incorrect")
})
t.Run("test filter teams by name with backslash/forward slash", func(t *testing.T) {
team4 := sys.FilterTeamByName(teams, "Team/4")
assert.Equal(t, "Team\\4", team4.FullName, "Team name incorrect")
assert.Equal(t, json.RawMessage([]byte(strconv.Itoa(4))), team4.ID, "Team id incorrect")
})
t.Run("test Filter teams by ID", func(t *testing.T) {
team1 := sys.FilterTeamByID(teams, json.RawMessage(`"1"`))
assert.Equal(t, "Team1", team1.FullName, "Team name incorrect")