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

Commit 885664e

Browse files
dudymasDSpeichert
authored andcommitted
fix(serializing): corrected mapstructure metadata
1 parent 604f24a commit 885664e

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

openstack/telemetry/v2/meters/fixtures.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package meters
44

55
import (
66
"fmt"
7-
"log"
87
"net/http"
98
"testing"
109

@@ -16,7 +15,7 @@ import (
1615
const MeterListBody = `
1716
[
1817
{
19-
"meter_id": "YmQ5NDMxYzEtOGQ2OS00YWQzLTgwM2EtOGQ0YTZiODlmZDM2K2luc3RhbmNl\n",
18+
"meter_id": "YmQ5NDMxYzEtOGQ2OS00YWQzLTgwM2EtOGQ0YTZiODlmZDM2K2luc3RhbmNl",
2019
"name": "instance",
2120
"project_id": "35b17138-b364-4e6a-a131-8f3099c5be68",
2221
"resource_id": "bd9431c1-8d69-4ad3-803a-8d4a6b89fd36",
@@ -30,10 +29,10 @@ const MeterListBody = `
3029
"name": "cpu_util",
3130
"resource_id": "5b88239b-8ba1-44ff-a154-978cbda23479",
3231
"source": "region2",
33-
"meter_id": "NWI4ODIzOWAtOGJhMS00NGZhLWExNTQtOTc4Y2JkYTIzNDc5K2NwdV91dGls\n",
32+
"meter_id": "NWI4ODIzOWAtOGJhMS00NGZhLWExNTQtOTc4Y2JkYTIzNDc5K2NwdV91dGls",
3433
"project_id": "69e6e7c4ed8b434e92feacbf3d4891fd",
3534
"type": "gauge",
36-
"unit": "%"
35+
"unit": "%%"
3736
}
3837
]
3938
`
@@ -90,7 +89,7 @@ const MeterStatisticsBody = `
9089
"period_start": "2015-07-17T16:43:31",
9190
"avg": 1.5856751105737468,
9291
"groupby": null,
93-
"unit": "%"
92+
"unit": "%%"
9493
}
9594
]
9695
`
@@ -136,7 +135,7 @@ var (
136135
Unit: "GiB",
137136
}
138137

139-
// StatisticsDerp is a MeterStatisticsResult struct that should correspond to the first result in *[]MeterStatisticsResult.
138+
// StatisticsDerp is a MeterStatisticsResult struct that should correspond to the second result in *[]MeterStatisticsResult.
140139
StatisticsDerp = MeterStatisticsResult{
141140
Avg: 1.5856751105737468,
142141
Count: 28162,
@@ -186,6 +185,5 @@ func HandleMeterStatisticsSuccessfully(t *testing.T) {
186185
w.Header().Add("Content-Type", "application/json")
187186
w.WriteHeader(http.StatusOK)
188187
fmt.Fprintf(w, MeterStatisticsBody)
189-
log.Printf("%s\n", MeterStatisticsBody)
190188
})
191189
}

openstack/telemetry/v2/meters/requests.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package meters
22

33
import (
4-
"fmt"
5-
"net/http"
6-
74
"github.com/rackspace/gophercloud"
85
)
96

@@ -90,8 +87,6 @@ func MeterStatistics(client *gophercloud.ServiceClient, n string, opts MeterStat
9087
url += query
9188
}
9289

93-
var b *http.Response
94-
b, res.Err = client.Get(url, &res.Body, &gophercloud.RequestOpts{})
95-
fmt.Printf("%+v\n%+v\n", res, b)
90+
_, res.Err = client.Get(url, &res.Body, &gophercloud.RequestOpts{})
9691
return res
9792
}

openstack/telemetry/v2/meters/results.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import (
88
)
99

1010
type MeterListResult struct {
11-
MeterId string `json:"meter_id"`
11+
MeterId string `mapstructure:"meter_id"`
1212
Name string `json:"name"`
13-
ProjectId string `json:"project_id"`
14-
ResourceId string `json:"resource_id"`
13+
ProjectId string `mapstructure:"project_id"`
14+
ResourceId string `mapstructure:"resource_id"`
1515
Source string `json:"source"`
1616
Type string `json:"type"`
1717
Unit string `json:"user"`
18-
UserId string `json:"user_id"`
18+
UserId string `mapstructure:"user_id"`
1919
}
2020

2121
type listResult struct {
@@ -51,13 +51,13 @@ type MeterStatisticsResult struct {
5151
Avg float32 `json:"avg"`
5252
Count int `json:"count"`
5353
Duration float32 `json:"duration"`
54-
DurationEnd string `json:"duration_end"`
55-
DurationStart string `json:"duration_start"`
54+
DurationEnd string `mapstructure:"duration_end"`
55+
DurationStart string `mapstructure:"duration_start"`
5656
Max float32 `json:"max"`
5757
Min float32 `json:"min"`
5858
Period int `json:"user_id"`
59-
PeriodEnd string `json:"period_end"`
60-
PeriodStart string `json:"period_start"`
59+
PeriodEnd string `mapstructure:"period_end"`
60+
PeriodStart string `mapstructure:"period_start"`
6161
Sum float32 `json:"sum"`
6262
Unit string `json:"unit"`
6363
}

0 commit comments

Comments
 (0)