Skip to content

Commit 7b3ab43

Browse files
Merge pull request #38 from deads2k/test-with-logging
Wire the ginkgo logr to the same writer during ginkgo setup
2 parents 5415620 + c3b8a0c commit 7b3ab43

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

pkg/ginkgo/logging.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package ginkgo
2+
3+
import (
4+
"github.com/go-logr/logr"
5+
"github.com/go-logr/logr/funcr"
6+
"github.com/onsi/ginkgo/v2"
7+
)
8+
9+
// this is copied from ginkgo because ginkgo made it internal and then hardcoded an init block
10+
// using these functions to wire to os.stdout and we want to wire to stderr (or a different buffer) so we can
11+
// have json output.
12+
13+
func GinkgoLogrFunc(writer ginkgo.GinkgoWriterInterface) logr.Logger {
14+
return funcr.New(func(prefix, args string) {
15+
if prefix == "" {
16+
writer.Printf("%s\n", args)
17+
} else {
18+
writer.Printf("%s %s\n", prefix, args)
19+
}
20+
}, funcr.Options{})
21+
}

pkg/ginkgo/parallel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func SpawnProcessToRunTest(ctx context.Context, testName string, timeout time.Du
7474
}
7575

7676
fmt.Fprintf(stderr, "Command Error: %v\n", cmdErr)
77-
fmt.Fprintf(stderr, "Deserializaion Erroer: %v\n", parseErr)
77+
fmt.Fprintf(stderr, "Deserializaion Error: %v\n", parseErr)
7878
return newTestResult(testName, result, start, time.Now(), stdout, stderr)
7979
}
8080

pkg/ginkgo/util.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func configureGinkgo() (*types.SuiteConfig, *types.ReporterConfig, error) {
3636

3737
// Write output to Stderr
3838
ginkgo.GinkgoWriter = ginkgo.NewWriter(os.Stderr)
39+
ginkgo.GinkgoLogr = GinkgoLogrFunc(ginkgo.GinkgoWriter)
3940

4041
gomega.RegisterFailHandler(ginkgo.Fail)
4142

test/framework/info.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,8 @@ var _ = Describe("[sig-testing] example-tests info", Label("framework"), func()
4040
Expect(result.Component.Kind).To(Equal("payload"), "Expected type to be 'payload'")
4141
Expect(result.Component.Name).To(Equal("example-tests"), "Expected name to be 'default'")
4242
})
43+
44+
It("should be able to log information", func() {
45+
GinkgoLogr.Info("creating resource group", "resourceGroup", "resourceGroupName")
46+
})
4347
})

0 commit comments

Comments
 (0)