2011-03-01 02:11:30 +00:00
|
|
|
/*
|
|
|
|
Copyright 2011 Google Inc.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"camli/blobref"
|
2011-03-19 04:17:26 +00:00
|
|
|
. "camli/test/asserts"
|
2011-03-01 02:11:30 +00:00
|
|
|
"http"
|
2011-03-15 17:26:37 +00:00
|
|
|
"http/httptest"
|
2011-03-01 02:11:30 +00:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func makeGetRequest(url string) *http.Request {
|
|
|
|
req := &http.Request{
|
|
|
|
Method: "GET",
|
|
|
|
RawURL: url,
|
|
|
|
}
|
|
|
|
var err os.Error
|
|
|
|
req.URL, err = http.ParseURL(url)
|
|
|
|
if err != nil {
|
|
|
|
panic("Error parsing url: " + url)
|
|
|
|
}
|
|
|
|
return req
|
|
|
|
}
|
|
|
|
|
|
|
|
type emptyEnumerator struct {
|
|
|
|
}
|
|
|
|
|
2011-05-10 18:21:28 +00:00
|
|
|
func (ee *emptyEnumerator) EnumerateBlobs(dest chan<- *blobref.SizedBlobRef,
|
2011-03-01 02:11:30 +00:00
|
|
|
after string,
|
|
|
|
limit uint,
|
|
|
|
waitSeconds int) os.Error {
|
2011-03-25 16:52:51 +00:00
|
|
|
close(dest)
|
2011-03-01 02:11:30 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type enumerateInputTest struct {
|
|
|
|
name string
|
|
|
|
url string
|
|
|
|
expectedCode int
|
|
|
|
expectedBody string
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEnumerateInput(t *testing.T) {
|
|
|
|
enumerator := &emptyEnumerator{}
|
|
|
|
|
|
|
|
emptyOutput := "{\n \"blobs\": [\n\n ],\n \"canLongPoll\": true\n}\n"
|
|
|
|
|
|
|
|
tests := []enumerateInputTest{
|
|
|
|
{"no 'after' with 'maxwaitsec'",
|
|
|
|
"http://example.com/camli/enumerate-blobs?after=foo&maxwaitsec=1", 400,
|
|
|
|
errMsgMaxWaitSecWithAfter},
|
|
|
|
{"'maxwaitsec' of 0 is okay with 'after'",
|
|
|
|
"http://example.com/camli/enumerate-blobs?after=foo&maxwaitsec=0", 200,
|
|
|
|
emptyOutput},
|
|
|
|
}
|
|
|
|
for _, test := range tests {
|
2011-03-15 17:26:37 +00:00
|
|
|
wr := httptest.NewRecorder()
|
|
|
|
wr.Code = 200 // default
|
2011-03-01 02:11:30 +00:00
|
|
|
req := makeGetRequest(test.url)
|
2011-05-09 16:11:18 +00:00
|
|
|
handleEnumerateBlobs(wr, req, enumerator)
|
2011-03-15 17:26:37 +00:00
|
|
|
ExpectInt(t, test.expectedCode, wr.Code, "response code for " + test.name)
|
|
|
|
ExpectString(t, test.expectedBody, wr.Body.String(), "output for " + test.name)
|
2011-03-01 02:11:30 +00:00
|
|
|
}
|
|
|
|
}
|