-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_test.go
51 lines (45 loc) · 1.24 KB
/
error_test.go
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
package zfs
import (
"errors"
"fmt"
"os/exec"
"testing"
)
func TestError(t *testing.T) {
tests := []struct {
err error
debug string
stderr string
}{
// Empty error
{nil, "", ""},
// Typical error
{errors.New("exit status foo"), "/sbin/foo bar qux", "command not found"},
// Quoted error
{errors.New("exit status quoted"), "\"/sbin/foo\" bar qux", "\"some\" 'random' `quotes`"},
{ErrFilesystemAlreadyMounted, "does not matter", "cannot mount 'fh27/115125': filesystem already mounted"},
}
for _, test := range tests {
// Generate error from tests
zErr := CommandError{
Err: test.err,
Debug: test.debug,
Stderr: test.stderr,
}
// Verify output format is consistent, so that any changes to the
// CommandError method must be reflected by the test
if str := zErr.Error(); str != fmt.Sprintf("%s: %q => %s", test.err, test.debug, test.stderr) {
t.Fatalf("unexpected CommandError string: %v", str)
}
}
}
func Test_createError(t *testing.T) {
err := createError(
&exec.Cmd{},
`exit status 1: "/sbin/zfs zfs umount fe29/252799" => cannot unmount '/disks/252799': pool or dataset is busy`,
errors.New("test"),
)
if !errors.Is(err, ErrPoolOrDatasetBusy) {
t.Fatalf("unexpected error type: %v", err)
}
}