-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retrieve quality gate status after the analysis is finished
- Loading branch information
1 parent
4beb848
commit 85b73d2
Showing
7 changed files
with
263 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package sonarscanner | ||
|
||
import "fmt" | ||
|
||
type AnalysisStatus int | ||
|
||
const ( | ||
AnalysisStatusUndefined AnalysisStatus = iota | ||
AnalysisStatusOk AnalysisStatus = iota | ||
AnalysisStatusWarning AnalysisStatus = iota | ||
AnalysisStatusError AnalysisStatus = iota | ||
AnalysisStatusNone AnalysisStatus = iota | ||
) | ||
|
||
const ( | ||
analysisStatusUndefinedStr = "UNDEFINED" | ||
analysisStatusOkStr = "OK" | ||
analysisStatusWarningStr = "WARN" | ||
analysisStatusErrorStr = "ERROR" | ||
analysisStatusNoneStr = "NONE" | ||
) | ||
|
||
func (status AnalysisStatus) String() string { | ||
switch status { | ||
case AnalysisStatusOk: | ||
return analysisStatusOkStr | ||
case AnalysisStatusWarning: | ||
return analysisStatusWarningStr | ||
case AnalysisStatusError: | ||
return analysisStatusErrorStr | ||
case AnalysisStatusNone: | ||
return analysisStatusNoneStr | ||
default: | ||
return analysisStatusUndefinedStr | ||
} | ||
} | ||
|
||
func parseAnalysisStatus(value string) (AnalysisStatus, error) { | ||
switch value { | ||
case analysisStatusOkStr: | ||
return AnalysisStatusOk, nil | ||
case analysisStatusWarningStr: | ||
return AnalysisStatusWarning, nil | ||
case analysisStatusErrorStr: | ||
return AnalysisStatusError, nil | ||
case analysisStatusNoneStr: | ||
return AnalysisStatusNone, nil | ||
default: | ||
return AnalysisStatusUndefined, fmt.Errorf("unexpected analysis status '%s'", value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package sonarscanner | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAnalysisStatusToString(t *testing.T) { | ||
assert.Equal(t, "OK", fmt.Sprint(AnalysisStatusOk)) | ||
assert.Equal(t, "WARN", fmt.Sprint(AnalysisStatusWarning)) | ||
assert.Equal(t, "ERROR", fmt.Sprint(AnalysisStatusError)) | ||
assert.Equal(t, "NONE", fmt.Sprint(AnalysisStatusNone)) | ||
assert.Equal(t, "UNDEFINED", fmt.Sprint(AnalysisStatusUndefined)) | ||
} | ||
|
||
func TestParseAnalysisStatus(t *testing.T) { | ||
assertAnalysisStatusParsedAs(t, "OK", AnalysisStatusOk) | ||
assertAnalysisStatusParsedAs(t, "WARN", AnalysisStatusWarning) | ||
assertAnalysisStatusParsedAs(t, "ERROR", AnalysisStatusError) | ||
assertAnalysisStatusParsedAs(t, "NONE", AnalysisStatusNone) | ||
} | ||
|
||
func TestParseInvalidAnalysisStatus(t *testing.T) { | ||
status, err := parseAnalysisStatus("UNDEFINED") | ||
|
||
assert.NotNil(t, err) | ||
assert.Equal(t, AnalysisStatusUndefined, status) | ||
} | ||
|
||
func assertAnalysisStatusParsedAs(t *testing.T, value string, expectedStatus AnalysisStatus) { | ||
actualStatus, err := parseAnalysisStatus(value) | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, expectedStatus, actualStatus) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.