From 27ff71516e0da0ea76e74686c62112e925eae847 Mon Sep 17 00:00:00 2001 From: Neil O'Toole Date: Fri, 7 Aug 2020 23:10:41 -0600 Subject: [PATCH] Added go test to github action; fixed Windows test issues (#52) * initial test of testing workflow * added .gitattributes for crlf issue on windows * testh was attempting to remove the copied sqlite3 file before it was closed by sqlite3.database.Close() * fiddling with .gitattributes to get line endings to work --- .gitattributes | 2 ++ .github/workflows/go.yml | 5 +++-- cli/output/xmlw/xmlw_test.go | 2 +- testh/testh.go | 13 ++++++++----- 4 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..dd1999e5 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Set the default behavior, in case people don't have core.autocrlf set. +* text=auto eol=lf \ No newline at end of file diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 04e6f425..a668b952 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,5 +1,5 @@ name: Go -on: [push] +on: [push, pull_request] jobs: @@ -27,7 +27,8 @@ jobs: - name: Build run: go build -v . - + - name: Test + run: go test -v ./cli/output/... # # diff --git a/cli/output/xmlw/xmlw_test.go b/cli/output/xmlw/xmlw_test.go index c9e35ce0..8d1ddbe5 100644 --- a/cli/output/xmlw/xmlw_test.go +++ b/cli/output/xmlw/xmlw_test.go @@ -103,5 +103,5 @@ func TestRecordWriter_TblTypes(t *testing.T) { want, err := ioutil.ReadFile("testdata/tbl_types.xml") require.NoError(t, err) - require.Equal(t, want, buf.Bytes()) + require.Equal(t, string(want), buf.String()) } diff --git a/testh/testh.go b/testh/testh.go index 1b9e5d93..465074ba 100644 --- a/testh/testh.go +++ b/testh/testh.go @@ -155,19 +155,22 @@ func (h *Helper) Source(handle string) *source.Source { srcFile, err := os.Open(fpath) require.NoError(t, err) - defer func() { assert.NoError(t, srcFile.Close()) }() + defer func() {assert.NoError(t, srcFile.Close())}() destFile, err := ioutil.TempFile("", "*_"+filepath.Base(src.Location)) require.NoError(t, err) - defer func() { assert.NoError(t, destFile.Close()) }() - t.Cleanup(func() { - assert.NoError(t, os.Remove(destFile.Name())) + defer func() {assert.NoError(t, destFile.Close())}() + + destFileName := destFile.Name() + + h.Cleanup.AddE(func() error { + return os.Remove(destFileName) }) _, err = io.Copy(destFile, srcFile) require.NoError(t, err) - src.Location = sqlite3.Prefix + destFile.Name() + src.Location = sqlite3.Prefix + destFileName } h.srcCache[handle] = src return src