diff --git a/internal/tartest/tartest.go b/internal/tartest/tartest.go index 5620aca..3359395 100644 --- a/internal/tartest/tartest.go +++ b/internal/tartest/tartest.go @@ -7,8 +7,6 @@ import ( "fmt" "io" "testing" - - "github.com/stretchr/testify/require" ) type ( @@ -122,7 +120,9 @@ func Extract(t *testing.T, r io.Reader) []Extractable { if err == io.EOF { break } - require.NoError(t, err) + if err != nil { + t.Errorf("expected nil error: %v", err) + } var elem Extractable switch hdr.Typeflag { diff --git a/internal/tartest/tartest_test.go b/internal/tartest/tartest_test.go index 2f58e4c..ab73197 100644 --- a/internal/tartest/tartest_test.go +++ b/internal/tartest/tartest_test.go @@ -4,10 +4,8 @@ import ( "bytes" "compress/gzip" "io" + "reflect" "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestTarball(t *testing.T) { @@ -26,7 +24,10 @@ func TestTarball(t *testing.T) { Dir{Name: "bin"}, Hardlink{Name: "entrypoint2"}, } - assert.Equal(t, want, got) + if !reflect.DeepEqual(want, got) { + t.Errorf("tarball mismatch. want: %+v, got: %+v", want, got) + } + } func TestGzip(t *testing.T) { @@ -34,10 +35,14 @@ func TestGzip(t *testing.T) { tbuf := tb.Buffer() tgz, err := gzip.NewReader(tb.Gzip()) - require.NoError(t, err) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } var uncompressed bytes.Buffer - _, err = io.Copy(&uncompressed, tgz) - require.NoError(t, err) - assert.Equal(t, tbuf.Bytes(), uncompressed.Bytes()) - + if _, err := io.Copy(&uncompressed, tgz); err != nil { + t.Fatalf("unexpected error: %v", err) + } + if !bytes.Equal(tbuf.Bytes(), uncompressed.Bytes()) { + t.Errorf("tbuf and uncompressed bytes mismatch") + } } diff --git a/main_test.go b/main_test.go index 92c4399..7b7aac0 100644 --- a/main_test.go +++ b/main_test.go @@ -5,10 +5,8 @@ import ( "io" "io/ioutil" "path/filepath" + "regexp" "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestExecute(t *testing.T) { @@ -26,7 +24,9 @@ func TestExecute(t *testing.T) { infile: "t10-in.txt", fixture: func(t *testing.T, dir string) { fname := filepath.Join(dir, "t10-in.txt") - require.NoError(t, ioutil.WriteFile(fname, _foo, 0644)) + if err := ioutil.WriteFile(fname, _foo, 0644); err != nil { + t.Fatalf("unexpected error: %v", err) + } }, outfile: "-", }, @@ -35,7 +35,9 @@ func TestExecute(t *testing.T) { infile: "t20-in.txt", fixture: func(t *testing.T, dir string) { fname := filepath.Join(dir, "t20-in.txt") - require.NoError(t, ioutil.WriteFile(fname, _foo, 0644)) + if err := ioutil.WriteFile(fname, _foo, 0644); err != nil { + t.Fatalf("unexpected error: %v", err) + } }, outfile: "t20-out.txt", }, @@ -67,19 +69,30 @@ func TestExecute(t *testing.T) { err := c.execute(inf, tt.outfile) if tt.wantErr != "" { - require.Error(t, err) - assert.Regexp(t, tt.wantErr, err.Error()) + if err == nil { + t.Fatal("expected error, got nil") + } + r := regexp.MustCompile(tt.wantErr) + if r.FindStringIndex(err.Error()) == nil { + t.Errorf("%s not found in %s", tt.wantErr, err.Error()) + } return } var out []byte - require.NoError(t, err) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } if tt.outfile == "-" { out = stdout.Bytes() } else { out, err = ioutil.ReadFile(tt.outfile) - require.NoError(t, err) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + } + if !bytes.Equal([]byte("foo foo"), out) { + t.Errorf("out != foo foo: %s", string(out)) } - assert.Equal(t, []byte("foo foo"), out) }) } } diff --git a/rootfs/rootfs_test.go b/rootfs/rootfs_test.go index 04a155b..101d717 100644 --- a/rootfs/rootfs_test.go +++ b/rootfs/rootfs_test.go @@ -4,11 +4,10 @@ import ( "archive/tar" "bytes" "encoding/json" + "reflect" "testing" "git.sr.ht/~motiejus/code/undocker/internal/tartest" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) type ( @@ -193,13 +192,22 @@ func TestRootFS(t *testing.T) { err := Flatten(in, &out) if tt.wantErr != "" { - assert.EqualError(t, err, tt.wantErr) + if err == nil { + t.Fatal("expected error, got nil") + } + if tt.wantErr != err.Error() { + t.Errorf("want != got: %s != %s", tt.wantErr, err.Error()) + } return } outb := out.Bytes() - require.NoError(t, err) + if err != nil { + t.Fatal("expected error, got nil") + } got := tartest.Extract(t, bytes.NewReader(outb)) - assert.Equal(t, tt.want, got) + if !reflect.DeepEqual(tt.want, got) { + t.Errorf("want != got: %v != %v", tt.want, got) + } }) } } diff --git a/rootfs/tree_test.go b/rootfs/tree_test.go index 5cab76d..45398dc 100644 --- a/rootfs/tree_test.go +++ b/rootfs/tree_test.go @@ -37,15 +37,17 @@ func TestTree(t *testing.T) { for _, path := range tt.matchTrue { t.Run(path, func(t *testing.T) { - assert.True(t, tree.HasPrefix(path), - "expected %s to be a prefix of %s", path, tree) + if !tree.HasPrefix(path) { + t.Errorf("expected %s to be a prefix of %s", path, tree) + } }) } for _, path := range tt.matchFalse { t.Run(path, func(t *testing.T) { - assert.False(t, tree.HasPrefix(path), - "expected %s to not be a prefix of %s", path, tree) + if tree.HasPrefix(path) { + t.Errorf("expected %s to not be a prefix of %s", path, tree) + } }) } }) @@ -56,8 +58,14 @@ func TestTreeMerge(t *testing.T) { tree1 := newTree("bin/ar", "var/cache/apt") tree2 := newTree("bin/ar", "bin/busybox", "usr/share/doc") tree1.Merge(tree2) - assert.Equal(t, "./bin/ar:./bin/busybox:./usr/share/doc:./var/cache/apt", tree1.String()) - assert.Equal(t, "./bin/ar:./bin/busybox:./usr/share/doc", tree2.String()) + want1 := "./bin/ar:./bin/busybox:./usr/share/doc:./var/cache/apt" + if got := tree1.String(); want1 != got { + t.Errorf("want != got: %q != %q", want1, got) + } + want2 := "./bin/ar:./bin/busybox:./usr/share/doc" + if got := tree2.String(); want2 != got { + t.Errorf("want != got: %q != %q", want2, got) + } } func TestString(t *testing.T) {