-
Notifications
You must be signed in to change notification settings - Fork 3
/
some.go
62 lines (50 loc) · 982 Bytes
/
some.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
package tests
import (
"fmt"
"reflect"
"strconv"
)
// $some
type someTest struct {
test Test
}
func NewSomeTest(input interface{}) (Test, error) {
fieldTest, err := fieldTestForValue(input)
if err != nil {
return nil, err
}
return &someTest{
test: fieldTest,
}, nil
}
func (at *someTest) Run(input interface{}) error {
castedArray, ok := castArray(input)
if !ok {
return fmt.Errorf("input (%#v %v) isn't an array", input, reflect.TypeOf(input))
}
if len(castedArray) == 0 {
return fmt.Errorf("input (%#v %v) is empty", input, reflect.TypeOf(input))
}
succeeded := false
var errs []error
for idx, element := range castedArray {
err := at.test.Run(element)
if err == nil {
succeeded = true
continue
}
errs = append(errs, &fieldError{
field: strconv.Itoa(idx),
fieldError: err,
})
}
if !succeeded {
return &objectTestError{
errors: errs,
}
}
return nil
}
func (at *someTest) IsMetaTest() bool {
return true
}