Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Phani Raj committed Aug 13, 2021
1 parent 5875424 commit 33ee312
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
10 changes: 5 additions & 5 deletions internal/cmd/passwords/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ func TestPassword_CreateCmd(t *testing.T) {
org := "planetscale"
db := "planetscale"
branch := "development"

res := &ps.Password{Name: "foo"}
name := "production-password"
res := &ps.DatabaseBranchPassword{Name: "foo"}

svc := &mock.PasswordsService{
CreateFn: func(ctx context.Context, req *ps.CreatePasswordRequest) (*ps.Password, error) {
CreateFn: func(ctx context.Context, req *ps.DatabaseBranchPasswordRequest) (*ps.DatabaseBranchPassword, error) {
c.Assert(req.Organization, qt.Equals, org)
c.Assert(req.Database, qt.Equals, db)
c.Assert(req.Branch, qt.Equals, branch)
c.Assert(req.DisplayName, qt.Equals, name)

return res, nil
},
Expand All @@ -52,10 +53,9 @@ func TestPassword_CreateCmd(t *testing.T) {
}

cmd := CreateCmd(ch)
cmd.SetArgs([]string{db, branch})
cmd.SetArgs([]string{db, branch, name})
err := cmd.Execute()

c.Assert(err, qt.IsNil)
c.Assert(svc.CreateFnInvoked, qt.IsTrue)
c.Assert(buf.String(), qt.JSONEquals, res)
}
4 changes: 2 additions & 2 deletions internal/cmd/passwords/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ func TestPassword_DeleteCmd(t *testing.T) {
password := "mypassword"

svc := &mock.PasswordsService{
DeleteFn: func(ctx context.Context, req *ps.DeletePasswordRequest) error {
DeleteFn: func(ctx context.Context, req *ps.DeleteDatabaseBranchPasswordRequest) error {
c.Assert(req.Organization, qt.Equals, org)
c.Assert(req.Database, qt.Equals, db)
c.Assert(req.Branch, qt.Equals, branch)
c.Assert(req.Password, qt.Equals, password)
c.Assert(req.PasswordId, qt.Equals, password)

return nil
},
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/passwords/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ func TestPassword_ListCmd(t *testing.T) {
db := "planetscale"
branch := "development"

resp := []*ps.Password{
resp := []*ps.DatabaseBranchPassword{
{Name: "foo"},
{Name: "bar"},
}

svc := &mock.PasswordsService{
ListFn: func(ctx context.Context, req *ps.ListPasswordsRequest) ([]*ps.Password, error) {
ListFn: func(ctx context.Context, req *ps.ListDatabaseBranchPasswordRequest) ([]*ps.DatabaseBranchPassword, error) {
c.Assert(req.Organization, qt.Equals, org)
c.Assert(req.Database, qt.Equals, db)
c.Assert(req.Branch, qt.Equals, branch)
Expand Down
38 changes: 38 additions & 0 deletions internal/mock/password.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package mock

import (
"context"

ps "github.com/planetscale/planetscale-go/planetscale"
)

type PasswordsService struct {
CreateFn func(context.Context, *ps.DatabaseBranchPasswordRequest) (*ps.DatabaseBranchPassword, error)
CreateFnInvoked bool
ListFn func(context.Context, *ps.ListDatabaseBranchPasswordRequest) ([]*ps.DatabaseBranchPassword, error)
ListFnInvoked bool
GetFn func(context.Context, *ps.GetDatabaseBranchPasswordRequest) (*ps.DatabaseBranchPassword, error)
GetFnInvoked bool
DeleteFn func(context.Context, *ps.DeleteDatabaseBranchPasswordRequest) error
DeleteFnInvoked bool
}

func (b *PasswordsService) Create(ctx context.Context, req *ps.DatabaseBranchPasswordRequest) (*ps.DatabaseBranchPassword, error) {
b.CreateFnInvoked = true
return b.CreateFn(ctx, req)
}

func (b *PasswordsService) List(ctx context.Context, req *ps.ListDatabaseBranchPasswordRequest) ([]*ps.DatabaseBranchPassword, error) {
b.ListFnInvoked = true
return b.ListFn(ctx, req)
}

func (b *PasswordsService) Get(ctx context.Context, req *ps.GetDatabaseBranchPasswordRequest) (*ps.DatabaseBranchPassword, error) {
b.GetFnInvoked = true
return b.GetFn(ctx, req)
}

func (b *PasswordsService) Delete(ctx context.Context, req *ps.DeleteDatabaseBranchPasswordRequest) error {
b.DeleteFnInvoked = true
return b.DeleteFn(ctx, req)
}
1 change: 0 additions & 1 deletion internal/proxyutil/remotesource.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func (r *RemoteCertSource) Cert(ctx context.Context, org, db, branch string) (*p
return &proxy.Cert{
ClientCert: cert.ClientCert,
CACerts: cert.CACerts,
RemoteAddr: cert.RemoteAddr,
Ports: proxy.RemotePorts{
Proxy: cert.Ports.Proxy,
MySQL: cert.Ports.MySQL,
Expand Down

0 comments on commit 33ee312

Please sign in to comment.