From dcb0deb9a50f212ada1c8d8c729da440a3556df4 Mon Sep 17 00:00:00 2001 From: nathan-nicholson Date: Mon, 30 Dec 2024 09:37:46 -0600 Subject: [PATCH] chore: delete unused printer struct Signed-off-by: nathan-nicholson --- internal/common/printer.go | 31 ------------- internal/common/printer_test.go | 78 --------------------------------- 2 files changed, 109 deletions(-) delete mode 100644 internal/common/printer.go delete mode 100644 internal/common/printer_test.go diff --git a/internal/common/printer.go b/internal/common/printer.go deleted file mode 100644 index c497050e..00000000 --- a/internal/common/printer.go +++ /dev/null @@ -1,31 +0,0 @@ -package common - -import ( - "fmt" - "io" -) - -type Printer struct { - writers []io.Writer -} - -func NewPrinter(writers ...io.Writer) *Printer { - return &Printer{ - writers: writers, - } -} - -func (p *Printer) AddWriter(w io.Writer) { - p.writers = append(p.writers, w) -} - -func (p *Printer) Print(s string) error { - for _, w := range p.writers { - _, err := fmt.Fprint(w, s) - if err != nil { - return fmt.Errorf("failed to write to writer: %w", err) - } - } - - return nil -} diff --git a/internal/common/printer_test.go b/internal/common/printer_test.go deleted file mode 100644 index ec7391db..00000000 --- a/internal/common/printer_test.go +++ /dev/null @@ -1,78 +0,0 @@ -package common - -import ( - "bytes" - "io" - "testing" -) - -type FailingWriter struct{} - -func (f *FailingWriter) Write(p []byte) (n int, err error) { - return 0, io.ErrUnexpectedEOF -} - -func (f *FailingWriter) String() string { - return "" -} - -func TestAwsCommand_Print(t *testing.T) { - tests := []struct { - name string - input string - writers []io.Writer - wantErr bool - }{ - { - name: "write single string to single writer", - input: "test message", - writers: []io.Writer{&bytes.Buffer{}}, - wantErr: false, - }, - { - name: "write single string to multiple writers", - input: "test message", - writers: []io.Writer{&bytes.Buffer{}, &bytes.Buffer{}}, - wantErr: false, - }, - { - name: "write empty string", - input: "", - writers: []io.Writer{&bytes.Buffer{}}, - wantErr: false, - }, - { - name: "fail to write to writer", - input: "test message", - writers: []io.Writer{&FailingWriter{}}, - wantErr: true, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - printer := NewPrinter(tt.writers...) - - err := printer.Print(tt.input) - - if tt.wantErr { - if err == nil { - t.Errorf("WriteString() error = %v, wantErr %v", err, tt.wantErr) - return - } - return - } - - for i, w := range tt.writers { - - stringer := w.(interface { - String() string - }) - - if got := stringer.String(); got != tt.input { - t.Errorf("Writer %d got = %v, want %v", i, got, tt.input) - } - } - }) - } -}