Skip to content

Commit

Permalink
Eliminate rubbish logs in pkg/conversion test
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtek-t committed Dec 22, 2015
1 parent 1f26fa4 commit 55747ec
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions pkg/conversion/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ import (
"github.com/google/gofuzz"
)

func testLogger(t *testing.T) DebugLogger {
// We don't set logger to eliminate rubbish logs in tests.
// If you want to switch it, simply switch it to: "return t"
return nil
}

func TestConverter_byteSlice(t *testing.T) {
c := NewConverter()
src := []byte{1, 2, 3}
Expand Down Expand Up @@ -77,7 +83,7 @@ func TestConverter_DefaultConvert(t *testing.T) {
Baz int
}
c := NewConverter()
c.Debug = t
c.Debug = testLogger(t)
c.nameFunc = func(t reflect.Type) string { return "MyType" }

// Ensure conversion funcs can call DefaultConvert to get default behavior,
Expand Down Expand Up @@ -116,7 +122,7 @@ func TestConverter_DeepCopy(t *testing.T) {
Qux map[string]string
}
c := NewConverter()
c.Debug = t
c.Debug = testLogger(t)

foo, baz := "foo", "baz"
x := A{
Expand Down Expand Up @@ -159,7 +165,7 @@ func TestConverter_CallsRegisteredFunctions(t *testing.T) {
}
type C struct{}
c := NewConverter()
c.Debug = t
c.Debug = testLogger(t)
err := c.RegisterConversionFunc(func(in *A, out *B, s Scope) error {
out.Bar = in.Foo
return s.Convert(&in.Baz, &out.Baz, 0)
Expand Down Expand Up @@ -244,7 +250,7 @@ func TestConverter_MapsStringArrays(t *testing.T) {
Other string
}
c := NewConverter()
c.Debug = t
c.Debug = testLogger(t)
if err := c.RegisterConversionFunc(func(input *[]string, out *string, s Scope) error {
if len(*input) == 0 {
*out = ""
Expand Down Expand Up @@ -297,7 +303,7 @@ func TestConverter_MapsStringArraysWithMappingKey(t *testing.T) {
Other string
}
c := NewConverter()
c.Debug = t
c.Debug = testLogger(t)
if err := c.RegisterConversionFunc(func(input *[]string, out *string, s Scope) error {
if len(*input) == 0 {
*out = ""
Expand Down Expand Up @@ -356,7 +362,7 @@ func TestConverter_fuzz(t *testing.T) {
reflect.TypeOf(ExternalTestType2{}): "TestType2",
}[t]
}
c.Debug = t
c.Debug = testLogger(t)

for i, item := range table {
for j := 0; j < *fuzzIters; j++ {
Expand Down Expand Up @@ -386,7 +392,7 @@ func TestConverter_MapElemAddr(t *testing.T) {
A map[string]string
}
c := NewConverter()
c.Debug = t
c.Debug = testLogger(t)
err := c.RegisterConversionFunc(
func(in *int, out *string, s Scope) error {
*out = fmt.Sprintf("%v", *in)
Expand Down Expand Up @@ -432,7 +438,7 @@ func TestConverter_tags(t *testing.T) {
A string `test:"bar"`
}
c := NewConverter()
c.Debug = t
c.Debug = testLogger(t)
err := c.RegisterConversionFunc(
func(in *string, out *string, s Scope) error {
if e, a := "foo", s.SrcTag().Get("test"); e != a {
Expand All @@ -457,7 +463,7 @@ func TestConverter_meta(t *testing.T) {
type Foo struct{ A string }
type Bar struct{ A string }
c := NewConverter()
c.Debug = t
c.Debug = testLogger(t)
checks := 0
err := c.RegisterConversionFunc(
func(in *Foo, out *Bar, s Scope) error {
Expand Down Expand Up @@ -566,7 +572,7 @@ func TestConverter_flags(t *testing.T) {
}
f := fuzz.New().NilChance(.5).NumElements(0, 100)
c := NewConverter()
c.Debug = t
c.Debug = testLogger(t)

for i, item := range table {
for j := 0; j < *fuzzIters; j++ {
Expand Down Expand Up @@ -620,7 +626,7 @@ func TestConverter_FieldRename(t *testing.T) {
if err != nil {
t.Fatalf("unexpected error %v", err)
}
c.Debug = t
c.Debug = testLogger(t)

aVal := &A{
WeirdMeta: WeirdMeta{
Expand Down

0 comments on commit 55747ec

Please sign in to comment.