From 0bee4110f79f668f43a41a1b48b43ed708771020 Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Wed, 8 Apr 2020 06:24:10 -0700 Subject: [PATCH 1/8] ucfg: no assert in TestValidationPass() --- validator_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/validator_test.go b/validator_test.go index 9d11c46..e4ec14f 100644 --- a/validator_test.go +++ b/validator_test.go @@ -24,6 +24,7 @@ import ( "testing" "time" + "github.com/davecgh/go-spew/spew" "github.com/stretchr/testify/assert" ) @@ -310,7 +311,9 @@ func TestValidationPass(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprintf("Test config (%v): %#v", i, test), func(t *testing.T) { err := c.Unpack(test) - assert.NoError(t, err) + if err != nil { + t.Fatalf("test:%v error:%v", spew.Sdump(test), err) + } }) } } From 1f50ffa740404367ada6ae996cc7307be9b857e1 Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Wed, 8 Apr 2020 06:38:37 -0700 Subject: [PATCH 2/8] ucfg: no assert in TestValidationFail() --- validator_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/validator_test.go b/validator_test.go index e4ec14f..9cdd6c7 100644 --- a/validator_test.go +++ b/validator_test.go @@ -538,7 +538,9 @@ func TestValidationFail(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprintf("Test config (%v): %#v", i, test), func(t *testing.T) { err := c.Unpack(test) - assert.True(t, err != nil) + if err == nil { + t.Fatalf("test:%v error:%v", spew.Sdump(test), err) + } }) } } From ec81b76ee2fb8c9a9dea67830428be78f16ba67d Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Wed, 8 Apr 2020 06:42:04 -0700 Subject: [PATCH 3/8] ucfg: no assert in TestValidateRequiredFailing() --- validator_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/validator_test.go b/validator_test.go index 9cdd6c7..6352400 100644 --- a/validator_test.go +++ b/validator_test.go @@ -637,7 +637,11 @@ func TestValidateRequiredFailing(t *testing.T) { t.Logf("Unpack returned error: %v", err) err = err.(Error).Reason() - assert.Equal(t, test.err, err) + logTmpl := "expected:%q got:%q" + if test.err != err { + t.Fatalf(logTmpl, test.err, err) + } + t.Logf(logTmpl, test.err, err) }) } } From 51f7b3c85b022b1e1fed8f32cc3c6aab2b1c4a0e Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Wed, 8 Apr 2020 06:43:46 -0700 Subject: [PATCH 4/8] ucfg: no assert in TestValidateNonzeroFailing() --- validator_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/validator_test.go b/validator_test.go index 6352400..324041c 100644 --- a/validator_test.go +++ b/validator_test.go @@ -760,7 +760,11 @@ func TestValidateNonzeroFailing(t *testing.T) { t.Logf("Unpack returned error: %v", err) err = err.(Error).Reason() - assert.Equal(t, test.err, err) + logTmpl := "expected:%q got:%q" + if test.err != err { + t.Fatalf(logTmpl, test.err, err) + } + t.Logf(logTmpl, test.err, err) }) } } From c489d4300fd7e48d3205b1b1ffaf88c18535d952 Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Wed, 8 Apr 2020 06:47:42 -0700 Subject: [PATCH 5/8] ucfg: no assert in TestValidationFailOnDefaults() --- validator_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/validator_test.go b/validator_test.go index 324041c..bbf445d 100644 --- a/validator_test.go +++ b/validator_test.go @@ -25,7 +25,6 @@ import ( "time" "github.com/davecgh/go-spew/spew" - "github.com/stretchr/testify/assert" ) type myNonzeroInt int @@ -986,7 +985,10 @@ func TestValidationFailOnDefaults(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprintf("Test config (%v): %#v", i, test), func(t *testing.T) { err := c.Unpack(test) - assert.True(t, err != nil) + if err == nil { + t.Fatalf("test:%v error:%v", spew.Sdump(test), err) + } + }) } } From ef86be18efd958318b378b1879dec3836a9427a4 Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Thu, 9 Apr 2020 21:45:59 -0700 Subject: [PATCH 6/8] ucfg: validateErrorTemplate for tests --- validator_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/validator_test.go b/validator_test.go index bbf445d..154f754 100644 --- a/validator_test.go +++ b/validator_test.go @@ -64,6 +64,8 @@ var errZeroTest = errors.New("value must not be 0") var errEmptyTest = errors.New("value must not be empty") var errMoreTest = errors.New("value must have more than 1 element") +var validateErrorTemplate = "config:%s test:%s error:%v" + func (m myNonzeroInt) Validate() error { return testZeroErr(int(m)) } @@ -311,7 +313,7 @@ func TestValidationPass(t *testing.T) { t.Run(fmt.Sprintf("Test config (%v): %#v", i, test), func(t *testing.T) { err := c.Unpack(test) if err != nil { - t.Fatalf("test:%v error:%v", spew.Sdump(test), err) + t.Fatalf(validateErrorTemplate, spew.Sdump(c), spew.Sdump(test), err) } }) } @@ -538,7 +540,7 @@ func TestValidationFail(t *testing.T) { t.Run(fmt.Sprintf("Test config (%v): %#v", i, test), func(t *testing.T) { err := c.Unpack(test) if err == nil { - t.Fatalf("test:%v error:%v", spew.Sdump(test), err) + t.Fatalf(validateErrorTemplate, spew.Sdump(c), spew.Sdump(test), err) } }) } @@ -986,7 +988,7 @@ func TestValidationFailOnDefaults(t *testing.T) { t.Run(fmt.Sprintf("Test config (%v): %#v", i, test), func(t *testing.T) { err := c.Unpack(test) if err == nil { - t.Fatalf("test:%v error:%v", spew.Sdump(test), err) + t.Fatalf(validateErrorTemplate, spew.Sdump(c), spew.Sdump(test), err) } }) From 58a54519a4624cc31e79d143d374d21b33c10f9f Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Sun, 12 Apr 2020 21:55:43 -0700 Subject: [PATCH 7/8] ucfg: mustUnpack() and mustFailUnpack() in validator tests --- validator_test.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/validator_test.go b/validator_test.go index 154f754..1da9116 100644 --- a/validator_test.go +++ b/validator_test.go @@ -64,7 +64,17 @@ var errZeroTest = errors.New("value must not be 0") var errEmptyTest = errors.New("value must not be empty") var errMoreTest = errors.New("value must have more than 1 element") -var validateErrorTemplate = "config:%s test:%s error:%v" +func mustFailUnpack(t *testing.T, cfg *Config, test interface{}) { + if err := cfg.Unpack(test); err == nil { + t.Fatalf("config:%s test:%s error:%v", spew.Sdump(cfg), spew.Sdump(test), err) + } +} + +func mustUnpack(t *testing.T, cfg *Config, test interface{}) { + if err := cfg.Unpack(test); err != nil { + t.Fatalf("config:%s test:%s error:%v", spew.Sdump(cfg), spew.Sdump(test), err) + } +} func (m myNonzeroInt) Validate() error { return testZeroErr(int(m)) @@ -311,10 +321,7 @@ func TestValidationPass(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprintf("Test config (%v): %#v", i, test), func(t *testing.T) { - err := c.Unpack(test) - if err != nil { - t.Fatalf(validateErrorTemplate, spew.Sdump(c), spew.Sdump(test), err) - } + mustUnpack(t, c, test) }) } } @@ -538,10 +545,7 @@ func TestValidationFail(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprintf("Test config (%v): %#v", i, test), func(t *testing.T) { - err := c.Unpack(test) - if err == nil { - t.Fatalf(validateErrorTemplate, spew.Sdump(c), spew.Sdump(test), err) - } + mustFailUnpack(t, c, test) }) } } @@ -986,11 +990,7 @@ func TestValidationFailOnDefaults(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprintf("Test config (%v): %#v", i, test), func(t *testing.T) { - err := c.Unpack(test) - if err == nil { - t.Fatalf(validateErrorTemplate, spew.Sdump(c), spew.Sdump(test), err) - } - + mustFailUnpack(t, c, test) }) } } From 330532664428dab7a8c7ca5d6f4b8b691643767d Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Sun, 12 Apr 2020 21:59:56 -0700 Subject: [PATCH 8/8] ucfg: quieter logs in TestValidateRequiredFailing() ucfg: quieter logs in TestValidateNonzeroFailing() --- validator_test.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/validator_test.go b/validator_test.go index 1da9116..af7d898 100644 --- a/validator_test.go +++ b/validator_test.go @@ -642,11 +642,9 @@ func TestValidateRequiredFailing(t *testing.T) { t.Logf("Unpack returned error: %v", err) err = err.(Error).Reason() - logTmpl := "expected:%q got:%q" if test.err != err { - t.Fatalf(logTmpl, test.err, err) + t.Fatalf("expected:%q got:%q", test.err, err) } - t.Logf(logTmpl, test.err, err) }) } } @@ -765,11 +763,9 @@ func TestValidateNonzeroFailing(t *testing.T) { t.Logf("Unpack returned error: %v", err) err = err.(Error).Reason() - logTmpl := "expected:%q got:%q" if test.err != err { - t.Fatalf(logTmpl, test.err, err) + t.Fatalf("expected:%q got:%q", test.err, err) } - t.Logf(logTmpl, test.err, err) }) } }