This repository has been archived by the owner on Aug 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathresult_test.go
105 lines (96 loc) · 2.35 KB
/
result_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package subzero
import "testing"
import "fmt"
import "errors"
import "reflect"
func TestResult(t *testing.T) {
var units = []struct {
exp Result
got string
}{
{Result{Type: "example", Success: "info.bing.com"}, "info.bing.com"},
{Result{Type: "example", Failure: errors.New("failed")}, "failed"},
}
for _, u := range units {
if u.exp.Failure != nil {
if !reflect.DeepEqual(u.exp.Failure.Error(), u.got) {
t.Fatalf("expected '%v', got '%v'", u.exp, u.got)
}
} else {
if !reflect.DeepEqual(u.exp.Success, u.got) {
t.Fatalf("expected '%v', got '%v'", u.exp, u.got)
}
}
}
}
func TestResultIsSuccess(t *testing.T) {
var units = []struct {
exp Result
got bool
}{
{Result{Type: "example", Success: "info.bing.com"}, true},
{Result{Type: "example", Failure: errors.New("failed")}, false},
}
for _, u := range units {
if u.exp.IsSuccess() != u.got {
t.Fatalf("expected '%v', got '%v'", u.exp, u.got)
}
}
}
func TestResultIsFailure(t *testing.T) {
var units = []struct {
exp Result
got bool
}{
{Result{Type: "example", Success: "info.bing.com"}, false},
{Result{Type: "example", Failure: errors.New("failed")}, true},
}
for _, u := range units {
if u.exp.IsFailure() != u.got {
t.Fatalf("expected '%v', got '%v'", u.exp, u.got)
}
}
}
func TestResultHasType(t *testing.T) {
var units = []struct {
exp Result
got bool
}{
{Result{Type: "example", Success: "info.bing.com"}, true},
{Result{Type: "example", Failure: errors.New("failed")}, true},
{Result{}, false},
}
for _, u := range units {
if u.exp.HasType() != u.got {
t.Fatalf("expected '%v', got '%v'", u.exp, u.got)
}
}
}
func ExampleResult() {
result := Result{Type: "example", Success: "info.bing.com"}
if result.Failure != nil {
fmt.Println(result.Type, ":", result.Failure)
} else {
fmt.Println(result.Type, ":", result.Success)
}
// Output: example : info.bing.com
}
func ExampleResult_IsSuccess() {
result := Result{Success: "wiggle.github.com"}
if result.IsSuccess() {
fmt.Println(result.Success)
}
// Output: wiggle.github.com
}
func ExampleResult_IsFailure() {
result := Result{Failure: errors.New("failed to party")}
if result.IsFailure() {
fmt.Println(result.Failure.Error())
}
// Output: failed to party
}
func ExampleResult_HasType() {
result := Result{Type: "example"}
fmt.Println(result.HasType())
// Output: true
}