Skip to content

Commit

Permalink
fix(2952): encode percent of rootDir (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
yk634 authored Nov 29, 2023
1 parent 947fa5f commit 23cc7ab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
4 changes: 3 additions & 1 deletion screwdriver/screwdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ func (a api) GetAPIURL() (string, error) {

// Get coverage object with coverage information
func (a api) GetCoverageInfo(jobID, pipelineID int, jobName, pipelineName, scope, prNum, prParentJobId string) (coverage Coverage, err error) {
url, err := a.makeURL(fmt.Sprintf(CoverageURL, jobID, pipelineID, jobName, pipelineName, scope, prNum, prParentJobId))
// If pipelineName contains a percent sign (%), it needs to be encoded to ensure the URL can be parsed correctly.
encodedPipelineName := strings.Replace(pipelineName, "%", "%25", -1)
url, err := a.makeURL(fmt.Sprintf(CoverageURL, jobID, pipelineID, jobName, encodedPipelineName, scope, prNum, prParentJobId))
body, err := a.get(url)
if err != nil {
return coverage, err
Expand Down
30 changes: 21 additions & 9 deletions screwdriver/screwdriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,28 +252,40 @@ func TestGetCoverageInfo(t *testing.T) {
"SD_SONAR_ENTERPRISE": false,
}
tests := []struct {
coverage Coverage
statusCode int
err error
pipelineName string
coverage Coverage
statusCode int
err error
}{
{
pipelineName: "d2lam/mytest",
coverage: Coverage{
EnvVars: envVars,
},
statusCode: 200,
err: nil,
},
{
coverage: Coverage{},
statusCode: 500,
pipelineName: "specialCharacter/!\"#$%&'()-=|@`{;+]},<.> 🚗",
coverage: Coverage{
EnvVars: envVars,
},
statusCode: 200,
err: nil,
},
{
pipelineName: "d2lam/mytest",
coverage: Coverage{},
statusCode: 500,
err: errors.New("WARNING: received error from GET(http://fakeurl/v4/coverage/info?jobId=123&pipelineId=456&jobName=main&pipelineName=d2lam/mytest&scope=&prNum=&prParentJobId=): " +
"Get \"http://fakeurl/v4/coverage/info?jobId=123&pipelineId=456&jobName=main&pipelineName=d2lam/mytest&scope=&prNum=&prParentJobId=\": " +
"GET http://fakeurl/v4/coverage/info?jobId=123&pipelineId=456&jobName=main&pipelineName=d2lam/mytest&scope=&prNum=&prParentJobId= giving up after 5 attempts "),
},
{
coverage: Coverage{},
statusCode: 404,
err: errors.New("WARNING: received response 404 from http://fakeurl/v4/coverage/info?jobId=123&pipelineId=456&jobName=main&pipelineName=d2lam/mytest&scope=&prNum=&prParentJobId= "),
pipelineName: "d2lam/mytest",
coverage: Coverage{},
statusCode: 404,
err: errors.New("WARNING: received response 404 from http://fakeurl/v4/coverage/info?jobId=123&pipelineId=456&jobName=main&pipelineName=d2lam/mytest&scope=&prNum=&prParentJobId= "),
},
}

Expand All @@ -288,7 +300,7 @@ func TestGetCoverageInfo(t *testing.T) {
client.HTTPClient = makeFakeHTTPClient(t, test.statusCode, string(JSON))
testAPI := api{"http://fakeurl", "faketoken", client}

coverage, err := testAPI.GetCoverageInfo(123, 456, "main", "d2lam/mytest", "", "", "")
coverage, err := testAPI.GetCoverageInfo(123, 456, "main", test.pipelineName, "", "", "")

if !reflect.DeepEqual(err, test.err) {
t.Errorf("Unexpected error from GetCoverageInfo: \n%v\n want \n%v", err.Error(), test.err.Error())
Expand Down

0 comments on commit 23cc7ab

Please sign in to comment.