Skip to content

Commit

Permalink
Bumped up test coverage every so slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
baalimago committed Feb 15, 2024
1 parent 0c4618a commit ccac27a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/filetools/writing_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package filetools_test

import (
"errors"
"io"
"os"
"testing"
Expand All @@ -9,6 +10,12 @@ import (
"github.com/baalimago/repeater/pkg/filetools"
)

type errorWriter struct{}

func (ew errorWriter) Write(p []byte) (n int, err error) {
return 0, errors.New("here i go erroring again!")
}

func Test_WriteStirngIfPossible(t *testing.T) {
t.Run("it should write... if.. possible", func(t *testing.T) {
goodFile := testboil.CreateTestFile(t, "testFile")
Expand All @@ -35,4 +42,14 @@ func Test_WriteStirngIfPossible(t *testing.T) {
t.Fatalf("expected: %v, got: %s", want, got)
}
})

t.Run("it should error if not possible", func(t *testing.T) {
want := "writethis"
_, got := filetools.WriteStringIfPossible(want, []io.Writer{&errorWriter{}})
var wrErr filetools.WriteError
if !errors.As(got, &wrErr) {
t.Fatal("expected WriteError, got nil")
}
})

}

0 comments on commit ccac27a

Please sign in to comment.