Multiple escaping occurs on Jenkins URLs at certain folder depth (#8048)

Co-author: @hansnqyr
This commit is contained in:
Colin Ameigh 2020-10-07 23:20:26 +01:00 committed by GitHub
parent 74fd427e03
commit 7f7703b8fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 1 deletions

View File

@ -439,7 +439,9 @@ type jobRequest struct {
}
func (jr jobRequest) combined() []string {
return append(jr.parents, jr.name)
path := make([]string, len(jr.parents))
copy(path, jr.parents)
return append(path, jr.name)
}
func (jr jobRequest) combinedEscaped() []string {

View File

@ -602,6 +602,59 @@ func TestGatherJobs(t *testing.T) {
},
},
},
{
name: "gather metrics for nested jobs with space exercising append slice behaviour",
input: mockHandler{
responseMap: map[string]interface{}{
"/api/json": &jobResponse{
Jobs: []innerJob{
{Name: "l1"},
},
},
"/job/l1/api/json": &jobResponse{
Jobs: []innerJob{
{Name: "l2"},
},
},
"/job/l1/job/l2/api/json": &jobResponse{
Jobs: []innerJob{
{Name: "job 1"},
},
},
"/job/l1/job/l2/job/job%201/api/json": &jobResponse{
Jobs: []innerJob{
{Name: "job 2"},
},
},
"/job/l1/job/l2/job/job%201/job/job%202/api/json": &jobResponse{
LastBuild: jobBuild{
Number: 3,
},
},
"/job/l1/job/l2/job/job%201/job/job%202/3/api/json": &buildResponse{
Building: false,
Result: "SUCCESS",
Duration: 25558,
Timestamp: (time.Now().Unix() - int64(time.Minute.Seconds())) * 1000,
},
},
},
output: &testutil.Accumulator{
Metrics: []*testutil.Metric{
{
Tags: map[string]string{
"name": "job 2",
"parents": "l1/l2/job 1",
"result": "SUCCESS",
},
Fields: map[string]interface{}{
"duration": int64(25558),
"result_code": 0,
},
},
},
},
},
{
name: "gather sub jobs, jobs filter",
input: mockHandler{