From 7143b27391d4c85086bfd502979d047b1c80aa69 Mon Sep 17 00:00:00 2001 From: Volker Schukai <volker.schukai@schukai.com> Date: Sun, 18 Sep 2022 15:42:28 +0200 Subject: [PATCH] change api HasError() to HasErrors() as it is more logical --- api.go | 2 +- change_test.go | 2 +- error.go | 2 +- error_test.go | 6 +++--- export_test.go | 2 +- file_test.go | 26 +++++++++++++------------- http-handler.go | 2 +- integration_test.go | 2 +- stream_test.go | 2 +- watch_test.go | 4 ++-- 10 files changed, 25 insertions(+), 25 deletions(-) diff --git a/api.go b/api.go index e57f55e..f77f1c7 100644 --- a/api.go +++ b/api.go @@ -38,7 +38,7 @@ func (s *setting[C]) SetMnemonic(mnemonic string) *setting[C] { } // Check if the setting contains errors -func (s *setting[C]) HasError() bool { +func (s *setting[C]) HasErrors() bool { return len(s.errors) > 0 } diff --git a/change_test.go b/change_test.go index 8494069..7e1b661 100644 --- a/change_test.go +++ b/change_test.go @@ -69,7 +69,7 @@ func TestCangeOnChange(t *testing.T) { s.Import() - if s.HasError() { + if s.HasErrors() { t.Error("Expected not error", s.Errors()) } diff --git a/error.go b/error.go index 8d9f5ee..a6c93fe 100644 --- a/error.go +++ b/error.go @@ -50,7 +50,7 @@ func newUnsupportedTypeError(t reflect.Type) UnsupportedTypeError { } // ResetError is used to reset the error to nil -// After calling this function, the call HasError() will return false +// After calling this function, the call HasErrors() will return false func (s *setting[C]) ResetErrors() *setting[C] { s.errors = []error{} return s diff --git a/error_test.go b/error_test.go index 877004f..0e58e86 100644 --- a/error_test.go +++ b/error_test.go @@ -14,11 +14,11 @@ func TestResetErrors(t *testing.T) { c := New(defaults) - assert.False(t, c.HasError()) + assert.False(t, c.HasErrors()) c.SetDefaultDirectories() - assert.True(t, c.HasError()) + assert.True(t, c.HasErrors()) c.ResetErrors() - assert.False(t, c.HasError()) + assert.False(t, c.HasErrors()) } func TestNewFlagDoesNotExistError(t *testing.T) { diff --git a/export_test.go b/export_test.go index 6709cb3..8d87c13 100644 --- a/export_test.go +++ b/export_test.go @@ -21,7 +21,7 @@ func TestWrite(t *testing.T) { s.Write(x, f) - if s.HasError() { + if s.HasErrors() { t.Error(s.Errors()) s.ResetErrors() continue diff --git a/file_test.go b/file_test.go index 29241d1..677d43e 100644 --- a/file_test.go +++ b/file_test.go @@ -167,7 +167,7 @@ func TestAddDirectoryMissingMnemonic(t *testing.T) { c := New(cfg) c.AddEtcDirectory() - if !c.HasError() { + if !c.HasErrors() { t.Error("Expected error") } @@ -260,7 +260,7 @@ func TestSetFileFormat(t *testing.T) { c := New(cfg) c.SetFileFormat(Yaml) - if c.HasError() { + if c.HasErrors() { t.Error("Expected not error") } @@ -273,7 +273,7 @@ func TestSetFileFormatError(t *testing.T) { c := New(cfg) c.SetFileFormat(Format(9999)) - if !c.HasError() { + if !c.HasErrors() { t.Error("Expected error") } @@ -302,7 +302,7 @@ func TestImport(t *testing.T) { c.SetDefaultDirectories().ResetErrors() c.Import() - if c.HasError() { + if c.HasErrors() { t.Error("Expected not error", c.Errors()) } @@ -413,7 +413,7 @@ func TestImport2(t *testing.T) { c.SetDefaultDirectories().ResetErrors() // errors not important here c.Import() - if c.HasError() { + if c.HasErrors() { t.Error("Expected not error", c.Errors()) } @@ -461,7 +461,7 @@ func TestImport3(t *testing.T) { c.SetDefaultDirectories().ResetErrors() // errors not important here c.Import() - if c.HasError() { + if c.HasErrors() { t.Error("Expected not error", c.Errors()) } @@ -514,7 +514,7 @@ func TestSetConfigName(t *testing.T) { c := New(cfg) c.SetFileName("test") - if c.HasError() { + if c.HasErrors() { t.Error("Expected not error") } @@ -527,13 +527,13 @@ func TestConfigSetFileName(t *testing.T) { c := New(cfg) c.SetFileName("test") - if c.HasError() { + if c.HasErrors() { t.Error("Expected not error") } c.SetFileName("") - if !c.HasError() { + if !c.HasErrors() { t.Error("Expected error") } @@ -546,7 +546,7 @@ func TestConfigSetFileFormat(t *testing.T) { c := New(cfg) c.SetFileFormat(99) - if !c.HasError() { + if !c.HasErrors() { t.Error("Expected not error") } @@ -559,7 +559,7 @@ func TestConfigSetDirectories(t *testing.T) { c := New(cfg) c.SetDirectories([]string{"a", "b"}) - if !c.HasError() { + if !c.HasErrors() { t.Error("Expected not error") } @@ -572,7 +572,7 @@ func TestConfigDirectories(t *testing.T) { c := New(cfg) c.SetDirectories([]string{"a", "b"}) - if !c.HasError() { + if !c.HasErrors() { t.Error("Expected not error") } @@ -591,7 +591,7 @@ func TestConfigAddDirectory(t *testing.T) { c := New(cfg) c.AddDirectory("a") - if !c.HasError() { + if !c.HasErrors() { t.Error("Expected not error") } diff --git a/http-handler.go b/http-handler.go index a025595..59b3e94 100644 --- a/http-handler.go +++ b/http-handler.go @@ -47,7 +47,7 @@ func (s *setting[C]) serveGet(w http.ResponseWriter, r *http.Request) { } - if s.HasError() { + if s.HasErrors() { w.WriteHeader(http.StatusInternalServerError) return } diff --git a/integration_test.go b/integration_test.go index e1b10bd..60ff24a 100644 --- a/integration_test.go +++ b/integration_test.go @@ -37,7 +37,7 @@ func FuzzTest(f *testing.F) { } s.Write(os.Stdout, Yaml) - if s.HasError() { + if s.HasErrors() { t.Error(s.Errors()) s.ResetErrors() } diff --git a/stream_test.go b/stream_test.go index 715e710..9914033 100644 --- a/stream_test.go +++ b/stream_test.go @@ -83,7 +83,7 @@ func TestAddReader(t *testing.T) { // // s.Import() // -// if s.HasError() { +// if s.HasErrors() { // t.Error("Expected no errors but got ", s.Errors()) // } // diff --git a/watch_test.go b/watch_test.go index 11b0919..ea0b06f 100644 --- a/watch_test.go +++ b/watch_test.go @@ -82,7 +82,7 @@ func TestSettingStopWatching(t *testing.T) { c.Watch() c.StopWatching() - if c.HasError() { + if c.HasErrors() { t.Error(c.Errors()) } @@ -99,7 +99,7 @@ func TestSettingStopWatchingNotOnWatch(t *testing.T) { c := New(config) c.StopWatching() - if !c.HasError() { + if !c.HasErrors() { t.Error("Expected to have an error") } -- GitLab