golang-client/misc/rfc8601DateTime_test.go
Chris Robinson 219cc1c2c1 Added Capability to get images and images with details
new file:   examples/30-image-v1.go
	modified:   examples/config.json.dist
	modified:   examples/setup.go
	modified:   identity/v2/auth.go
	new file:   image/v1/image.go
	new file:   image/v1/image_test.go
	new file:   misc/rfc8601DateTime.go
	new file:   misc/rfc8601DateTime_test.go
	modified:   misc/util.go
	modified:   misc/util_test.go
	modified:   objectstorage/v1/objectstorage.go
	modified:   objectstorage/v1/objectstorage_test.go
	new file:   testUtil/testUtil.go

Partially implements blueprint image-v1

Change-Id: I6277a5c8915f45f4b7585855d836015ffd9e1c12
2014-10-27 14:09:26 -07:00

59 lines
1.9 KiB
Go

// Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
//
// 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 misc_test
import (
"encoding/json"
"git.openstack.org/stackforge/golang-client.git/misc"
"git.openstack.org/stackforge/golang-client.git/testUtil"
"testing"
"time"
)
var testValue = `{"created_at":"2014-09-29T14:44:31"}`
var testTime, _ = time.Parse(`"2006-01-02T15:04:05"`, `"2014-09-29T14:44:31"`)
var timeTestValue = timeTest{CreatedAt: misc.RFC8601DateTime{testTime}}
func TestMarshalTimeTest(t *testing.T) {
bytes, _ := json.Marshal(timeTestValue)
testUtil.Equals(t, testValue, string(bytes))
}
func TestUnmarshalValidTimeTest(t *testing.T) {
val := timeTest{}
err := json.Unmarshal([]byte(testValue), &val)
testUtil.IsNil(t, err)
testUtil.Equals(t, timeTestValue.CreatedAt.Time, val.CreatedAt.Time)
}
func TestUnmarshalInvalidDataFormatTimeTest(t *testing.T) {
val := timeTest{}
err := json.Unmarshal([]byte("something other than date time"), &val)
testUtil.Assert(t, err != nil, "expected an error")
}
// Added this test to ensure that its understood that
// only one specific format is supported at this time.
func TestUnmarshalInvalidDateTimeFormatTimeTest(t *testing.T) {
val := timeTest{}
err := json.Unmarshal([]byte("2014-09-29T14:44"), &val)
testUtil.Assert(t, err != nil, "expected an error")
}
type timeTest struct {
CreatedAt misc.RFC8601DateTime `json:"created_at"`
}