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

Commit 916da9a

Browse files
author
Samuel Ortiz
committed
imageservice: Avoid using pointers for the Image fields
Signed-off-by: Samuel Ortiz <[email protected]>
1 parent ab0ffaf commit 916da9a

File tree

2 files changed

+47
-47
lines changed

2 files changed

+47
-47
lines changed

openstack/imageservice/v2/images/requests_test.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestListImage(t *testing.T) {
3333
}
3434

3535
for _, i := range images {
36-
t.Logf("%s\t%s\t%s\t%s\t%v\t\n", i.ID, i.Name, *(i.Owner), *(i.Checksum), i.SizeBytes)
36+
t.Logf("%s\t%s\t%s\t%s\t%v\t\n", i.ID, i.Name, i.Owner, i.Checksum, i.SizeBytes)
3737
count++
3838
}
3939

@@ -76,13 +76,13 @@ func TestCreateImage(t *testing.T) {
7676

7777
Status: ImageStatusQueued,
7878

79-
ContainerFormat: &containerFormat,
80-
DiskFormat: &diskFormat,
79+
ContainerFormat: containerFormat,
80+
DiskFormat: diskFormat,
8181

82-
MinDiskGigabytes: &minDiskGigabytes,
83-
MinRAMMegabytes: &minRAMMegabytes,
82+
MinDiskGigabytes: minDiskGigabytes,
83+
MinRAMMegabytes: minRAMMegabytes,
8484

85-
Owner: &owner,
85+
Owner: owner,
8686

8787
Visibility: ImageVisibilityPrivate,
8888

@@ -123,13 +123,13 @@ func TestCreateImageNulls(t *testing.T) {
123123

124124
Status: ImageStatusQueued,
125125

126-
ContainerFormat: &containerFormat,
127-
DiskFormat: &diskFormat,
126+
ContainerFormat: containerFormat,
127+
DiskFormat: diskFormat,
128128

129-
MinDiskGigabytes: &minDiskGigabytes,
130-
MinRAMMegabytes: &minRAMMegabytes,
129+
MinDiskGigabytes: minDiskGigabytes,
130+
MinRAMMegabytes: minRAMMegabytes,
131131

132-
Owner: &owner,
132+
Owner: owner,
133133

134134
Visibility: ImageVisibilityPrivate,
135135

@@ -165,19 +165,19 @@ func TestGetImage(t *testing.T) {
165165

166166
Status: ImageStatusActive,
167167

168-
ContainerFormat: &containerFormat,
169-
DiskFormat: &diskFormat,
168+
ContainerFormat: containerFormat,
169+
DiskFormat: diskFormat,
170170

171-
MinDiskGigabytes: &minDiskGigabytes,
172-
MinRAMMegabytes: &minRAMMegabytes,
171+
MinDiskGigabytes: minDiskGigabytes,
172+
MinRAMMegabytes: minRAMMegabytes,
173173

174-
Owner: &owner,
174+
Owner: owner,
175175

176176
Protected: false,
177177
Visibility: ImageVisibilityPublic,
178178

179-
Checksum: &checksum,
180-
SizeBytes: &sizeBytes,
179+
Checksum: checksum,
180+
SizeBytes: sizeBytes,
181181

182182
Metadata: make(map[string]string),
183183
Properties: make(map[string]string),
@@ -218,20 +218,20 @@ func TestUpdateImage(t *testing.T) {
218218
Status: ImageStatusActive,
219219
Visibility: ImageVisibilityPublic,
220220

221-
SizeBytes: &sizebytes,
222-
Checksum: &checksum,
221+
SizeBytes: sizebytes,
222+
Checksum: checksum,
223223

224224
Tags: []string{
225225
"fedora",
226226
"beefy",
227227
},
228228

229-
Owner: nil,
230-
MinRAMMegabytes: nil,
231-
MinDiskGigabytes: nil,
229+
Owner: "",
230+
MinRAMMegabytes: 0,
231+
MinDiskGigabytes: 0,
232232

233-
DiskFormat: nil,
234-
ContainerFormat: nil,
233+
DiskFormat: "",
234+
ContainerFormat: "",
235235

236236
Metadata: make(map[string]string),
237237
Properties: make(map[string]string),

openstack/imageservice/v2/images/results.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ type Image struct {
2222

2323
Tags []string
2424

25-
ContainerFormat *string
26-
DiskFormat *string
25+
ContainerFormat string
26+
DiskFormat string
2727

28-
MinDiskGigabytes *int
29-
MinRAMMegabytes *int
28+
MinDiskGigabytes int
29+
MinRAMMegabytes int
3030

31-
Owner *string
31+
Owner string
3232

3333
Protected bool
3434
Visibility ImageVisibility
3535

36-
Checksum *string
37-
SizeBytes *int
36+
Checksum string
37+
SizeBytes int
3838

3939
Metadata map[string]string
4040
Properties map[string]string
@@ -68,37 +68,37 @@ func asString(any interface{}, key string) (string, error) {
6868
return "", fmt.Errorf("expected string value for key '%s', but found: %#v", key, any)
6969
}
7070

71-
func asNoneableString(any interface{}, key string) (*string, error) {
71+
func asNoneableString(any interface{}, key string) (string, error) {
7272
// JSON null values could be also returned according to behaviour https://bugs.launchpad.net/glance/+bug/1481512
7373
if any == nil {
74-
return nil, nil
74+
return "", nil
7575
}
7676
if str, ok := any.(string); ok {
7777
if str == "None" || &str == nil {
78-
return nil, nil
78+
return "", nil
7979
}
80-
return &str, nil
80+
return str, nil
8181
}
82-
return nil, fmt.Errorf("expected string value for key '%s', but found: %#v", key, any)
82+
return "", fmt.Errorf("expected string value for key '%s', but found: %#v", key, any)
8383
}
8484

85-
func asNoneableInteger(any interface{}, key string) (*int, error) {
85+
func asNoneableInteger(any interface{}, key string) (int, error) {
8686
// FIXME problem here is that provider_client.go uses: json.NewDecoder(resp.Body).Decode(options.JSONResponse)
8787
// which apparently converts integers in JSON to float64 values
8888
// JSON null values could be also returned according to behaviour https://bugs.launchpad.net/glance/+bug/1481512
8989
if any == nil {
90-
return nil, nil
90+
return 0, nil
9191
}
9292
if f, ok := any.(float64); ok {
9393
i := int(f)
94-
return &i, nil
94+
return i, nil
9595
} else if s, ok := any.(string); ok {
9696
if s == "None" {
97-
return nil, nil
97+
return 0, nil
9898
}
99-
return nil, fmt.Errorf("expected \"None\" or integer value for key '%s', but found unexpected string: \"%s\"", key, s)
99+
return 0, fmt.Errorf("expected \"None\" or integer value for key '%s', but found unexpected string: \"%s\"", key, s)
100100
}
101-
return nil, fmt.Errorf("expected \"None\" or integer value for key '%s', but found: %T(%#v)", key, any, any)
101+
return 0, fmt.Errorf("expected \"None\" or integer value for key '%s', but found: %T(%#v)", key, any, any)
102102
}
103103

104104
func asMapStringString(any interface{}) (map[string]string, error) {
@@ -129,18 +129,18 @@ func extractStringAtKey(m map[string]interface{}, k string) (string, error) {
129129
return "", fmt.Errorf("expected key \"%s\" in map, but this key is not present", k)
130130
}
131131

132-
func extractNoneableStringAtKey(m map[string]interface{}, k string) (*string, error) {
132+
func extractNoneableStringAtKey(m map[string]interface{}, k string) (string, error) {
133133
if any, ok := m[k]; ok {
134134
return asNoneableString(any, k)
135135
}
136-
return nil, fmt.Errorf("expected key \"%s\" in map, but this key is not present", k)
136+
return "", fmt.Errorf("expected key \"%s\" in map, but this key is not present", k)
137137
}
138138

139-
func extractNoneableIntegerAtKey(m map[string]interface{}, k string) (*int, error) {
139+
func extractNoneableIntegerAtKey(m map[string]interface{}, k string) (int, error) {
140140
if any, ok := m[k]; ok {
141141
return asNoneableInteger(any, k)
142142
}
143-
return nil, fmt.Errorf("expected key \"%s\" in map, but this key is not present", k)
143+
return 0, fmt.Errorf("expected key \"%s\" in map, but this key is not present", k)
144144
}
145145

146146
func extractStringSliceAtKey(m map[string]interface{}, key string) ([]string, error) {

0 commit comments

Comments
 (0)