File: generic_error_test.go

package info (click to toggle)
runc 1.0.0~rc9+dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 1,996 kB
  • sloc: sh: 1,422; ansic: 1,008; makefile: 116
file content (49 lines) | stat: -rw-r--r-- 975 bytes parent folder | download | duplicates (5)
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
package libcontainer

import (
	"fmt"
	"io/ioutil"
	"testing"
)

func TestErrorDetail(t *testing.T) {
	err := newGenericError(fmt.Errorf("test error"), SystemError)
	if derr := err.Detail(ioutil.Discard); derr != nil {
		t.Fatal(derr)
	}
}

func TestErrorWithCode(t *testing.T) {
	err := newGenericError(fmt.Errorf("test error"), SystemError)
	if code := err.Code(); code != SystemError {
		t.Fatalf("expected err code %q but %q", SystemError, code)
	}
}

func TestErrorWithError(t *testing.T) {
	cc := []struct {
		errmsg string
		cause  string
	}{
		{
			errmsg: "test error",
		},
		{
			errmsg: "test error",
			cause:  "test",
		},
	}

	for _, v := range cc {
		err := newSystemErrorWithCause(fmt.Errorf(v.errmsg), v.cause)

		msg := err.Error()
		if v.cause == "" && msg != v.errmsg {
			t.Fatalf("expected err(%q) equal errmsg(%q)", msg, v.errmsg)
		}
		if v.cause != "" && msg == v.errmsg {
			t.Fatalf("unexpected err(%q) equal errmsg(%q)", msg, v.errmsg)
		}

	}
}