mirror of
https://github.com/vee1e/runtimeclass-debugger.git
synced 2026-09-01 18:27:58 +00:00
53 lines
941 B
Go
53 lines
941 B
Go
package diag
|
|
|
|
// Status is the outcome of a single check.
|
|
type Status string
|
|
|
|
const (
|
|
StatusPass Status = "pass"
|
|
StatusFail Status = "fail"
|
|
StatusWarn Status = "warn"
|
|
StatusSkip Status = "skip"
|
|
)
|
|
|
|
const (
|
|
ExitOK = 0
|
|
ExitFail = 1
|
|
ExitWarn = 2
|
|
ExitError = 3
|
|
)
|
|
|
|
// CheckResult is the outcome of a single check.
|
|
type CheckResult struct {
|
|
ID string
|
|
Status Status
|
|
Detail string
|
|
}
|
|
|
|
// Report is the full set of check results for one run.
|
|
type Report struct {
|
|
Checks []CheckResult
|
|
ExitCode int
|
|
}
|
|
|
|
// ComputeExitCode derives the exit code from the checks:
|
|
// 0 = all pass; 1 = any fail; 2 = any warn and no fail.
|
|
func (r *Report) ComputeExitCode() int {
|
|
hasFail, hasWarn := false, false
|
|
for _, c := range r.Checks {
|
|
switch c.Status {
|
|
case StatusFail:
|
|
hasFail = true
|
|
case StatusWarn:
|
|
hasWarn = true
|
|
}
|
|
}
|
|
switch {
|
|
case hasFail:
|
|
return ExitFail
|
|
case hasWarn:
|
|
return ExitWarn
|
|
default:
|
|
return ExitOK
|
|
}
|
|
}
|