Skip to content

Commit b557b91

Browse files
Merge pull request #266 from planetscale/add-with-postgresql-list-option
Add WithPostgreSQL() ListOption for cluster size queries
2 parents 4306fe0 + f21396d commit b557b91

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

planetscale/client.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ func WithRates() ListOption {
116116
}
117117
}
118118

119+
// WithPostgreSQL returns a ListOption that sets the "postgresql" URL parameter.
120+
func WithPostgreSQL() ListOption {
121+
return func(opt *ListOptions) error {
122+
opt.URLValues.Set("postgresql", "true")
123+
return nil
124+
}
125+
}
126+
119127
// WithRegion returns a ListOption sets the "region" URL parameter.
120128
func WithRegion(region string) ListOption {
121129
return func(opt *ListOptions) error {

planetscale/organizations_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,59 @@ func TestOrganizations_ListClusterSKUsWithRates(t *testing.T) {
242242

243243
c.Assert(orgs, qt.DeepEquals, want)
244244
}
245+
246+
func TestOrganizations_ListClusterSKUsWithPostgreSQL(t *testing.T) {
247+
c := qt.New(t)
248+
249+
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
250+
w.WriteHeader(200)
251+
252+
c.Assert(r.URL.String(), qt.Equals, "/v1/organizations/my-cool-org/cluster-size-skus?postgresql=true")
253+
out := `[
254+
{
255+
"name": "PS_10_AWS_ARM",
256+
"type": "ClusterSizeSku",
257+
"display_name": "PS-10-AWS-ARM",
258+
"cpu": "1/8",
259+
"provider_instance_type": null,
260+
"storage": null,
261+
"ram": 1,
262+
"sort_order": 1,
263+
"enabled": true,
264+
"provider": "aws",
265+
"rate": 34,
266+
"replica_rate": null,
267+
"default_vtgate": null,
268+
"default_vtgate_rate": null
269+
}
270+
]`
271+
272+
_, err := w.Write([]byte(out))
273+
c.Assert(err, qt.IsNil)
274+
}))
275+
276+
client, err := NewClient(WithBaseURL(ts.URL))
277+
c.Assert(err, qt.IsNil)
278+
279+
ctx := context.Background()
280+
281+
orgs, err := client.Organizations.ListClusterSKUs(ctx, &ListOrganizationClusterSKUsRequest{
282+
Organization: "my-cool-org",
283+
}, WithPostgreSQL())
284+
285+
c.Assert(err, qt.IsNil)
286+
want := []*ClusterSKU{
287+
{
288+
Name: "PS_10_AWS_ARM",
289+
DisplayName: "PS-10-AWS-ARM",
290+
CPU: "1/8",
291+
Memory: 1,
292+
Enabled: true,
293+
Provider: Pointer("aws"),
294+
Rate: Pointer[int64](34),
295+
SortOrder: 1,
296+
},
297+
}
298+
299+
c.Assert(orgs, qt.DeepEquals, want)
300+
}

0 commit comments

Comments
 (0)