Skip to content

Commit

Permalink
Fix up promote tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
iheanyi committed Sep 16, 2021
1 parent 6bf9128 commit f0cf181
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
24 changes: 22 additions & 2 deletions internal/cmd/branch/promote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,28 @@ func TestBranch_PromoteCmd(t *testing.T) {
db := "planetscale"
branch := "development"

res := &ps.DatabaseBranch{Name: branch}
res := &ps.DatabaseBranch{
Name: branch,
}

svc := &mock.DatabaseBranchesService{
PromoteFn: func(ctx context.Context, req *ps.PromoteBranchRequest) (*ps.DatabaseBranch, error) {
PromoteFn: func(ctx context.Context, req *ps.PromoteRequest) (*ps.BranchPromotionRequest, error) {
c.Assert(req.Branch, qt.Equals, branch)
c.Assert(req.Database, qt.Equals, db)
c.Assert(req.Organization, qt.Equals, org)

return &ps.BranchPromotionRequest{
Branch: branch,
State: "pending",
}, nil
},
GetPromotionRequestFn: func(ctx context.Context, req *ps.GetPromotionRequestRequest) (*ps.BranchPromotionRequest, error) {
return &ps.BranchPromotionRequest{
Branch: branch,
State: "promoted",
}, nil
},
GetFn: func(ctx context.Context, req *ps.GetDatabaseBranchRequest) (*ps.DatabaseBranch, error) {
c.Assert(req.Branch, qt.Equals, branch)
c.Assert(req.Database, qt.Equals, db)
c.Assert(req.Organization, qt.Equals, org)
Expand Down Expand Up @@ -56,5 +74,7 @@ func TestBranch_PromoteCmd(t *testing.T) {

c.Assert(err, qt.IsNil)
c.Assert(svc.PromoteFnInvoked, qt.IsTrue)
c.Assert(svc.GetFnInvoked, qt.IsTrue)
c.Assert(svc.GetPromotionRequestFnInvoked, qt.IsTrue)
c.Assert(buf.String(), qt.JSONEquals, res)
}
12 changes: 10 additions & 2 deletions internal/mock/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ type DatabaseBranchesService struct {
RefreshSchemaFn func(context.Context, *ps.RefreshSchemaRequest) error
RefreshSchemaFnInvoked bool

PromoteFn func(context.Context, *ps.PromoteRequest) (*ps.DatabaseBranch, error)
PromoteFn func(context.Context, *ps.PromoteRequest) (*ps.BranchPromotionRequest, error)
PromoteFnInvoked bool

GetPromotionRequestFn func(context.Context, *ps.GetPromotionRequestRequest) (*ps.BranchPromotionRequest, error)
GetPromotionRequestFnInvoked bool
}

func (d *DatabaseBranchesService) Create(ctx context.Context, req *ps.CreateDatabaseBranchRequest) (*ps.DatabaseBranch, error) {
Expand Down Expand Up @@ -75,7 +78,12 @@ func (d *DatabaseBranchesService) RefreshSchema(ctx context.Context, req *ps.Ref
return d.RefreshSchemaFn(ctx, req)
}

func (d *DatabaseBranchesService) Promote(ctx context.Context, req *ps.PromoteRequest) (*ps.DatabaseBranch, error) {
func (d *DatabaseBranchesService) Promote(ctx context.Context, req *ps.PromoteRequest) (*ps.BranchPromotionRequest, error) {
d.PromoteFnInvoked = true
return d.PromoteFn(ctx, req)
}

func (d *DatabaseBranchesService) GetPromotionRequest(ctx context.Context, req *ps.GetPromotionRequestRequest) (*ps.BranchPromotionRequest, error) {
d.GetPromotionRequestFnInvoked = true
return d.GetPromotionRequestFn(ctx, req)
}

0 comments on commit f0cf181

Please sign in to comment.