-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathloader_test.go
More file actions
62 lines (54 loc) · 1.2 KB
/
loader_test.go
File metadata and controls
62 lines (54 loc) · 1.2 KB
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 forms
import (
"errors"
"net/url"
"testing"
)
var (
load_error = errors.New("load_error")
error_loader LoaderFunc = func(in map[string]interface{}) (out interface{}, errs map[string]error, err error) {
err = load_error
return
}
int_loader LoaderFunc = func(in map[string]interface{}) (out interface{}, errs map[string]error, err error) {
out = 2
return
}
)
func fatal_loader(t *testing.T) LoaderFunc {
return func(in map[string]interface{}) (out interface{}, errs map[string]error, err error) {
t.Fail()
return
}
}
func TestLoaderNotCalledOnConverterError(t *testing.T) {
f := &Form{
Fields: []Field{
{Name: "foo", Converter: error_converter},
},
Loader: fatal_loader(t),
}
f.Load(create_req(url.Values{
"foo": {"bar"},
}))
}
func TestLoaderNotCalledOnValidatorError(t *testing.T) {
f := &Form{
Fields: []Field{
{Name: "foo", Validators: []Validator{error_validator}},
},
Loader: fatal_loader(t),
}
f.Load(create_req(url.Values{
"foo": {"bar"},
}))
}
func TestLoaderReturnsValue(t *testing.T) {
f := &Form{
Loader: int_loader,
}
res := f.Load(create_req(nil))
if ex, ok := res.Value.(int); !ok || ex != 2 {
t.Fatal("Expected %v. Got %v", 2, ex)
}
}