-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpebkac_test.go
58 lines (43 loc) · 1.02 KB
/
pebkac_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
package param
import (
"net/url"
"strings"
"testing"
)
type Bad struct {
Unknown interface{}
}
type Bad2 struct {
Unknown *interface{}
}
type Bad3 struct {
BadMap map[int]int
}
// These tests are not parallel so we can frob pebkac behavior in an isolated
// way
func assertPebkac(t *testing.T, err error) {
if err == nil {
t.Error("Expected PEBKAC error message")
} else if !strings.HasSuffix(err.Error(), yourFault) {
t.Errorf("Expected PEBKAC error, but got: %v", err)
}
}
func TestBadInputs(t *testing.T) {
pebkacTesting = true
err := Parse(url.Values{"Unknown": {"4"}}, Bad{})
assertPebkac(t, err)
b := &Bad{}
err = Parse(url.Values{"Unknown": {"4"}}, &b)
assertPebkac(t, err)
pebkacTesting = false
}
func TestBadTypes(t *testing.T) {
pebkacTesting = true
err := Parse(url.Values{"Unknown": {"4"}}, &Bad{})
assertPebkac(t, err)
err = Parse(url.Values{"Unknown": {"4"}}, &Bad2{})
assertPebkac(t, err)
err = Parse(url.Values{"BadMap[llama]": {"4"}}, &Bad3{})
assertPebkac(t, err)
pebkacTesting = false
}