Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 1 | package images |
| 2 | |
| 3 | import ( |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 4 | "encoding/json" |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 5 | "testing" |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 6 | ) |
| 7 | |
| 8 | const ( |
| 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 | |
| 24 | func 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 Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 30 | |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 31 | image, err := GetImage(simpleImageMap) |
| 32 | if err != nil { |
| 33 | t.Fatal(err) |
| 34 | } |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 35 | |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 36 | if image.Id != "52415800-8b69-11e0-9b19-734f6f006e54" { |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 37 | t.Fatal("I expected an image ID of 52415800-8b69-11e0-9b19-734f6f006e54; got " + image.Id) |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 38 | } |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 39 | |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 40 | if image.Name != "CentOS 5.2" { |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 41 | t.Fatal("I expected an image name of CentOS 5.2; got " + image.Name) |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 42 | } |
| 43 | } |