Skip to content

Commit

Permalink
update some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
owenrumney committed Feb 7, 2021
1 parent 5e75153 commit 5365441
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
9 changes: 3 additions & 6 deletions cmd/squealer/main.go
Expand Up @@ -16,7 +16,7 @@ var rootcmd = &cobra.Command{
Use: "squeal",
Short: "Search for secrets and squeal about them",
Long: `Start commit searching`,
Run: startSquealing,
Run: squeal,
}

var (
Expand All @@ -27,7 +27,7 @@ var (
fromHash string
)

func startSquealing(_ *cobra.Command, args []string) {
func squeal(_ *cobra.Command, args []string) {
var basePath = "./"
if len(args) > 0 {
basePath = args[0]
Expand Down Expand Up @@ -57,10 +57,7 @@ func startSquealing(_ *cobra.Command, args []string) {
if !concise {
fmt.Println(printMetrics(metrics))
}
if metrics.TransgressionsReported > 0 {
os.Exit(1)
}
os.Exit(0)
os.Exit(int(metrics.TransgressionsReported))
}

func printMetrics(metrics *mertics.Metrics) string {
Expand Down
38 changes: 38 additions & 0 deletions internal/app/squealer/match/transgression_test.go
@@ -0,0 +1,38 @@
package match

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestTransgressionOutputString(t *testing.T) {
tr := createTestTransgression()

assert.Equal(t, `
content: | password=Password1234
filename: | /config.yml
hash: | sdjn34rf32fds
exclude rule: | /config.yml:sdjn34rf32fds
`, tr.String())
}

func TestTransgressionOutputRedacted(t *testing.T) {
tr := createTestTransgression()

assert.Equal(t, `
content: | password=REDACTED
filename: | /config.yml
hash: | sdjn34rf32fds
exclude rule: | /config.yml:sdjn34rf32fds
`, tr.String())
}

func createTestTransgression() Transgression {
return Transgression{
lineContent: "password=Password1234",
filename: "/config.yml",
hash: "sdjn34rf32fds",
match: "Password1234",
redacted: "password=REDACTED",
}
}

0 comments on commit 5365441

Please sign in to comment.