blob: 217baee23efcd09699a60475d55c06d624e55751 [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
Ash Wilson7ddf0362014-09-17 10:59:09 -040011 simpleImageJSON = `
12 {
Samuel A. Falvo II808bb632014-03-12 00:07:50 -070013 "id": "52415800-8b69-11e0-9b19-734f6f006e54",
14 "name": "CentOS 5.2",
Ash Wilson7ddf0362014-09-17 10:59:09 -040015 "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 II808bb632014-03-12 00:07:50 -070027)
28
Ash Wilson12259392014-09-17 10:50:02 -040029func TestExtractImage(t *testing.T) {
Ash Wilson7ddf0362014-09-17 10:59:09 -040030 var simpleImage GetResult
31 err := json.Unmarshal([]byte(simpleImageJSON), &simpleImage)
Samuel A. Falvo II808bb632014-03-12 00:07:50 -070032 if err != nil {
33 t.Fatal(err)
34 }
Jon Perritt30558642014-04-14 17:07:12 -050035
Ash Wilson7ddf0362014-09-17 10:59:09 -040036 image, err := ExtractImage(simpleImage)
Samuel A. Falvo II808bb632014-03-12 00:07:50 -070037 if err != nil {
38 t.Fatal(err)
39 }
Jon Perritt30558642014-04-14 17:07:12 -050040
Ash Wilson7ddf0362014-09-17 10:59:09 -040041 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 II808bb632014-03-12 00:07:50 -070043 }
Jon Perritt30558642014-04-14 17:07:12 -050044
Samuel A. Falvo II808bb632014-03-12 00:07:50 -070045 if image.Name != "CentOS 5.2" {
Jon Perritt30558642014-04-14 17:07:12 -050046 t.Fatal("I expected an image name of CentOS 5.2; got " + image.Name)
Samuel A. Falvo II808bb632014-03-12 00:07:50 -070047 }
48}