Skip to content

Commit f97b4ff

Browse files
committed
test: update TarDir unit test
The current TestTarDir does not check if an empty archive is produced. Update the test case to check for empty tar archives. The include test case does not correctly check for *.mod, files. Update the assertion to expect files matching either pattern. The test is currently failing and will be fixed in the next few commits. Signed-off-by: Aaron D Borden <[email protected]>
1 parent 2af4858 commit f97b4ff

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pkg/utils/utils_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package utils
22

33
import (
44
"archive/tar"
5+
"fmt"
56
"io"
67
"os"
78
"path"
@@ -126,19 +127,22 @@ func TestTarDir(t *testing.T) {
126127

127128
_ = TarDir(testSrcDir, tarPath, []string{}, []string{"*.mod"})
128129
fileNames, _ := getTarFileNames(tarPath)
130+
assert.Greater(t, len(fileNames), 0, "expected tar to have greater than 0 files")
129131
for _, fileName := range fileNames {
130132
flag, _ := filepath.Match(getNewPattern("*.mod"), fileName)
131-
assert.Equal(t, flag, false)
133+
assert.Equal(t, flag, false, "expected *.mod to be excluded")
132134
}
133135
_, err = os.Stat(tarPath)
134136
assert.Equal(t, err, nil)
135137
os.Remove(tarPath)
136138

137139
_ = TarDir(testSrcDir, tarPath, []string{"*/*.lock", "*.mod"}, []string{})
138140
fileNames, _ = getTarFileNames(tarPath)
141+
assert.Greater(t, len(fileNames), 0, "expected tar to have greater than 0 files")
139142
for _, fileName := range fileNames {
140-
flag, _ := filepath.Match(getNewPattern("*/*.lock"), fileName)
141-
assert.Equal(t, flag, true)
143+
matchedLockPattern, _ := filepath.Match(getNewPattern("*/*.lock"), fileName)
144+
matchedModPattern, _ := filepath.Match(getNewPattern("*.mod"), fileName)
145+
assert.True(t, matchedLockPattern || matchedModPattern, fmt.Sprintf("expected \"%s\" to match one of */*.lock or *.mod", fileName))
142146
}
143147
_, err = os.Stat(tarPath)
144148
assert.Equal(t, err, nil)

0 commit comments

Comments
 (0)