Skip to content

Commit

Permalink
Update tests for new command
Browse files Browse the repository at this point in the history
  • Loading branch information
FayeSGW committed Aug 21, 2024
1 parent 85c564e commit a65c8d8
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 50 deletions.
128 changes: 81 additions & 47 deletions cmd/kosli/attestSonar_test.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmd/kosli/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func newAttestationForm(payload interface{}, attachments []string) (

func wrapAttestationError(err error) error {
if err != nil {
return fmt.Errorf(strings.Replace(err.Error(), "requires at least one of: artifact_fingerprint or git_commit_info.",
return fmt.Errorf("%s", strings.Replace(err.Error(), "requires at least one of: artifact_fingerprint or git_commit_info.",
"requires at least one of: specifying the fingerprint (either by calculating it using the artifact name/path and --artifact-type, or by providing it using --fingerprint) or providing --commit (requires an available git repo to access commit details)", 1))
}
return err
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
organization=fayesgw
projectKey=FayeSGW_Hangman
serverUrl=https://sonarcloud.io
serverVersion=8.0.0.56246
dashboardUrl=https://sonarcloud.io/dashboard?id=FayeSGW_Hangman
ceTaskId=AZE2jzvUF2N-a1ygL1sM
ceTaskUrl=https://sonarcloud.io/api/ce/task?id=AZE2jzvUF2N-a1ygL1sM
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
projectKey=test5
serverUrl=http://localhost:9000
serverVersion=10.6.0.92116
dashboardUrl=http://localhost:9000/dashboard?id=test5
ceTaskId=9427d05e-a671-4942-95c4-ff0595b6f0fe
ceTaskUrl=http://localhost:9000/api/ce/task?id=9427d05e-a671-4942-95c4-ff0595b6f0fe
2 changes: 1 addition & 1 deletion internal/requests/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (c *Client) Do(p *RequestParams) (*HTTPResponse, error) {
cleanedErrorMessage = fmt.Sprintf("%s", respBodyMap)
}
}
return nil, fmt.Errorf(cleanedErrorMessage)
return nil, fmt.Errorf("%s", cleanedErrorMessage)
}
return &HTTPResponse{string(body), resp}, nil
}
Expand Down
5 changes: 4 additions & 1 deletion internal/sonar/sonar.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ type Branch struct {
type QualityGate struct {
Status string `json:"status"`
Conditions []Condition `json:"conditions"`
//Name string `json:"name"` I cannot find a way to find out which quality gate was used for a specific scan
}

type Condition struct {
Expand Down Expand Up @@ -203,6 +202,10 @@ func GetCETaskData(httpClient *http.Client, project *Project, sonarResults *Sona
analysisId := taskResponseData.Task.AnalysisID
sonarResults.Status = taskResponseData.Task.Status

if analysisId == "" {
return "", fmt.Errorf("analysis ID not found. Please check the ceTaskURL is correct")
}

if project.Url == "" {
project.Url = fmt.Sprintf("%s/dashboard?id=%s", sonarResults.ServerUrl, project.Key)
}
Expand Down

0 comments on commit a65c8d8

Please sign in to comment.