From 72fdc255e797ac5bcfd723720020ab805ebf144a Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Thu, 11 May 2023 17:14:19 -0700 Subject: [PATCH] db: clean out dependency on stretchr --- dbg/BUILD.bazel | 2 +- dbg/dbg_test.go | 52 ++++++++++++++++++++++++------------------------- go.mod | 3 --- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/dbg/BUILD.bazel b/dbg/BUILD.bazel index 113b53e..1196885 100644 --- a/dbg/BUILD.bazel +++ b/dbg/BUILD.bazel @@ -13,7 +13,7 @@ go_test( srcs = ["dbg_test.go"], embed = [":dbg"], deps = [ + "//assert", "//testio", - "@com_github_stretchr_testify//require", ], ) diff --git a/dbg/dbg_test.go b/dbg/dbg_test.go index d8930db..738359b 100644 --- a/dbg/dbg_test.go +++ b/dbg/dbg_test.go @@ -1,12 +1,13 @@ package dbg import ( + "fmt" "io/ioutil" "os" "testing" + "git.wntrmute.dev/kyle/goutils/assert" "git.wntrmute.dev/kyle/goutils/testio" - "github.com/stretchr/testify/require" ) func TestNew(t *testing.T) { @@ -17,16 +18,16 @@ func TestNew(t *testing.T) { dbg.Print("hello") dbg.Println("hello") dbg.Printf("hello %s", "world") - require.Equal(t, 0, buf.Len()) + assert.BoolT(t, buf.Len() == 0) dbg.Enabled = true dbg.Print("hello") // +5 dbg.Println("hello") // +6 dbg.Printf("hello %s", "world") // +11 - require.Equal(t, 22, buf.Len()) + assert.BoolT(t, buf.Len() == 22, fmt.Sprintf("buffer should be length 22 but is length %d", buf.Len())) err := dbg.Close() - require.NoError(t, err) + assert.NoErrorT(t, err) } func TestTo(t *testing.T) { @@ -36,39 +37,38 @@ func TestTo(t *testing.T) { dbg.Print("hello") dbg.Println("hello") dbg.Printf("hello %s", "world") - require.Equal(t, 0, buf.Len()) + assert.BoolT(t, buf.Len() == 0, "debug output should be suppressed") dbg.Enabled = true dbg.Print("hello") // +5 dbg.Println("hello") // +6 dbg.Printf("hello %s", "world") // +11 - - require.Equal(t, 22, buf.Len()) + assert.BoolT(t, buf.Len() == 22, "didn't get the expected debug output") err := dbg.Close() - require.NoError(t, err) + assert.NoErrorT(t, err) } func TestToFile(t *testing.T) { testFile, err := ioutil.TempFile("", "dbg") - require.NoError(t, err) + assert.NoErrorT(t, err) err = testFile.Close() - require.NoError(t, err) + assert.NoErrorT(t, err) testFileName := testFile.Name() defer os.Remove(testFileName) dbg, err := ToFile(testFileName) - require.NoError(t, err) + assert.NoErrorT(t, err) dbg.Print("hello") dbg.Println("hello") dbg.Printf("hello %s", "world") stat, err := os.Stat(testFileName) - require.NoError(t, err) + assert.NoErrorT(t, err) - require.EqualValues(t, 0, stat.Size()) + assert.BoolT(t, stat.Size() == 0, "no debug output should have been sent to the log file") dbg.Enabled = true dbg.Print("hello") // +5 @@ -76,12 +76,12 @@ func TestToFile(t *testing.T) { dbg.Printf("hello %s", "world") // +11 stat, err = os.Stat(testFileName) - require.NoError(t, err) + assert.NoErrorT(t, err) - require.EqualValues(t, 22, stat.Size()) + assert.BoolT(t, stat.Size() == 22, fmt.Sprintf("have %d bytes in the log file, expected 22", stat.Size())) err = dbg.Close() - require.NoError(t, err) + assert.NoErrorT(t, err) } func TestWriting(t *testing.T) { @@ -90,31 +90,31 @@ func TestWriting(t *testing.T) { dbg := To(buf) n, err := dbg.Write(data) - require.NoError(t, err) - require.EqualValues(t, 0, n) + assert.NoErrorT(t, err) + assert.BoolT(t, n == 0, "expected nothing to be written to the buffer") dbg.Enabled = true n, err = dbg.Write(data) - require.NoError(t, err) - require.EqualValues(t, 12, n) + assert.NoErrorT(t, err) + assert.BoolT(t, n == 12, fmt.Sprintf("wrote %d bytes in the buffer, expected to write 12", n)) err = dbg.Close() - require.NoError(t, err) + assert.NoErrorT(t, err) } func TestToFileError(t *testing.T) { testFile, err := ioutil.TempFile("", "dbg") - require.NoError(t, err) + assert.NoErrorT(t, err) err = testFile.Chmod(0400) - require.NoError(t, err) + assert.NoErrorT(t, err) err = testFile.Close() - require.NoError(t, err) + assert.NoErrorT(t, err) testFileName := testFile.Name() _, err = ToFile(testFileName) - require.Error(t, err) + assert.ErrorT(t, err) err = os.Remove(testFileName) - require.NoError(t, err) + assert.NoErrorT(t, err) } diff --git a/go.mod b/go.mod index 0360681..6430fb4 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,6 @@ require ( github.com/kr/text v0.2.0 github.com/pkg/errors v0.9.1 github.com/pkg/sftp v1.12.0 - github.com/stretchr/testify v1.6.1 golang.org/x/crypto v0.0.0-20220314234659-1baeb1ce4c0b golang.org/x/sys v0.0.0-20220412211240-33da011f77ad gopkg.in/yaml.v2 v2.4.0 @@ -21,7 +20,5 @@ require ( require ( github.com/kr/fs v0.1.0 // indirect github.com/kr/pretty v0.1.0 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect - gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect )