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 | |
Ash Wilson | 7ddf036 | 2014-09-17 10:59:09 -0400 | [diff] [blame^] | 11 | simpleImageJSON = ` |
| 12 | { |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 13 | "id": "52415800-8b69-11e0-9b19-734f6f006e54", |
| 14 | "name": "CentOS 5.2", |
Ash Wilson | 7ddf036 | 2014-09-17 10:59:09 -0400 | [diff] [blame^] | 15 | "links": [ |
| 16 | { |
| 17 | "rel": "self", |
| 18 | "href": "http://servers.api.openstack.org/v2/1234/images/52415800-8b69-11e0-9b19-734f6f006e54" |
| 19 | }, |
| 20 | { |
| 21 | "rel": "bookmark", |
| 22 | "href": "http://servers.api.openstack.org/1234/images/52415800-8b69-11e0-9b19-734f6f006e54" |
| 23 | } |
| 24 | ] |
| 25 | } |
| 26 | ` |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 27 | ) |
| 28 | |
Ash Wilson | 1225939 | 2014-09-17 10:50:02 -0400 | [diff] [blame] | 29 | func TestExtractImage(t *testing.T) { |
Ash Wilson | 7ddf036 | 2014-09-17 10:59:09 -0400 | [diff] [blame^] | 30 | var simpleImage GetResult |
| 31 | err := json.Unmarshal([]byte(simpleImageJSON), &simpleImage) |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 32 | if err != nil { |
| 33 | t.Fatal(err) |
| 34 | } |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 35 | |
Ash Wilson | 7ddf036 | 2014-09-17 10:59:09 -0400 | [diff] [blame^] | 36 | image, err := ExtractImage(simpleImage) |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 37 | if err != nil { |
| 38 | t.Fatal(err) |
| 39 | } |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 40 | |
Ash Wilson | 7ddf036 | 2014-09-17 10:59:09 -0400 | [diff] [blame^] | 41 | if image.ID != "52415800-8b69-11e0-9b19-734f6f006e54" { |
| 42 | 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] | 43 | } |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 44 | |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 45 | if image.Name != "CentOS 5.2" { |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 46 | 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] | 47 | } |
| 48 | } |