From b06eba3df09a8fcd777b8fe350c2b184758963d1 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 28 Jan 2024 16:10:14 -0500 Subject: Use checkmate for tests --- internal/output/console_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'internal/output') diff --git a/internal/output/console_test.go b/internal/output/console_test.go index be369ab..e006cd6 100644 --- a/internal/output/console_test.go +++ b/internal/output/console_test.go @@ -5,7 +5,7 @@ import ( "io" "testing" - "gotest.tools/v3/assert" + "github.com/eugenetriguba/checkmate" ) func NewConsoleOutputterWithWriters(stdout io.Writer, stderr io.Writer) ConsoleOutputter { @@ -19,8 +19,8 @@ func TestConsoleOutputter_Output(t *testing.T) { consoleOutputter.Output("test string") - assert.Equal(t, stdout.String(), "test string\n") - assert.Equal(t, stderr.String(), "") + checkmate.AssertEqual(t, stdout.String(), "test string\n") + checkmate.AssertEqual(t, stderr.String(), "") } func TestConsoleOutputter_Error(t *testing.T) { @@ -30,8 +30,8 @@ func TestConsoleOutputter_Error(t *testing.T) { consoleOutputter.Error("test string") - assert.Equal(t, stdout.String(), "") - assert.Equal(t, stderr.String(), "test string\n") + checkmate.AssertEqual(t, stdout.String(), "") + checkmate.AssertEqual(t, stderr.String(), "test string\n") } func TestConsoleOutputter_Table(t *testing.T) { @@ -70,7 +70,7 @@ func TestConsoleOutputter_Table(t *testing.T) { consoleOutputter.Table(tc.headers, tc.rows) - assert.Equal(t, stdout.String(), tc.expectedStdout) - assert.Equal(t, stderr.String(), "") + checkmate.AssertEqual(t, stdout.String(), tc.expectedStdout) + checkmate.AssertEqual(t, stderr.String(), "") } } -- cgit v1.2.3 From 345e28bd44ba6a38bf7ee9bfe2066f333bbbe894 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 28 Jan 2024 16:29:00 -0500 Subject: Update to checkmate v0.2.0 --- internal/output/console_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'internal/output') diff --git a/internal/output/console_test.go b/internal/output/console_test.go index e006cd6..ff1f8b8 100644 --- a/internal/output/console_test.go +++ b/internal/output/console_test.go @@ -5,7 +5,7 @@ import ( "io" "testing" - "github.com/eugenetriguba/checkmate" + "github.com/eugenetriguba/checkmate/assert" ) func NewConsoleOutputterWithWriters(stdout io.Writer, stderr io.Writer) ConsoleOutputter { @@ -19,8 +19,8 @@ func TestConsoleOutputter_Output(t *testing.T) { consoleOutputter.Output("test string") - checkmate.AssertEqual(t, stdout.String(), "test string\n") - checkmate.AssertEqual(t, stderr.String(), "") + assert.Equal(t, stdout.String(), "test string\n") + assert.Equal(t, stderr.String(), "") } func TestConsoleOutputter_Error(t *testing.T) { @@ -30,8 +30,8 @@ func TestConsoleOutputter_Error(t *testing.T) { consoleOutputter.Error("test string") - checkmate.AssertEqual(t, stdout.String(), "") - checkmate.AssertEqual(t, stderr.String(), "test string\n") + assert.Equal(t, stdout.String(), "") + assert.Equal(t, stderr.String(), "test string\n") } func TestConsoleOutputter_Table(t *testing.T) { @@ -70,7 +70,7 @@ func TestConsoleOutputter_Table(t *testing.T) { consoleOutputter.Table(tc.headers, tc.rows) - checkmate.AssertEqual(t, stdout.String(), tc.expectedStdout) - checkmate.AssertEqual(t, stderr.String(), "") + assert.Equal(t, stdout.String(), tc.expectedStdout) + assert.Equal(t, stderr.String(), "") } } -- cgit v1.2.3 From 95eea2a07198576e3f4b0a246dd5e2b0cd4ef219 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 28 Jan 2024 17:47:31 -0500 Subject: Wrap db repo and console errs to give better errors --- internal/output/console.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'internal/output') diff --git a/internal/output/console.go b/internal/output/console.go index d2946ed..50534dd 100644 --- a/internal/output/console.go +++ b/internal/output/console.go @@ -18,12 +18,12 @@ func NewConsoleOutputter() ConsoleOutputter { func (c ConsoleOutputter) Output(message string) error { _, err := fmt.Fprintln(c.stdout, message) - return err + return fmt.Errorf("unable to print message %s: %w", message, err) } func (c ConsoleOutputter) Error(message string) error { _, err := fmt.Fprintln(c.stderr, message) - return err + return fmt.Errorf("unable to print message %s: %w", message, err) } func (c ConsoleOutputter) Table(headers []string, rows [][]string) error { @@ -32,13 +32,13 @@ func (c ConsoleOutputter) Table(headers []string, rows [][]string) error { for _, header := range headers { _, err := fmt.Fprintf(w, "%s\t", header) if err != nil { - return err + return fmt.Errorf("unable to print table header %s: %w", header, err) } } if len(headers) > 0 { _, err := fmt.Fprint(w, "\n") if err != nil { - return err + return fmt.Errorf("unable to print newline after table header: %w", err) } } @@ -46,12 +46,12 @@ func (c ConsoleOutputter) Table(headers []string, rows [][]string) error { for _, cell := range row { _, err := fmt.Fprintf(w, "%s\t", cell) if err != nil { - return err + return fmt.Errorf("unable to print table cell %s: %w", cell, err) } } _, err := fmt.Fprint(w, "\n") if err != nil { - return err + return fmt.Errorf("unable to print newline for table row %s: %w", row, err) } } -- cgit v1.2.3 From 32d10125d82aa7933fffac474105bf5897f3853a Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Wed, 7 Feb 2024 20:05:53 -0500 Subject: Use checkmate 0.3.0 --- internal/output/console_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'internal/output') diff --git a/internal/output/console_test.go b/internal/output/console_test.go index ff1f8b8..78e5d38 100644 --- a/internal/output/console_test.go +++ b/internal/output/console_test.go @@ -5,7 +5,7 @@ import ( "io" "testing" - "github.com/eugenetriguba/checkmate/assert" + "github.com/eugenetriguba/checkmate/check" ) func NewConsoleOutputterWithWriters(stdout io.Writer, stderr io.Writer) ConsoleOutputter { @@ -19,8 +19,8 @@ func TestConsoleOutputter_Output(t *testing.T) { consoleOutputter.Output("test string") - assert.Equal(t, stdout.String(), "test string\n") - assert.Equal(t, stderr.String(), "") + check.Equal(t, stdout.String(), "test string\n") + check.Equal(t, stderr.String(), "") } func TestConsoleOutputter_Error(t *testing.T) { @@ -30,8 +30,8 @@ func TestConsoleOutputter_Error(t *testing.T) { consoleOutputter.Error("test string") - assert.Equal(t, stdout.String(), "") - assert.Equal(t, stderr.String(), "test string\n") + check.Equal(t, stdout.String(), "") + check.Equal(t, stderr.String(), "test string\n") } func TestConsoleOutputter_Table(t *testing.T) { @@ -70,7 +70,7 @@ func TestConsoleOutputter_Table(t *testing.T) { consoleOutputter.Table(tc.headers, tc.rows) - assert.Equal(t, stdout.String(), tc.expectedStdout) - assert.Equal(t, stderr.String(), "") + check.Equal(t, stdout.String(), tc.expectedStdout) + check.Equal(t, stderr.String(), "") } } -- cgit v1.2.3 From b3595cd1f9793eaf8c1f80d1cfadbbebe328f0c4 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Wed, 7 Feb 2024 21:44:22 -0500 Subject: Fix return value for console outputter output and error funcs --- internal/output/console.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'internal/output') diff --git a/internal/output/console.go b/internal/output/console.go index 50534dd..7f04b28 100644 --- a/internal/output/console.go +++ b/internal/output/console.go @@ -18,12 +18,18 @@ func NewConsoleOutputter() ConsoleOutputter { func (c ConsoleOutputter) Output(message string) error { _, err := fmt.Fprintln(c.stdout, message) - return fmt.Errorf("unable to print message %s: %w", message, err) + if err != nil { + return fmt.Errorf("unable to print message %s: %w", message, err) + } + return nil } func (c ConsoleOutputter) Error(message string) error { _, err := fmt.Fprintln(c.stderr, message) - return fmt.Errorf("unable to print message %s: %w", message, err) + if err != nil { + return fmt.Errorf("unable to print message %s: %w", message, err) + } + return nil } func (c ConsoleOutputter) Table(headers []string, rows [][]string) error { -- cgit v1.2.3 From df5dce753523e0e1eca7de91d272ff16c9c0d79c Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 25 Feb 2024 15:48:14 -0500 Subject: Change Error in console outputter to accept error --- internal/output/console.go | 7 +++++++ internal/output/console_test.go | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'internal/output') diff --git a/internal/output/console.go b/internal/output/console.go index 7f04b28..42b0e3f 100644 --- a/internal/output/console.go +++ b/internal/output/console.go @@ -24,12 +24,19 @@ func (c ConsoleOutputter) Output(message string) error { return nil } +<<<<<<< Updated upstream func (c ConsoleOutputter) Error(message string) error { _, err := fmt.Fprintln(c.stderr, message) if err != nil { return fmt.Errorf("unable to print message %s: %w", message, err) } return nil +======= +func (c ConsoleOutputter) Error(err error) error { + msg := err.Error() + _, printErr := fmt.Fprintln(c.stderr, msg) + return fmt.Errorf("unable to print message %s: %w", msg, printErr) +>>>>>>> Stashed changes } func (c ConsoleOutputter) Table(headers []string, rows [][]string) error { diff --git a/internal/output/console_test.go b/internal/output/console_test.go index 78e5d38..492d0a2 100644 --- a/internal/output/console_test.go +++ b/internal/output/console_test.go @@ -2,6 +2,7 @@ package output import ( "bytes" + "errors" "io" "testing" @@ -28,7 +29,7 @@ func TestConsoleOutputter_Error(t *testing.T) { var stderr bytes.Buffer consoleOutputter := NewConsoleOutputterWithWriters(&stdout, &stderr) - consoleOutputter.Error("test string") + consoleOutputter.Error(errors.New("test string")) check.Equal(t, stdout.String(), "") check.Equal(t, stderr.String(), "test string\n") -- cgit v1.2.3 From 29b5f58de7a5f027ea70932bf3c6d4a02de3ffdd Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 25 Feb 2024 15:49:31 -0500 Subject: fix merge conflict --- internal/output/console.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'internal/output') diff --git a/internal/output/console.go b/internal/output/console.go index 42b0e3f..1a4efad 100644 --- a/internal/output/console.go +++ b/internal/output/console.go @@ -24,19 +24,13 @@ func (c ConsoleOutputter) Output(message string) error { return nil } -<<<<<<< Updated upstream -func (c ConsoleOutputter) Error(message string) error { - _, err := fmt.Fprintln(c.stderr, message) - if err != nil { - return fmt.Errorf("unable to print message %s: %w", message, err) - } - return nil -======= func (c ConsoleOutputter) Error(err error) error { msg := err.Error() _, printErr := fmt.Fprintln(c.stderr, msg) - return fmt.Errorf("unable to print message %s: %w", msg, printErr) ->>>>>>> Stashed changes + if printErr != nil { + return fmt.Errorf("unable to print message %s: %w", msg, printErr) + } + return nil } func (c ConsoleOutputter) Table(headers []string, rows [][]string) error { -- cgit v1.2.3 From 38a2e5f69f46368075072be36fac7bc46b2c064d Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 25 Feb 2024 15:54:55 -0500 Subject: Fix interface --- internal/output/output.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'internal/output') diff --git a/internal/output/output.go b/internal/output/output.go index c51553b..9a9fb77 100644 --- a/internal/output/output.go +++ b/internal/output/output.go @@ -2,6 +2,6 @@ package output type Outputter interface { Output(message string) error - Error(message string) error + Error(err error) error Table(header []string, rows [][]string) error } -- cgit v1.2.3