1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-03-03 15:02:35 +02:00

fix backslash mess (#2428)

This commit is contained in:
Sven Merk 2020-11-26 11:22:54 +01:00 committed by GitHub
parent d952cb89d6
commit 2511ec9cea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 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 || strings.ReplaceAll(team.FullName, `\`, `/`) == teamName {
if team.FullName == teamName || team.FullName == strings.ReplaceAll(teamName, `\`, `/`) {
return team
}
}

View File

@ -167,7 +167,7 @@ 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"}, {"id":4, "fullName":"Team\\4"}]`, 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)
@ -178,7 +178,7 @@ func TestGetTeams(t *testing.T) {
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")
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")
@ -187,8 +187,8 @@ func TestGetTeams(t *testing.T) {
})
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")
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")
})