Skip to content

Commit f923894

Browse files
committed
fix(orgs): droppped typed plans
1 parent d880ac0 commit f923894

File tree

3 files changed

+11
-135
lines changed

3 files changed

+11
-135
lines changed

axiom/orgs.go

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -12,61 +12,7 @@ import (
1212
"go.opentelemetry.io/otel/trace"
1313
)
1414

15-
//go:generate go run golang.org/x/tools/cmd/stringer -type=Plan,PaymentStatus -linecomment -output=orgs_string.go
16-
17-
// Plan represents the plan of an [Organization].
18-
type Plan uint8
19-
20-
// All available [Organization] [Plan]s.
21-
const (
22-
emptyPlan Plan = iota //
23-
24-
Personal // personal
25-
Basic // basic
26-
Team // teamMonthly
27-
Enterprise // enterprise
28-
Comped // comped
29-
)
30-
31-
func planFromString(s string) (plan Plan, err error) {
32-
switch s {
33-
case emptyPlan.String():
34-
plan = emptyPlan
35-
case Personal.String():
36-
plan = Personal
37-
case Basic.String():
38-
plan = Basic
39-
case Team.String():
40-
plan = Team
41-
case Enterprise.String():
42-
plan = Enterprise
43-
case Comped.String():
44-
plan = Comped
45-
default:
46-
err = fmt.Errorf("unknown plan %q", s)
47-
}
48-
49-
return plan, err
50-
}
51-
52-
// MarshalJSON implements [json.Marshaler]. It is in place to marshal the plan
53-
// to its string representation because that's what the server expects.
54-
func (p Plan) MarshalJSON() ([]byte, error) {
55-
return json.Marshal(p.String())
56-
}
57-
58-
// UnmarshalJSON implements [json.Unmarshaler]. It is in place to unmarshal the
59-
// plan from the string representation the server returns.
60-
func (p *Plan) UnmarshalJSON(b []byte) (err error) {
61-
var s string
62-
if err = json.Unmarshal(b, &s); err != nil {
63-
return err
64-
}
65-
66-
*p, err = planFromString(s)
67-
68-
return err
69-
}
15+
//go:generate go run golang.org/x/tools/cmd/stringer -type=PaymentStatus -linecomment -output=orgs_string.go
7016

