2011-05-10 19:56:59 +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 client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var response = `{
|
|
|
|
"stat": [
|
2013-08-04 02:54:30 +00:00
|
|
|
{"blobRef": "foo-abcd",
|
2011-05-10 19:56:59 +00:00
|
|
|
"size": 123},
|
2013-08-04 02:54:30 +00:00
|
|
|
{"blobRef": "foo-cdef",
|
2011-05-10 19:56:59 +00:00
|
|
|
"size": 999}
|
|
|
|
],
|
|
|
|
"maxUploadSize": 1048576,
|
|
|
|
"uploadUrl": "http://upload-server.example.com/some/server-chosen/url",
|
|
|
|
"uploadUrlExpirationSeconds": 7200,
|
|
|
|
"canLongPoll": true
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
func TestParseStatResponse(t *testing.T) {
|
|
|
|
res, err := parseStatResponse(strings.NewReader(response))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
hm := res.HaveMap
|
|
|
|
res.HaveMap = nil
|
|
|
|
want := &statResponse{
|
|
|
|
HaveMap: nil,
|
|
|
|
maxUploadSize: 1048576,
|
|
|
|
uploadUrl: "http://upload-server.example.com/some/server-chosen/url",
|
|
|
|
uploadUrlExpirationSeconds: 7200,
|
|
|
|
canLongPoll: true,
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(want, res) {
|
|
|
|
t.Errorf(" Got: %#v\nWant: %#v", res, want)
|
|
|
|
}
|
|
|
|
|
2013-08-04 02:54:30 +00:00
|
|
|
if sb, ok := hm["foo-abcd"]; !ok || sb.Size != 123 {
|
2011-05-10 19:56:59 +00:00
|
|
|
t.Errorf("Got unexpected map: %#v", hm)
|
|
|
|
}
|
|
|
|
|
2013-08-04 02:54:30 +00:00
|
|
|
if sb, ok := hm["foo-cdef"]; !ok || sb.Size != 999 {
|
2011-05-10 19:56:59 +00:00
|
|
|
t.Errorf("Got unexpected map: %#v", hm)
|
|
|
|
}
|
|
|
|
}
|