1
// session_test - REST client session tests
2
// Copyright 2015 Dean Troyer
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
8
// http://www.apache.org/licenses/LICENSE-2.0
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.
24
"git.openstack.org/stackforge/golang-client.git/openstack"
25
"git.openstack.org/stackforge/golang-client.git/testUtil"
28
type TestStruct struct {
30
Name string `json:"name"`
33
func TestSessionGet(t *testing.T) {
34
tokn := "eaaafd18-0fed-4b3a-81b4-663c99ec1cbb"
35
var apiServer = testUtil.CreateGetJsonTestServer(
38
`{"id":"id1","name":"Chris"}`,
41
expected := TestStruct{ID: "id1", Name: "Chris"}
42
actual := TestStruct{}
44
s, _ := session.NewSession(nil, "", nil)
45
var headers http.Header = http.Header{}
46
headers.Set("X-Auth-Token", tokn)
47
headers.Set("Accept", "application/json")
48
headers.Set("Etag", "md5hash-blahblah")
49
resp, err := s.Get(apiServer.URL, nil, &headers)
53
testUtil.IsNil(t, err)
55
if err = json.Unmarshal(resp.Body, &actual); err != nil {
59
testUtil.Equals(t, expected, actual)