Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
fix panic when updating org with existing schedule (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmizerany committed Dec 8, 2022
1 parent 55707d2 commit c8f5624
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
22 changes: 11 additions & 11 deletions control/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,17 +310,17 @@ func (c *Client) ScheduleNow(ctx context.Context, org string, info *OrgInfo, pha
if !phases[0].Effective.IsZero() {
return errors.New("first phase must be effective now")
}
}
cps, err := c.LookupPhases(ctx, org)
if err != nil && !errors.Is(err, ErrOrgNotFound) {
return err
}
for _, p := range cps {
if p.Current {
p0 := phases[0]
p.Features = p0.Features
phases[0] = p
break
cps, err := c.LookupPhases(ctx, org)
if err != nil && !errors.Is(err, ErrOrgNotFound) {
return err
}
for _, p := range cps {
if p.Current {
p0 := phases[0]
p.Features = p0.Features
phases[0] = p
break
}
}
}
return c.Schedule(ctx, org, info, phases)
Expand Down
21 changes: 21 additions & 0 deletions control/schedule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,27 @@ func TestSchedule(t *testing.T) {
})
}

func TestScheduleUpdateOrgOnSchedule(t *testing.T) {
info := &OrgInfo{Email: "test@foo.com"}
c := newTestClient(t)
ctx := context.Background()
c.Push(ctx, []Feature{{
FeaturePlan: mpf("feature:x@plan:test@0"),
Interval: "@daily",
Currency: "usd",
}}, pushLogger(t))
err := c.Schedule(ctx, "org:example", info, []Phase{{
Features: []refs.FeaturePlan{mpf("feature:x@plan:test@0")},
}})
if err != nil {
t.Fatalf("got %v, want nil", err)
}
err = c.ScheduleNow(ctx, "org:example", info, nil) // org update only
if err != nil {
t.Fatal(err)
}
}

func TestScheduleMinMaxItems(t *testing.T) {
c := newTestClient(t)
ctx := context.Background()
Expand Down

0 comments on commit c8f5624

Please sign in to comment.