-
Notifications
You must be signed in to change notification settings - Fork 17
/
action_test.go
71 lines (65 loc) · 2.33 KB
/
action_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
package grill
import (
"reflect"
"testing"
"github.com/golang/protobuf/ptypes/wrappers"
)
func TestMultiOutput(t *testing.T) {
tests := []struct {
name string
input []interface{}
want interface{}
}{
{"NoElement", []interface{}{}, []interface{}{}},
{"OneElement", []interface{}{1}, []interface{}{1}},
{"MultiElement", []interface{}{1, 2}, []interface{}{1, 2}},
{"CompositeElements", []interface{}{1, "abc", nil}, []interface{}{1, "abc", nil}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ActionOutput(tt.input...); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ActionOutput() = %v, want %v", got, tt.want)
}
})
}
}
func TestAssertOutput(t *testing.T) {
type custom struct {
val int
}
tests := []struct {
name string
output interface{}
expected []interface{}
wantErr bool
}{
{"SingleInt-Failure", 1, []interface{}{2}, true},
{"SingleInt-Success", 1, []interface{}{1}, false},
{"MultiInt-Failure", []interface{}{1, 2, 3}, []interface{}{1, 1, 3}, true},
{"MultiIntInt-InvalidLength-Failure", []interface{}{1, 2, 3, 4}, []interface{}{1, 1, 3}, true},
{"MultiInt-AnySuccess", []interface{}{1, 2, 3}, []interface{}{Any, Any, Any}, false},
{"MultiInt-Success", []interface{}{1, 2, 3}, []interface{}{1, 2, 3}, false},
{"String-Success", []interface{}{"1", "2", "3"}, []interface{}{"1", "2", "3"}, false},
{"Custom-Success", &custom{1}, []interface{}{&custom{1}}, false},
{"Composite-Failure", []interface{}{1, "1", &custom{1}}, []interface{}{1, "1", &custom{2}}, true},
{"Composite-Success", []interface{}{1, "1", &custom{1}}, []interface{}{1, "1", &custom{1}}, false},
{"Composite-Any", []interface{}{1, "1", &custom{1}}, []interface{}{1, "1", Any}, false},
{"NilProtoMessage-Success", []interface{}{getNilProtoMessage(), "1"}, []interface{}{nil, "1"}, false},
{"NilError-Success", []interface{}{2, getNilError()}, []interface{}{2, nil}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assertion := AssertOutput(tt.expected...)
assertion.(OutputAssertion).SetOutput(tt.output)
if gotErr := assertion.Assert(); (gotErr != nil) != tt.wantErr {
t.Errorf("AssertOutput() gotErr = %v, wantErr %v", gotErr, tt.wantErr)
}
})
}
}
func getNilProtoMessage() *wrappers.StringValue {
return nil
}
func getNilError() error {
return nil
}