Skip to content

Commit

Permalink
- F CI Now Uses Systemout reporter to print file contents
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclerc-cio committed Nov 22, 2024
1 parent 3b0b06b commit d26ff73
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
3 changes: 3 additions & 0 deletions examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import (
)

func ExampleVerifyString() {
t = makeExamplesRunLikeTests("ExampleVerifyString")

approvals.VerifyString(t, "Hello World!")

printFileContent("examples_test.ExampleVerifyString.received.txt")

// Output:
Expand Down
5 changes: 4 additions & 1 deletion reporter_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package approvals

import (
"fmt"
"os"
"testing"

Expand All @@ -15,7 +16,9 @@ type TestFailable struct {
name string
}

func (s *TestFailable) Fail() {}
func (s *TestFailable) Fail() {
fmt.Println("This test failed")
}
func (s *TestFailable) Name() string {
return s.name

Expand Down
5 changes: 3 additions & 2 deletions reporters/continuous_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ func (s *continuousIntegration) Report(approved, received string) bool {

if exists {
ci, err := strconv.ParseBool(value)
if err == nil {
return ci
if err == nil && ci {
systemout := NewSystemoutReporter()
return systemout.Report(approved, received)
}
}

Expand Down
36 changes: 36 additions & 0 deletions reporters/systemout_reporter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package reporters

import (
"fmt"
"path/filepath"

"github.com/approvals/go-approval-tests/utils"
)

type systemout struct{}

// NewQuietReporter creates a new reporter that does nothing.
func NewSystemoutReporter() Reporter {
return &systemout{}
}

func (s *systemout) Report(approved, received string) bool {

approvedFull, _ := filepath.Abs(approved)
receivedFull, _ := filepath.Abs(received)

fmt.Printf("approval files did not match\napproved: %v\nreceived: %v\n", approvedFull, receivedFull)

printFileContent("Received", receivedFull)
printFileContent("Approved", approvedFull)

return true
}

func printFileContent(label, path string) {
content, err := utils.ReadFile(path)
if err != nil {
content = fmt.Sprintf("** Error reading %s file **", label)
}
fmt.Printf("%s content:\n%s\n", label, content)
}

0 comments on commit d26ff73

Please sign in to comment.