Skip to content

Commit

Permalink
improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
owenrumney committed Feb 6, 2021
1 parent e6cd826 commit 5e75153
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cmd/squealer/main.go
Expand Up @@ -55,17 +55,17 @@ func startSquealing(_ *cobra.Command, args []string) {
}
metrics := scanner.GetMetrics()
if !concise {
printMetrics(metrics)
fmt.Println(printMetrics(metrics))
}
if metrics.TransgressionsReported > 0 {
os.Exit(1)
}
os.Exit(0)
}

func printMetrics(metrics *mertics.Metrics) {
func printMetrics(metrics *mertics.Metrics) string {
duration, _ := metrics.Duration()
fmt.Printf(`
return fmt.Sprintf(`
Processing:
duration: %4.2fs
commits: %d
Expand Down
33 changes: 33 additions & 0 deletions cmd/squealer/main_test.go
@@ -0,0 +1,33 @@
package main

import (
"github.com/owenrumney/squealer/internal/app/squealer/mertics"
"github.com/stretchr/testify/assert"
"testing"
)

func TestPrintMetrics(t *testing.T) {
m := mertics.Metrics{
CommitsProcessed: 1,
FilesProcessed: 2,
TransgressionsFound: 3,
TransgressionsIgnored: 4,
TransgressionsReported: 5,
}
m.StartTimer()
m.StopTimer()

output := printMetrics(&m)
assert.Equal(t, `
Processing:
duration: 0.00s
commits: 1
commit files: 2
transgressionMap:
identified: 3
ignored: 4
reported: 5
`, output)
}

0 comments on commit 5e75153

Please sign in to comment.