-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathfind_files_windows_test.go
More file actions
68 lines (62 loc) · 1.22 KB
/
find_files_windows_test.go
File metadata and controls
68 lines (62 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1
//go:build windows
package fsutil
import (
"errors"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestHandleFsError(t *testing.T) {
tests := []struct {
name string
err error
wantSkip bool
wantErr error
}{
{
name: "nil error",
err: nil,
wantSkip: false,
wantErr: nil,
},
{
name: "permission denied is skipped",
err: os.ErrPermission,
wantSkip: true,
wantErr: nil,
},
{
name: "not exist is skipped",
err: os.ErrNotExist,
wantSkip: true,
wantErr: nil,
},
{
name: "invalid is skipped",
err: os.ErrInvalid,
wantSkip: true,
wantErr: nil,
},
{
name: "other error is propagated",
err: errors.New("some other error"),
wantSkip: true,
wantErr: errors.New("some other error"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
skip, err := handleFsError(tt.err)
assert.Equal(t, tt.wantSkip, skip)
if tt.wantErr != nil {
require.Error(t, err)
assert.Equal(t, tt.wantErr.Error(), err.Error())
} else {
require.NoError(t, err)
}
})
}
}