summaryrefslogtreecommitdiffstats
path: root/request_test.go
diff options
context:
space:
mode:
authorclsr <clsr@clsr.net>2017-08-25 17:04:42 +0200
committerclsr <clsr@clsr.net>2017-08-25 17:04:44 +0200
commit9ca364d8753a5f2c7529c5b3dd7178bfd51effc6 (patch)
treedc5ab072ffbbd37da910d440e05b5bc56dc3f6da /request_test.go
parentba217ddeef9c6cd502a6f150bf59cf3ce329cc61 (diff)
downloadcnp-go-9ca364d8753a5f2c7529c5b3dd7178bfd51effc6.tar.gz
cnp-go-9ca364d8753a5f2c7529c5b3dd7178bfd51effc6.zip
Add support for the draft/cnp-select "select" request/response parameterv0.1.2
Diffstat (limited to 'request_test.go')
-rw-r--r--request_test.go24
1 files changed, 23 insertions, 1 deletions
diff --git a/request_test.go b/request_test.go
index bb4aa9b..23b8ac0 100644
--- a/request_test.go
+++ b/request_test.go
@@ -64,6 +64,10 @@ var requestTests = []requestTest{
{"", "/", Parameters{"if_modified": "12345-01-01T00:00:00Z"}, nil, ErrorInvalid{}},
{"", "/", Parameters{"if_modified": "-5-01-01T00:00:00Z"}, nil, ErrorInvalid{}},
{"", "/", Parameters{"if_modified": "-2005-01-01T00:00:00Z"}, nil, ErrorInvalid{}},
+ {"", "/", Parameters{"select": "w"}, nil, ErrorInvalid{}},
+ {"", "/", Parameters{"select": " "}, nil, ErrorInvalid{}},
+ {"", "/", Parameters{"select": ":"}, nil, ErrorInvalid{}},
+ {"", "/", Parameters{"select": ":foobar"}, nil, ErrorInvalid{}},
// valid simple requests
{"", "/", nil, nil, nil},
@@ -73,7 +77,7 @@ var requestTests = []requestTest{
{"example.com", "/ f=#\\oo///.././.../~/\x01/\xff/ba\nr", nil, nil, nil},
// valid request params
- {"", "/", Parameters{"length": "", "name": "", "type": "", "if_modified": "", "": "", "q\x00we": "=a s\nd"}, nil, nil},
+ {"", "/", Parameters{"length": "", "name": "", "type": "", "if_modified": "", "select": "", "": "", "q\x00we": "=a s\nd"}, nil, nil},
{"", "/", Parameters{"length": "0"}, nil, nil},
{"", "/", Parameters{"length": "1"}, nil, nil},
{"", "/", Parameters{"length": "12345670089000000"}, nil, nil},
@@ -90,6 +94,10 @@ var requestTests = []requestTest{
{"", "/", Parameters{"if_modified": "0123-05-06T07:08:09Z"}, nil, nil},
{"", "/", Parameters{"if_modified": "0000-02-29T00:00:00Z"}, nil, nil},
{"", "/", Parameters{"if_modified": "2000-02-29T00:00:00Z"}, nil, nil},
+ {"", "/", Parameters{"select": "\x00:\x00"}, nil, nil},
+ {"", "/", Parameters{"select": "foo:bar:baz"}, nil, nil},
+ {"", "/", Parameters{"select": "byte:5-"}, nil, nil},
+ {"", "/", Parameters{"select": "cnm:#/foo/bar"}, nil, nil},
}
func TestNewRequest(t *testing.T) {
@@ -274,6 +282,20 @@ func TestRequestGetSet(t *testing.T) {
tm2 = req.IfModified().Format(time.RFC3339)
}
c(k, v, tst.v, tm2)
+ case "select":
+ if tst.v != nil {
+ continue
+ }
+ sel := ""
+ ss := strings.SplitN(v, ":", 2)
+ if len(ss) == 2 {
+ req.SetSelect(ss[0], ss[1])
+ a, b := req.Select()
+ if a != "" {
+ sel = a + ":" + b
+ }
+ }
+ c(k, v, tst.v, sel)
default:
req.SetParam(k, v)
c(k, v, tst.v, req.Param(k))