github.com/slspeek/camlistore_namedsearch@v0.0.0-20140519202248-ed6f70f7721a/pkg/blobserver/handlers/enumerate_test.go (about) 1 /* 2 Copyright 2011 Google Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package handlers 18 19 import ( 20 "net/http" 21 "net/http/httptest" 22 "testing" 23 24 "camlistore.org/pkg/blob" 25 "camlistore.org/pkg/context" 26 . "camlistore.org/pkg/test/asserts" 27 ) 28 29 type emptyEnumerator struct { 30 } 31 32 func (ee *emptyEnumerator) EnumerateBlobs(ctx *context.Context, dest chan<- blob.SizedRef, after string, limit int) error { 33 close(dest) 34 return nil 35 } 36 37 type enumerateInputTest struct { 38 name string 39 url string 40 expectedCode int 41 expectedBody string 42 } 43 44 func TestEnumerateInput(t *testing.T) { 45 enumerator := &emptyEnumerator{} 46 47 emptyOutput := "{\n \"blobs\": [\n\n ],\n \"canLongPoll\": true\n}\n" 48 49 tests := []enumerateInputTest{ 50 {"no 'after' with 'maxwaitsec'", 51 "http://example.com/camli/enumerate-blobs?after=foo&maxwaitsec=1", 400, 52 errMsgMaxWaitSecWithAfter}, 53 {"'maxwaitsec' of 0 is okay with 'after'", 54 "http://example.com/camli/enumerate-blobs?after=foo&maxwaitsec=0", 200, 55 emptyOutput}, 56 } 57 for _, test := range tests { 58 wr := httptest.NewRecorder() 59 wr.Code = 200 // default 60 req, _ := http.NewRequest("GET", test.url, nil) 61 handleEnumerateBlobs(wr, req, enumerator) 62 ExpectInt(t, test.expectedCode, wr.Code, "response code for "+test.name) 63 ExpectString(t, test.expectedBody, wr.Body.String(), "output for "+test.name) 64 } 65 }