Skip to content

Commit

Permalink
Refactor code to comply to CodeClimate recommandations (part 1/2)
Browse files Browse the repository at this point in the history
  • Loading branch information
obourdon committed Oct 23, 2020
1 parent 4c1aeaf commit 832eb22
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
30 changes: 3 additions & 27 deletions outputs/rspecish.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func (r Rspecish) ValidOptions() []*formatOption {

func (r Rspecish) Output(w io.Writer, results <-chan []resource.TestResult,
startTime time.Time, outConfig util.OutputConfig) (exitCode int) {

testCount := 0
var failedOrSkipped [][]resource.TestResult
var skipped, failed int
Expand All @@ -28,36 +27,15 @@ func (r Rspecish) Output(w io.Writer, results <-chan []resource.TestResult,
for _, testResult := range resultGroup {
switch testResult.Result {
case resource.SUCCESS:
log.Printf("[TRACE] SUCCESS: %s => %s (%s %+v %+v) [%.02f]",
testResult.ResourceType,
testResult.ResourceId,
testResult.Property,
testResult.Expected,
testResult.Found,
testResult.Duration.Seconds(),
)
logTrace("TRACE", "SUCCESS", testResult)
fmt.Fprintf(w, green("."))
case resource.SKIP:
log.Printf("[TRACE] SKIP: %s => %s (%s %+v %+v) [%.02f]",
testResult.ResourceType,
testResult.ResourceId,
testResult.Property,
testResult.Expected,
testResult.Found,
testResult.Duration.Seconds(),
)
logTrace("TRACE", "SKIP", testResult)
fmt.Fprintf(w, yellow("S"))
failedOrSkippedGroup = append(failedOrSkippedGroup, testResult)
skipped++
case resource.FAIL:
log.Printf("[WARN] FAIL: %s => %s (%s %+v %+v) [%.02f]",
testResult.ResourceType,
testResult.ResourceId,
testResult.Property,
testResult.Expected,
testResult.Found,
testResult.Duration.Seconds(),
)
logTrace("WARN", "FAIL", testResult)
fmt.Fprintf(w, red("F"))
failedOrSkippedGroup = append(failedOrSkippedGroup, testResult)
failed++
Expand All @@ -68,10 +46,8 @@ func (r Rspecish) Output(w io.Writer, results <-chan []resource.TestResult,
failedOrSkipped = append(failedOrSkipped, failedOrSkippedGroup)
}
}

fmt.Fprint(w, "\n\n")
fmt.Fprint(w, failedOrSkippedSummary(failedOrSkipped))

outstr := summary(startTime, testCount, failed, skipped)
fmt.Fprint(w, outstr)
resstr := strings.ReplaceAll(outstr, "\n", " ")
Expand Down
20 changes: 20 additions & 0 deletions outputs/traces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package outputs

import (
"log"

"github.com/aelsabbahy/goss/resource"
)

func logTrace(level string, msg string, testResult resource.TestResult) {
log.Printf("[%s] %s: %s => %s (%s %+v %+v) [%.02f]",
level,
msg,
testResult.ResourceType,
testResult.ResourceId,
testResult.Property,
testResult.Expected,
testResult.Found,
testResult.Duration.Seconds(),
)
}
1 change: 0 additions & 1 deletion serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package goss

import (
"bytes"
"errors"
"fmt"
"log"
"net/http"
Expand Down

0 comments on commit 832eb22

Please sign in to comment.