Skip to content

Commit

Permalink
sizes: Add description field. (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsomething authored Jan 21, 2021
1 parent dc72781 commit f07b337
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
1 change: 1 addition & 0 deletions sizes.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Size struct {
Regions []string `json:"regions,omitempty"`
Available bool `json:"available,omitempty"`
Transfer float64 `json:"transfer,omitempty"`
Description string `json:"description,omitempty"`
}

func (s Size) String() string {
Expand Down
59 changes: 55 additions & 4 deletions sizes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,66 @@ func TestSizes_List(t *testing.T) {
setup()
defer teardown()

expectedSizes := []Size{
{
Slug: "s-1vcpu-1gb",
Memory: 1024,
Vcpus: 1,
Disk: 25,
PriceMonthly: 5,
PriceHourly: 0.00744,
Regions: []string{"nyc1", "nyc2"},
Available: true,
Transfer: 1,
Description: "Basic",
},
{
Slug: "512mb",
Memory: 512,
Vcpus: 1,
Disk: 20,
PriceMonthly: 5,
PriceHourly: 0.00744,
Regions: []string{"nyc1", "nyc2"},
Available: true,
Transfer: 1,
Description: "Legacy Basic",
},
}

mux.HandleFunc("/v2/sizes", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{
"sizes": [
{
"slug": "1"
"slug": "s-1vcpu-1gb",
"memory": 1024,
"vcpus": 1,
"disk": 25,
"transfer": 1,
"price_monthly": 5,
"price_hourly": 0.00744,
"regions": [
"nyc1",
"nyc2"
],
"available": true,
"description": "Basic"
},
{
"slug": "2"
"slug": "512mb",
"memory": 512,
"vcpus": 1,
"disk": 20,
"transfer": 1,
"price_monthly": 5,
"price_hourly": 0.00744,
"regions": [
"nyc1",
"nyc2"
],
"available": true,
"description": "Legacy Basic"
}
],
"meta": {
Expand All @@ -33,7 +84,6 @@ func TestSizes_List(t *testing.T) {
t.Errorf("Sizes.List returned error: %v", err)
}

expectedSizes := []Size{{Slug: "1"}, {Slug: "2"}}
if !reflect.DeepEqual(sizes, expectedSizes) {
t.Errorf("Sizes.List returned sizes %+v, expected %+v", sizes, expectedSizes)
}
Expand Down Expand Up @@ -103,10 +153,11 @@ func TestSize_String(t *testing.T) {
Regions: []string{"1", "2"},
Available: true,
Transfer: 789,
Description: "Basic",
}

stringified := size.String()
expected := `godo.Size{Slug:"slize", Memory:123, Vcpus:456, Disk:789, PriceMonthly:123, PriceHourly:456, Regions:["1" "2"], Available:true, Transfer:789}`
expected := `godo.Size{Slug:"slize", Memory:123, Vcpus:456, Disk:789, PriceMonthly:123, PriceHourly:456, Regions:["1" "2"], Available:true, Transfer:789, Description:"Basic"}`
if expected != stringified {
t.Errorf("Size.String returned %+v, expected %+v", stringified, expected)
}
Expand Down

0 comments on commit f07b337

Please sign in to comment.