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

Commit 010cf65

Browse files
author
Samuel Ortiz
committed
imageservice: Avoid using pointers for CreateOps fields
Signed-off-by: Samuel Ortiz <[email protected]>
1 parent 05c51dd commit 010cf65

File tree

4 files changed

+28
-24
lines changed

4 files changed

+28
-24
lines changed

acceptance/openstack/imageservice/v2/common.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ func createTestImage(t *testing.T, client *gophercloud.ServiceClient) images.Ima
5353
//creating image
5454
imageName := tools.RandomString("ACCPT", 16)
5555
containerFormat := "ami"
56-
createResult := images.Create(client, images.CreateOpts{Name: &imageName,
57-
ContainerFormat: &containerFormat,
58-
DiskFormat: &containerFormat})
56+
createResult := images.Create(client, images.CreateOpts{Name: imageName,
57+
ContainerFormat: containerFormat,
58+
DiskFormat: containerFormat})
5959
th.AssertNoErr(t, createResult.Err)
6060
image, err := createResult.Extract()
6161
th.AssertNoErr(t, err)
@@ -75,7 +75,7 @@ func createTestImage(t *testing.T, client *gophercloud.ServiceClient) images.Ima
7575
image, err = images.Get(client, image.ID).Extract()
7676
th.AssertNoErr(t, err)
7777
th.AssertEquals(t, image.Status, images.ImageStatusActive)
78-
th.AssertEquals(t, *image.SizeBytes, 9)
78+
th.AssertEquals(t, image.SizeBytes, 9)
7979
return *image
8080
}
8181

openstack/imageservice/v2/images/fixtures.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ func HandleImageCreationSuccessfully(t *testing.T) {
159159
th.TestJSONRequest(t, r, `{
160160
"id": "e7db3b45-8db7-47ad-8109-3fb55c2c24fd",
161161
"name": "Ubuntu 12.10",
162+
"protected": false,
162163
"tags": [
163164
"ubuntu",
164165
"quantal"
@@ -170,6 +171,7 @@ func HandleImageCreationSuccessfully(t *testing.T) {
170171
fmt.Fprintf(w, `{
171172
"status": "queued",
172173
"name": "Ubuntu 12.10",
174+
"protected": false,
173175
"tags": ["ubuntu","quantal"],
174176
"container_format": "bare",
175177
"created_at": "2014-11-11T20:47:55Z",
@@ -200,6 +202,7 @@ func HandleImageCreationSuccessfullyNulls(t *testing.T) {
200202
th.TestJSONRequest(t, r, `{
201203
"id": "e7db3b45-8db7-47ad-8109-3fb55c2c24fd",
202204
"name": "Ubuntu 12.10",
205+
"protected": false,
203206
"tags": [
204207
"ubuntu",
205208
"quantal"
@@ -211,6 +214,7 @@ func HandleImageCreationSuccessfullyNulls(t *testing.T) {
211214
fmt.Fprintf(w, `{
212215
"status": "queued",
213216
"name": "Ubuntu 12.10",
217+
"protected": false,
214218
"tags": ["ubuntu","quantal"],
215219
"container_format": "bare",
216220
"created_at": "2014-11-11T20:47:55Z",

openstack/imageservice/v2/images/requests.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ type CreateOptsBuilder interface {
114114
// CreateOpts implements CreateOptsBuilder
115115
type CreateOpts struct {
116116
// Name [required] is the name of the new image.
117-
Name *string
117+
Name string
118118

119119
// Id [optional] is the the image ID.
120-
ID *string
120+
ID string
121121

122122
// Visibility [optional] defines who can see/use the image.
123123
Visibility *ImageVisibility
@@ -127,23 +127,23 @@ type CreateOpts struct {
127127

128128
// ContainerFormat [optional] is the format of the
129129
// container. Valid values are ami, ari, aki, bare, and ovf.
130-
ContainerFormat *string
130+
ContainerFormat string
131131

132132
// DiskFormat [optional] is the format of the disk. If set,
133133
// valid values are ami, ari, aki, vhd, vmdk, raw, qcow2, vdi,
134134
// and iso.
135-
DiskFormat *string
135+
DiskFormat string
136136

137137
// MinDiskGigabytes [optional] is the amount of disk space in
138138
// GB that is required to boot the image.
139-
MinDiskGigabytes *int
139+
MinDiskGigabytes int
140140

141141
// MinRAMMegabytes [optional] is the amount of RAM in MB that
142142
// is required to boot the image.
143-
MinRAMMegabytes *int
143+
MinRAMMegabytes int
144144

145145
// protected [optional] is whether the image is not deletable.
146-
Protected *bool
146+
Protected bool
147147

148148
// properties [optional] is a set of properties, if any, that
149149
// are associated with the image.
@@ -154,12 +154,12 @@ type CreateOpts struct {
154154
// a CreateOpts.
155155
func (opts CreateOpts) ToImageCreateMap() (map[string]interface{}, error) {
156156
body := map[string]interface{}{}
157-
if opts.Name == nil {
157+
if opts.Name == "" {
158158
return body, fmt.Errorf("'Name' field is requered, but is not set (was: %v)'", opts.Name)
159159
}
160160

161161
body["name"] = opts.Name
162-
if opts.ID != nil {
162+
if opts.ID != "" {
163163
body["id"] = opts.ID
164164
}
165165
if opts.Visibility != nil {
@@ -168,22 +168,22 @@ func (opts CreateOpts) ToImageCreateMap() (map[string]interface{}, error) {
168168
if opts.Tags != nil {
169169
body["tags"] = opts.Tags
170170
}
171-
if opts.ContainerFormat != nil {
171+
if opts.ContainerFormat != "" {
172172
body["container_format"] = opts.ContainerFormat
173173
}
174-
if opts.DiskFormat != nil {
174+
if opts.DiskFormat != "" {
175175
body["disk_format"] = opts.DiskFormat
176176
}
177-
if opts.MinDiskGigabytes != nil {
177+
if opts.MinDiskGigabytes != 0 {
178178
body["min_disk"] = opts.MinDiskGigabytes
179179
}
180-
if opts.MinRAMMegabytes != nil {
180+
if opts.MinRAMMegabytes != 0 {
181181
body["min_ram"] = opts.MinRAMMegabytes
182182

183183
}
184-
if opts.Protected != nil {
185-
body["protected"] = opts.Protected
186-
}
184+
185+
body["protected"] = opts.Protected
186+
187187
if opts.Properties != nil {
188188
body["properties"] = opts.Properties
189189
}

openstack/imageservice/v2/images/requests_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ func TestCreateImage(t *testing.T) {
5656
name := "Ubuntu 12.10"
5757

5858
actualImage, err := Create(fakeclient.ServiceClient(), CreateOpts{
59-
ID: &id,
60-
Name: &name,
59+
ID: id,
60+
Name: name,
6161
Tags: []string{"ubuntu", "quantal"},
6262
}).Extract()
6363

@@ -103,8 +103,8 @@ func TestCreateImageNulls(t *testing.T) {
103103
name := "Ubuntu 12.10"
104104

105105
actualImage, err := Create(fakeclient.ServiceClient(), CreateOpts{
106-
ID: &id,
107-
Name: &name,
106+
ID: id,
107+
Name: name,
108108
Tags: []string{"ubuntu", "quantal"},
109109
}).Extract()
110110

0 commit comments

Comments
 (0)