mirror of https://github.com/perkeep/perkeep.git
65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
|
/*
|
||
|
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": [
|
||
|
{"blobRef": "foo-abc",
|
||
|
"size": 123},
|
||
|
{"blobRef": "foo-def",
|
||
|
"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)
|
||
|
}
|
||
|
|
||
|
if sb, ok := hm["foo-abc"]; !ok || sb.Size != 123 {
|
||
|
t.Errorf("Got unexpected map: %#v", hm)
|
||
|
}
|
||
|
|
||
|
if sb, ok := hm["foo-def"]; !ok || sb.Size != 999 {
|
||
|
t.Errorf("Got unexpected map: %#v", hm)
|
||
|
}
|
||
|
}
|