Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 7689304

Browse files
James FisherSamuel Ortiz
authored andcommitted
fix tests
1 parent 6ef241d commit 7689304

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

openstack/imageservice/v2/requests_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ func TestCreateImage(t *testing.T) {
3030
container_format := "bare"
3131
disk_format := "qcow2"
3232
owner := "b4eedccc6fb74fa8a7ad6b08382b852b"
33+
min_disk_gigabytes := 0
34+
min_ram_megabytes := 0
3335

3436
expectedImage := Image{
3537
Id: "e7db3b45-8db7-47ad-8109-3fb55c2c24fd",
@@ -41,6 +43,9 @@ func TestCreateImage(t *testing.T) {
4143
ContainerFormat: &container_format,
4244
DiskFormat: &disk_format,
4345

46+
MinDiskGigabytes: &min_disk_gigabytes,
47+
MinRamMegabytes: &min_ram_megabytes,
48+
4449
Owner: &owner,
4550

4651
Visibility: ImageVisibilityPrivate,
@@ -144,6 +149,9 @@ func TestUpdateImage(t *testing.T) {
144149

145150
DiskFormat: nil,
146151
ContainerFormat: nil,
152+
153+
Metadata: make(map[string]string),
154+
Properties: make(map[string]string),
147155
}
148156

149157
th.AssertDeepEquals(t, &expectedImage, actualImage)

openstack/imageservice/v2/results.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ func extractImageVisibilityAtKey(m map[string]interface{}, k string) (ImageVisib
213213
}
214214
}
215215

216+
func extractBoolAtKeyOptional(m map[string]interface{}, k string, ifMissing bool) (bool, error) {
217+
if any, ok := m[k]; ok {
218+
return asBool(any)
219+
} else {
220+
return ifMissing, nil
221+
}
222+
}
223+
216224
func extractMapStringStringAtKeyOptional(m map[string]interface{}, k string, ifMissing map[string]string) (map[string]string, error) {
217225
if any, ok := m[k]; ok {
218226
return asMapStringString(any)
@@ -271,7 +279,8 @@ func extractImage(res gophercloud.ErrResult) (*Image, error) {
271279
return nil, err
272280
}
273281

274-
if image.Protected, err = extractBoolAtKey(body, "protected"); err != nil {
282+
// FIXME should this key actually be optional? Is a missing key equivalent to "protected": false ?
283+
if image.Protected, err = extractBoolAtKeyOptional(body, "protected", false); err != nil {
275284
return nil, err
276285
}
277286

0 commit comments

Comments
 (0)