Skip to content

Commit c86e506

Browse files
committed
test: migrate tar_test.go from testify to gotest.tools/v3
1 parent 8b9ecfd commit c86e506

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

internal/sync/tar_test.go

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
"testing"
2424

2525
"github.com/moby/moby/api/types/container"
26-
"github.com/stretchr/testify/assert"
27-
"github.com/stretchr/testify/require"
26+
"gotest.tools/v3/assert"
27+
"gotest.tools/v3/assert/cmp"
2828
)
2929

3030
// fakeLowLevelClient records calls made to it for test assertions.
@@ -51,7 +51,7 @@ func (f *fakeLowLevelClient) Untar(_ context.Context, _ string, _ io.ReadCloser)
5151
func TestSync_ExistingPath(t *testing.T) {
5252
tmpDir := t.TempDir()
5353
existingFile := filepath.Join(tmpDir, "exists.txt")
54-
require.NoError(t, os.WriteFile(existingFile, []byte("data"), 0o644))
54+
assert.NilError(t, os.WriteFile(existingFile, []byte("data"), 0o644))
5555

5656
client := &fakeLowLevelClient{
5757
containers: []container.Summary{{ID: "ctr1"}},
@@ -62,9 +62,9 @@ func TestSync_ExistingPath(t *testing.T) {
6262
{HostPath: existingFile, ContainerPath: "/app/exists.txt"},
6363
})
6464

65-
require.NoError(t, err)
66-
assert.Equal(t, 1, client.untarCount, "existing path should be copied via Untar")
67-
assert.Empty(t, client.execCmds, "no delete command expected for existing path")
65+
assert.NilError(t, err)
66+
assert.Equal(t, client.untarCount, 1, "existing path should be copied via Untar")
67+
assert.Equal(t, len(client.execCmds), 0, "no delete command expected for existing path")
6868
}
6969

7070
func TestSync_NonExistentPath(t *testing.T) {
@@ -77,9 +77,9 @@ func TestSync_NonExistentPath(t *testing.T) {
7777
{HostPath: "/no/such/file", ContainerPath: "/app/gone.txt"},
7878
})
7979

80-
require.NoError(t, err)
81-
require.Len(t, client.execCmds, 1, "should issue a delete command")
82-
assert.Equal(t, []string{"rm", "-rf", "/app/gone.txt"}, client.execCmds[0])
80+
assert.NilError(t, err)
81+
assert.Equal(t, len(client.execCmds), 1, "should issue a delete command")
82+
assert.DeepEqual(t, client.execCmds[0], []string{"rm", "-rf", "/app/gone.txt"})
8383
}
8484

8585
func TestSync_StatPermissionError(t *testing.T) {
@@ -92,11 +92,11 @@ func TestSync_StatPermissionError(t *testing.T) {
9292

9393
tmpDir := t.TempDir()
9494
restrictedDir := filepath.Join(tmpDir, "noaccess")
95-
require.NoError(t, os.Mkdir(restrictedDir, 0o700))
95+
assert.NilError(t, os.Mkdir(restrictedDir, 0o700))
9696
targetFile := filepath.Join(restrictedDir, "secret.txt")
97-
require.NoError(t, os.WriteFile(targetFile, []byte("data"), 0o644))
97+
assert.NilError(t, os.WriteFile(targetFile, []byte("data"), 0o644))
9898
// Remove all permissions on the parent directory so stat on the child fails with EACCES.
99-
require.NoError(t, os.Chmod(restrictedDir, 0o000))
99+
assert.NilError(t, os.Chmod(restrictedDir, 0o000))
100100
t.Cleanup(func() {
101101
// Restore permissions so t.TempDir() cleanup can remove it.
102102
_ = os.Chmod(restrictedDir, 0o700)
@@ -111,17 +111,16 @@ func TestSync_StatPermissionError(t *testing.T) {
111111
{HostPath: targetFile, ContainerPath: "/app/secret.txt"},
112112
})
113113

114-
require.Error(t, err)
115-
assert.Contains(t, err.Error(), "permission denied")
116-
assert.Contains(t, err.Error(), "secret.txt")
117-
assert.Equal(t, 0, client.untarCount, "should not attempt copy on stat error")
118-
assert.Empty(t, client.execCmds, "should not attempt delete on stat error")
114+
assert.ErrorContains(t, err, "permission denied")
115+
assert.ErrorContains(t, err, "secret.txt")
116+
assert.Equal(t, client.untarCount, 0, "should not attempt copy on stat error")
117+
assert.Equal(t, len(client.execCmds), 0, "should not attempt delete on stat error")
119118
}
120119

121120
func TestSync_MixedPaths(t *testing.T) {
122121
tmpDir := t.TempDir()
123122
existingFile := filepath.Join(tmpDir, "keep.txt")
124-
require.NoError(t, os.WriteFile(existingFile, []byte("data"), 0o644))
123+
assert.NilError(t, os.WriteFile(existingFile, []byte("data"), 0o644))
125124

126125
client := &fakeLowLevelClient{
127126
containers: []container.Summary{{ID: "ctr1"}},
@@ -133,8 +132,8 @@ func TestSync_MixedPaths(t *testing.T) {
133132
{HostPath: "/no/such/path", ContainerPath: "/app/removed.txt"},
134133
})
135134

136-
require.NoError(t, err)
137-
assert.Equal(t, 1, client.untarCount, "existing path should be copied")
138-
require.Len(t, client.execCmds, 1)
139-
assert.Contains(t, client.execCmds[0][len(client.execCmds[0])-1], "removed.txt")
135+
assert.NilError(t, err)
136+
assert.Equal(t, client.untarCount, 1, "existing path should be copied")
137+
assert.Equal(t, len(client.execCmds), 1)
138+
assert.Check(t, cmp.Contains(client.execCmds[0][len(client.execCmds[0])-1], "removed.txt"))
140139
}

0 commit comments

Comments
 (0)