diff options
Diffstat (limited to 'internal/vfs/zip')
-rw-r--r-- | internal/vfs/zip/archive_test.go | 24 | ||||
-rw-r--r-- | internal/vfs/zip/vfs_test.go | 28 |
2 files changed, 26 insertions, 26 deletions
diff --git a/internal/vfs/zip/archive_test.go b/internal/vfs/zip/archive_test.go index 37529e22..782c43b1 100644 --- a/internal/vfs/zip/archive_test.go +++ b/internal/vfs/zip/archive_test.go @@ -7,6 +7,7 @@ import ( "crypto/rand" "fmt" "io" + "io/fs" "net/http" "net/http/httptest" "os" @@ -66,7 +67,7 @@ func testOpen(t *testing.T, zip *zipArchive) { }, "file_does_not_exist": { file: "unknown.html", - expectedErr: os.ErrNotExist, + expectedErr: fs.ErrNotExist, }, } @@ -74,7 +75,7 @@ func testOpen(t *testing.T, zip *zipArchive) { t.Run(name, func(t *testing.T) { f, err := zip.Open(context.Background(), tt.file) if tt.expectedErr != nil { - require.EqualError(t, err, tt.expectedErr.Error()) + require.ErrorIs(t, err, tt.expectedErr) return } @@ -248,7 +249,7 @@ func testLstat(t *testing.T, zip *zipArchive) { }, "file_does_not_exist": { file: "unknown.html", - expectedErr: os.ErrNotExist, + expectedErr: fs.ErrNotExist, }, } @@ -256,7 +257,7 @@ func testLstat(t *testing.T, zip *zipArchive) { t.Run(name, func(t *testing.T) { fi, err := zip.Lstat(context.Background(), tt.file) if tt.expectedErr != nil { - require.EqualError(t, err, tt.expectedErr.Error()) + require.ErrorIs(t, err, tt.expectedErr) return } @@ -309,7 +310,7 @@ func testReadLink(t *testing.T, zip *zipArchive) { }, "file_does_not_exist": { file: "unknown.html", - expectedErr: os.ErrNotExist, + expectedErr: fs.ErrNotExist, }, } @@ -317,7 +318,7 @@ func testReadLink(t *testing.T, zip *zipArchive) { t.Run(name, func(t *testing.T) { link, err := zip.Readlink(context.Background(), tt.file) if tt.expectedErr != nil { - require.EqualError(t, err, tt.expectedErr.Error()) + require.ErrorIs(t, err, tt.expectedErr) return } @@ -357,7 +358,7 @@ func TestArchiveCanBeReadAfterOpenCtxCanceled(t *testing.T) { cancel() err := zip.openArchive(ctx, testServerURL+"/public.zip") - require.EqualError(t, err, context.Canceled.Error()) + require.ErrorIs(t, err, context.Canceled) <-zip.done @@ -374,15 +375,14 @@ func TestReadArchiveFails(t *testing.T) { testServerURL, cleanup := newZipFileServerURL(t, "group/zip.gitlab.io/public.zip", nil) defer cleanup() - fs := New(&zipCfg).(*zipVFS) - zip := newArchive(fs, time.Second) + zfs := New(&zipCfg).(*zipVFS) + zip := newArchive(zfs, time.Second) err := zip.openArchive(context.Background(), testServerURL+"/unkown.html") - require.Error(t, err) - require.Contains(t, err.Error(), httprange.ErrNotFound.Error()) + require.ErrorIs(t, err, httprange.ErrNotFound) _, err = zip.Open(context.Background(), "index.html") - require.EqualError(t, err, os.ErrNotExist.Error()) + require.ErrorIs(t, err, fs.ErrNotExist) } func createArchive(t *testing.T, dir string) (map[string][]byte, int64) { diff --git a/internal/vfs/zip/vfs_test.go b/internal/vfs/zip/vfs_test.go index 12e82c1c..af1d263b 100644 --- a/internal/vfs/zip/vfs_test.go +++ b/internal/vfs/zip/vfs_test.go @@ -5,6 +5,7 @@ import ( "errors" "io" "io/fs" + "net/url" "testing" "time" @@ -17,27 +18,27 @@ import ( ) func TestVFSRoot(t *testing.T) { - url, cleanup := newZipFileServerURL(t, "group/zip.gitlab.io/public.zip", nil) + u, cleanup := newZipFileServerURL(t, "group/zip.gitlab.io/public.zip", nil) defer cleanup() tests := map[string]struct { - path string - sha256 string - expectedErrMsg string + path string + sha256 string + expectedErr error }{ "zip_file_exists": { path: "/public.zip", sha256: "d6b318b399cfe9a1c8483e49847ee49a2676d8cfd6df57ec64d971ad03640a75", }, "zip_file_does_not_exist": { - path: "/unknown", - sha256: "filedoesnotexist", - expectedErrMsg: fs.ErrNotExist.Error(), + path: "/unknown", + sha256: "filedoesnotexist", + expectedErr: fs.ErrNotExist, }, "invalid_url": { - path: "/%", - sha256: "invalidurl", - expectedErrMsg: "invalid URL", + path: "/%", + sha256: "invalidurl", + expectedErr: url.EscapeError("%"), }, } @@ -45,10 +46,9 @@ func TestVFSRoot(t *testing.T) { for name, tt := range tests { t.Run(name, func(t *testing.T) { - root, err := vfs.Root(context.Background(), url+tt.path, tt.sha256) - if tt.expectedErrMsg != "" { - require.Error(t, err) - require.Contains(t, err.Error(), tt.expectedErrMsg) + root, err := vfs.Root(context.Background(), u+tt.path, tt.sha256) + if tt.expectedErr != nil { + require.ErrorIs(t, err, tt.expectedErr) return } |