7117
// PaymentStatus represents the payment status of an [Organization].
7218
type PaymentStatus uint8
@@ -135,7 +81,7 @@ type License struct {
13581
// ExpiresAt is the time the license expires.
13682
ExpiresAt time.Time `json:"expiresAt"`
13783
// Plan associated with the license.
138-
Plan Plan `json:"tier"`
84+
Plan string `json:"tier"`
13985
// MonthlyIngestGB is the monthly amount of data in gigabytes that can be
14086
// ingested as part of the license.
14187
MonthlyIngestGB uint64 `json:"monthlyIngestGb"`
@@ -199,7 +145,7 @@ type Organization struct {
199145
// Trial describes if the plan is trialed or not.
200146
Trial bool `json:"inTrial"`
201147
// Plan the organization is on.
202-
Plan Plan `json:"plan"`
148+
Plan string `json:"plan"`
203149
// PlanCreated is the time the plan was created.
204150
PlanCreated time.Time `json:"planCreated"`
205151
// LastUsageSync is the last time the usage instance usage statistics were

axiom/orgs_string.go

Lines changed: 1 addition & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

axiom/orgs_test.go

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestOrganizationsService_List(t *testing.T) {
2020
ID: "axiom",
2121
Name: "Axiom Industries Ltd",
2222
Slug: "",
23-
Plan: Basic,
23+
Plan: "enterprise",
2424
PlanCreated: testhelper.MustTimeParse(t, time.RFC3339, "1970-01-01T00:00:00Z"),
2525
Trial: false,
2626
LastUsageSync: testhelper.MustTimeParse(t, time.RFC3339, "0001-01-01T00:00:00Z"),
@@ -33,7 +33,7 @@ func TestOrganizationsService_List(t *testing.T) {
3333
IssuedAt: testhelper.MustTimeParse(t, time.RFC3339, "2021-01-19T17:55:53Z"),
3434
ValidFrom: testhelper.MustTimeParse(t, time.RFC3339, "2021-01-19T17:55:53Z"),
3535
ExpiresAt: testhelper.MustTimeParse(t, time.RFC3339, "2022-01-19T17:55:53Z"),
36-
Plan: Enterprise,
36+
Plan: "enterprise",
3737
MonthlyIngestGB: 100,
3838
MaxUsers: 50,
3939
MaxTeams: 10,
@@ -63,7 +63,7 @@ func TestOrganizationsService_List(t *testing.T) {
6363
"name": "Axiom Industries Ltd",
6464
"slug": "",
6565
"inTrial": false,
66-
"plan": "basic",
66+
"plan": "enterprise",
6767
"planCreated": "1970-01-01T00:00:00Z",
6868
"lastUsageSync": "0001-01-01T00:00:00Z",
6969
"role": "admin",
@@ -111,7 +111,7 @@ func TestOrganizationsService_Get(t *testing.T) {
111111
ID: "axiom",
112112
Name: "Axiom Industries Ltd",
113113
Slug: "",
114-
Plan: Basic,
114+
Plan: "enterprise",
115115
PlanCreated: testhelper.MustTimeParse(t, time.RFC3339, "1970-01-01T00:00:00Z"),
116116
Trial: false,
117117
LastUsageSync: testhelper.MustTimeParse(t, time.RFC3339, "0001-01-01T00:00:00Z"),
@@ -124,7 +124,7 @@ func TestOrganizationsService_Get(t *testing.T) {
124124
IssuedAt: testhelper.MustTimeParse(t, time.RFC3339, "2021-01-19T17:55:53Z"),
125125
ValidFrom: testhelper.MustTimeParse(t, time.RFC3339, "2021-01-19T17:55:53Z"),
126126
ExpiresAt: testhelper.MustTimeParse(t, time.RFC3339, "2022-01-19T17:55:53Z"),
127-
Plan: Enterprise,
127+
Plan: "enterprise",
128128
MonthlyIngestGB: 100,
129129
MaxUsers: 50,
130130
MaxTeams: 10,
@@ -152,7 +152,7 @@ func TestOrganizationsService_Get(t *testing.T) {
152152
"name": "Axiom Industries Ltd",
153153
"slug": "",
154154
"inTrial": false,
155-
"plan": "basic",
155+
"plan": "enterprise",
156156
"planCreated": "1970-01-01T00:00:00Z",
157157
"lastUsageSync": "0001-01-01T00:00:00Z",
158158
"role": "admin",
@@ -194,54 +194,6 @@ func TestOrganizationsService_Get(t *testing.T) {
194194
assert.Equal(t, exp, res)
195195
}
196196

197-
func TestPlan_Marshal(t *testing.T) {
198-
exp := `{
199-
"plan": "personal"
200-
}`
201-
202-
b, err := json.Marshal(struct {
203-
Plan Plan `json:"plan"`
204-
}{
205-
Plan: Personal,
206-
})
207-
require.NoError(t, err)
208-
require.NotEmpty(t, b)
209-
210-
assert.JSONEq(t, exp, string(b))
211-
}
212-
213-
func TestPlan_Unmarshal(t *testing.T) {
214-
var act struct {
215-
Plan Plan `json:"plan"`
216-
}
217-
err := json.Unmarshal([]byte(`{ "plan": "personal" }`), &act)
218-
require.NoError(t, err)
219-
220-
assert.Equal(t, Personal, act.Plan)
221-
}
222-
223-
func TestPlan_String(t *testing.T) {
224-
// Check outer bounds.
225-
assert.Empty(t, Plan(0).String())
226-
assert.Empty(t, emptyPlan.String())
227-
assert.Equal(t, emptyPlan, Plan(0))
228-
assert.Contains(t, (Comped + 1).String(), "Plan(")
229-
230-
for p := Personal; p <= Comped; p++ {
231-
s := p.String()
232-
assert.NotEmpty(t, s)
233-
assert.NotContains(t, s, "Plan(")
234-
}
235-
}
236-
237-
func TestPlanFromString(t *testing.T) {
238-
for p := Personal; p <= Comped; p++ {
239-
parsed, err := planFromString(p.String())
240-
assert.NoError(t, err)
241-
assert.Equal(t, p, parsed)
242-
}
243-
}
244-
245197
func TestPaymentStatus_Marshal(t *testing.T) {
246198
exp := `{
247199
"paymentStatus": "success"
@@ -293,7 +245,7 @@ func TestPaymentStatusFromString(t *testing.T) {
293245
func TestLicense(t *testing.T) {
294246
exp := License{
295247
ID: "98baf1f7-0b51-403f-abc1-2ee91972a225",
296-
Plan: Personal,
248+
Plan: "personal",
297249
MaxUsers: 50,
298250
MaxTeams: 10,
299251
MaxDatasets: 25,

0 commit comments

Comments
 (0)