blob: ee3b79e2711c40cb6f902d4cd58a70c404b16faa [file] [log] [blame]
Samuel A. Falvo II808bb632014-03-12 00:07:50 -07001package images
2
3import (
Samuel A. Falvo II808bb632014-03-12 00:07:50 -07004 "encoding/json"
Jon Perritt30558642014-04-14 17:07:12 -05005 "testing"
Samuel A. Falvo II808bb632014-03-12 00:07:50 -07006)
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 }
Jon Perritt30558642014-04-14 17:07:12 -050030
Samuel A. Falvo II808bb632014-03-12 00:07:50 -070031 image, err := GetImage(simpleImageMap)
32 if err != nil {
33 t.Fatal(err)
34 }
Jon Perritt30558642014-04-14 17:07:12 -050035
Samuel A. Falvo II808bb632014-03-12 00:07:50 -070036 if image.Id != "52415800-8b69-11e0-9b19-734f6f006e54" {
Jon Perritt30558642014-04-14 17:07:12 -050037 t.Fatal("I expected an image ID of 52415800-8b69-11e0-9b19-734f6f006e54; got " + image.Id)
Samuel A. Falvo II808bb632014-03-12 00:07:50 -070038 }
Jon Perritt30558642014-04-14 17:07:12 -050039
Samuel A. Falvo II808bb632014-03-12 00:07:50 -070040 if image.Name != "CentOS 5.2" {
Jon Perritt30558642014-04-14 17:07:12 -050041 t.Fatal("I expected an image name of CentOS 5.2; got " + image.Name)
Samuel A. Falvo II808bb632014-03-12 00:07:50 -070042 }
43}