blob: 05a8550db1c3b51111702bef47c3b1ecfd100c81 [file] [log] [blame]
Samuel A. Falvo II808bb632014-03-12 00:07:50 -07001package images
2
3import (
4 "testing"
5 "encoding/json"
6)
7
8const (
9 // This example was taken from: http://docs.openstack.org/api/openstack-compute/2/content/Rebuild_Server-d1e3538.html
10
11 simpleImageJson = `{
12 "id": "52415800-8b69-11e0-9b19-734f6f006e54",
13 "name": "CentOS 5.2",
14 "links": [{
15 "rel": "self",
16 "href": "http://servers.api.openstack.org/v2/1234/images/52415800-8b69-11e0-9b19-734f6f006e54"
17 },{
18 "rel": "bookmark",
19 "href": "http://servers.api.openstack.org/1234/images/52415800-8b69-11e0-9b19-734f6f006e54"
20 }]
21 }`
22)
23
24func TestGetImage(t *testing.T) {
25 var simpleImageMap map[string]interface{}
26 err := json.Unmarshal([]byte(simpleImageJson), &simpleImageMap)
27 if err != nil {
28 t.Fatal(err)
29 }
30
31 image, err := GetImage(simpleImageMap)
32 if err != nil {
33 t.Fatal(err)
34 }
35
36 if image.Id != "52415800-8b69-11e0-9b19-734f6f006e54" {
37 t.Fatal("I expected an image ID of 52415800-8b69-11e0-9b19-734f6f006e54; got "+image.Id)
38 }
39
40 if image.Name != "CentOS 5.2" {
41 t.Fatal("I expected an image name of CentOS 5.2; got "+image.Name)
42 }
43}