X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/b002129afda08bbb4fdbed6e629858a5c298c068..080c940d7a8134a6e277a53b7e45eb27e2b2c87f:/sdk/go/arvados/client_test.go diff --git a/sdk/go/arvados/client_test.go b/sdk/go/arvados/client_test.go index 2db50bfd6c..df938008d4 100644 --- a/sdk/go/arvados/client_test.go +++ b/sdk/go/arvados/client_test.go @@ -1,3 +1,7 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: Apache-2.0 + package arvados import ( @@ -5,8 +9,10 @@ import ( "fmt" "io/ioutil" "net/http" + "net/url" "sync" "testing" + "testing/iotest" ) type stubTransport struct { @@ -46,6 +52,22 @@ func (stub *errorTransport) RoundTrip(req *http.Request) (*http.Response, error) return nil, fmt.Errorf("something awful happened") } +type timeoutTransport struct { + response []byte +} + +func (stub *timeoutTransport) RoundTrip(req *http.Request) (*http.Response, error) { + return &http.Response{ + Status: "200 OK", + StatusCode: 200, + Proto: "HTTP/1.1", + ProtoMajor: 1, + ProtoMinor: 1, + Request: req, + Body: ioutil.NopCloser(iotest.TimeoutReader(bytes.NewReader(stub.response))), + }, nil +} + func TestCurrentUser(t *testing.T) { t.Parallel() stub := &stubTransport{ @@ -81,3 +103,72 @@ func TestCurrentUser(t *testing.T) { t.Errorf("got nil error, expected something awful") } } + +func TestAnythingToValues(t *testing.T) { + type testCase struct { + in interface{} + // ok==nil means anythingToValues should return an + // error, otherwise it's a func that returns true if + // out is correct + ok func(out url.Values) bool + } + for _, tc := range []testCase{ + { + in: map[string]interface{}{"foo": "bar"}, + ok: func(out url.Values) bool { + return out.Get("foo") == "bar" + }, + }, + { + in: map[string]interface{}{"foo": 2147483647}, + ok: func(out url.Values) bool { + return out.Get("foo") == "2147483647" + }, + }, + { + in: map[string]interface{}{"foo": 1.234}, + ok: func(out url.Values) bool { + return out.Get("foo") == "1.234" + }, + }, + { + in: map[string]interface{}{"foo": "1.234"}, + ok: func(out url.Values) bool { + return out.Get("foo") == "1.234" + }, + }, + { + in: map[string]interface{}{"foo": map[string]interface{}{"bar": 1.234}}, + ok: func(out url.Values) bool { + return out.Get("foo") == `{"bar":1.234}` + }, + }, + { + in: url.Values{"foo": {"bar"}}, + ok: func(out url.Values) bool { + return out.Get("foo") == "bar" + }, + }, + { + in: 1234, + ok: nil, + }, + { + in: []string{"foo"}, + ok: nil, + }, + } { + t.Logf("%#v", tc.in) + out, err := anythingToValues(tc.in) + switch { + case tc.ok == nil: + if err == nil { + t.Errorf("got %#v, expected error", out) + } + case err != nil: + t.Errorf("got err %#v, expected nil", err) + case !tc.ok(out): + t.Errorf("got %#v but tc.ok() says that is wrong", out) + } + } +}