Skip to content

Commit

Permalink
latest interface changes
Browse files Browse the repository at this point in the history
  • Loading branch information
janelletavares committed Nov 5, 2021
1 parent ee83401 commit 2ddc6b1
Show file tree
Hide file tree
Showing 26 changed files with 109 additions and 189 deletions.
6 changes: 3 additions & 3 deletions cmd/meroxa/root/connectors/connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ func TestConnectExecution(t *testing.T) {
// Create source
client.
EXPECT().
GetResourceByName(
GetResourceByNameOrID(
ctx,
rSource.Name,
).AnyTimes().
).
Return(&rSource, nil)

client.
Expand All @@ -120,7 +120,7 @@ func TestConnectExecution(t *testing.T) {
// Create destination
client.
EXPECT().
GetResourceByName(
GetResourceByNameOrID(
ctx,
rDestination.Name,
).
Expand Down
4 changes: 2 additions & 2 deletions cmd/meroxa/root/connectors/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var (
)

type createConnectorClient interface {
GetResourceByName(ctx context.Context, name string) (*meroxa.Resource, error)
GetResourceByNameOrID(ctx context.Context, nameOrID string) (*meroxa.Resource, error)
CreateConnector(ctx context.Context, input *meroxa.CreateConnectorInput) (*meroxa.Connector, error)
}

Expand Down Expand Up @@ -111,7 +111,7 @@ func (c *Create) CreateConnector(ctx context.Context) (*meroxa.Connector, error)
return nil, errors.New("requires either a source (--from) or a destination (--to)")
}

res, err := c.client.GetResourceByName(ctx, resourceName)
res, err := c.client.GetResourceByNameOrID(ctx, resourceName)
if err != nil {
return nil, fmt.Errorf("can't fetch resource with name %q: %w", resourceName, err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/meroxa/root/connectors/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func TestCreateConnectorExecution(t *testing.T) {

client.
EXPECT().
GetResourceByName(
GetResourceByNameOrID(
ctx,
sourceName,
).
Expand Down
8 changes: 4 additions & 4 deletions cmd/meroxa/root/connectors/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ var (
)

type describeConnectorClient interface {
GetConnectorByName(ctx context.Context, name string) (*meroxa.Connector, error)
GetConnectorByNameOrID(ctx context.Context, nameOrID string) (*meroxa.Connector, error)
}

type Describe struct {
client describeConnectorClient
logger log.Logger

args struct {
Name string
NameOrID string
}
}

Expand All @@ -59,7 +59,7 @@ func (d *Describe) Docs() builder.Docs {
}

func (d *Describe) Execute(ctx context.Context) error {
connector, err := d.client.GetConnectorByName(ctx, d.args.Name)
connector, err := d.client.GetConnectorByNameOrID(ctx, d.args.NameOrID)
if err != nil {
return err
}
Expand All @@ -83,6 +83,6 @@ func (d *Describe) ParseArgs(args []string) error {
return errors.New("requires connector name")
}

d.args.Name = args[0]
d.args.NameOrID = args[0]
return nil
}
8 changes: 4 additions & 4 deletions cmd/meroxa/root/connectors/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func TestDescribeConnectorArgs(t *testing.T) {
t.Fatalf("expected \"%s\" got \"%s\"", tt.err, err)
}

if tt.name != ar.args.Name {
t.Fatalf("expected \"%s\" got \"%s\"", tt.name, ar.args.Name)
if tt.name != ar.args.NameOrID {
t.Fatalf("expected \"%s\" got \"%s\"", tt.name, ar.args.NameOrID)
}
}
}
Expand All @@ -69,7 +69,7 @@ func TestDescribeConnectorExecution(t *testing.T) {
c.Trace = "exception goes here"
client.
EXPECT().
GetConnectorByName(
GetConnectorByNameOrID(
ctx,
c.Name,
).
Expand All @@ -79,7 +79,7 @@ func TestDescribeConnectorExecution(t *testing.T) {
client: client,
logger: logger,
}
dc.args.Name = c.Name
dc.args.NameOrID = c.Name

err := dc.Execute(ctx)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions cmd/meroxa/root/connectors/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ var (
)

type logsConnectorClient interface {
GetConnectorLogs(ctx context.Context, connectorName string) (*http.Response, error)
GetConnectorLogs(ctx context.Context, nameOrID string) (*http.Response, error)
}

type Logs struct {
client logsConnectorClient
logger log.Logger

args struct {
Name string
NameOrID string
}
}

Expand All @@ -60,7 +60,7 @@ func (l *Logs) Docs() builder.Docs {
}

func (l *Logs) Execute(ctx context.Context) error {
resp, err := l.client.GetConnectorLogs(ctx, l.args.Name)
resp, err := l.client.GetConnectorLogs(ctx, l.args.NameOrID)

if err != nil {
return err
Expand Down Expand Up @@ -92,6 +92,6 @@ func (l *Logs) ParseArgs(args []string) error {
return errors.New("requires connector name")
}

l.args.Name = args[0]
l.args.NameOrID = args[0]
return nil
}
6 changes: 3 additions & 3 deletions cmd/meroxa/root/connectors/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func TestLogsConnectorArgs(t *testing.T) {
t.Fatalf("expected \"%s\" got \"%s\"", tt.err, err)
}

if tt.name != cc.args.Name {
t.Fatalf("expected \"%s\" got \"%s\"", tt.name, cc.args.Name)
if tt.name != cc.args.NameOrID {
t.Fatalf("expected \"%s\" got \"%s\"", tt.name, cc.args.NameOrID)
}
}
}
Expand All @@ -67,7 +67,7 @@ func TestLogsConnectorExecution(t *testing.T) {
logger: logger,
}

c.args.Name = connectorName
c.args.NameOrID = connectorName

var responseDetails = io.NopCloser(bytes.NewReader([]byte(
`[2021-04-29T12:16:42Z] Just another log line from my connector`,
Expand Down
4 changes: 2 additions & 2 deletions cmd/meroxa/root/connectors/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

type removeConnectorClient interface {
GetConnectorByName(ctx context.Context, name string) (*meroxa.Connector, error)
GetConnectorByNameOrID(ctx context.Context, nameOrID string) (*meroxa.Connector, error)
DeleteConnector(ctx context.Context, nameOrID string) error
}

Expand Down Expand Up @@ -58,7 +58,7 @@ func (r *Remove) ValueToConfirm(_ context.Context) (wantInput string) {
func (r *Remove) Execute(ctx context.Context) error {
r.logger.Infof(ctx, "Removing connector %q...", r.args.Name)

con, err := r.client.GetConnectorByName(ctx, r.args.Name)
con, err := r.client.GetConnectorByNameOrID(ctx, r.args.Name)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/meroxa/root/connectors/remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestRemoveConnectorExecution(t *testing.T) {

client.
EXPECT().
GetConnectorByName(ctx, c.Name).
GetConnectorByNameOrID(ctx, c.Name).
Return(&c, nil)

client.
Expand Down
12 changes: 6 additions & 6 deletions cmd/meroxa/root/connectors/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Update struct {
logger log.Logger

args struct {
Name string
NameOrID string
}

flags struct {
Expand Down Expand Up @@ -70,12 +70,12 @@ func (u *Update) Execute(ctx context.Context) error {
return errors.New("requires either --config, --name or --state")
}

u.logger.Infof(ctx, "Updating connector %q...", u.args.Name)
u.logger.Infof(ctx, "Updating connector %q...", u.args.NameOrID)
var con *meroxa.Connector
var err error

if u.flags.State != "" {
con, err = u.client.UpdateConnectorStatus(ctx, u.args.Name, meroxa.Action(u.flags.State))
con, err = u.client.UpdateConnectorStatus(ctx, u.args.NameOrID, meroxa.Action(u.flags.State))
if err != nil {
return err
}
Expand All @@ -101,13 +101,13 @@ func (u *Update) Execute(ctx context.Context) error {
cu.Configuration = config
}

con, err = u.client.UpdateConnector(ctx, u.args.Name, cu)
con, err = u.client.UpdateConnector(ctx, u.args.NameOrID, cu)
if err != nil {
return err
}
}

u.logger.Infof(ctx, "Connector %q successfully updated!", u.args.Name)
u.logger.Infof(ctx, "Connector %q successfully updated!", u.args.NameOrID)
u.logger.JSON(ctx, con)
return nil
}
Expand All @@ -129,7 +129,7 @@ func (u *Update) ParseArgs(args []string) error {
return errors.New("requires connector name")
}

u.args.Name = args[0]
u.args.NameOrID = args[0]
return nil
}

Expand Down
22 changes: 11 additions & 11 deletions cmd/meroxa/root/connectors/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func TestUpdateConnectorArgs(t *testing.T) {
t.Fatalf("expected \"%s\" got \"%s\"", tt.err, err)
}

if tt.name != cc.args.Name {
t.Fatalf("expected \"%s\" got \"%s\"", tt.name, cc.args.Name)
if tt.name != cc.args.NameOrID {
t.Fatalf("expected \"%s\" got \"%s\"", tt.name, cc.args.NameOrID)
}
}
}
Expand Down Expand Up @@ -120,12 +120,12 @@ func TestUpdateConnectorExecutionWithNewState(t *testing.T) {
}

c := utils.GenerateConnector(0, "")
u.args.Name = c.Name
u.args.NameOrID = c.Name
u.flags.State = "pause"

client.
EXPECT().
UpdateConnectorStatus(ctx, u.args.Name, meroxa.Action(u.flags.State)).
UpdateConnectorStatus(ctx, u.args.NameOrID, meroxa.Action(u.flags.State)).
Return(&c, nil)

err := u.Execute(ctx)
Expand All @@ -137,7 +137,7 @@ func TestUpdateConnectorExecutionWithNewState(t *testing.T) {
gotLeveledOutput := logger.LeveledOutput()
wantLeveledOutput := fmt.Sprintf(`Updating connector %q...
Connector %q successfully updated!
`, u.args.Name, u.args.Name)
`, u.args.NameOrID, u.args.NameOrID)

if gotLeveledOutput != wantLeveledOutput {
t.Fatalf("expected output:\n%s\ngot:\n%s", wantLeveledOutput, gotLeveledOutput)
Expand Down Expand Up @@ -167,7 +167,7 @@ func TestUpdateConnectorExecutionWithNewName(t *testing.T) {
}

c := utils.GenerateConnector(0, "")
u.args.Name = c.Name
u.args.NameOrID = c.Name

newName := "new-name"
u.flags.Name = newName
Expand All @@ -177,7 +177,7 @@ func TestUpdateConnectorExecutionWithNewName(t *testing.T) {

client.
EXPECT().
UpdateConnector(ctx, u.args.Name, &cu).
UpdateConnector(ctx, u.args.NameOrID, &cu).
Return(&c, nil)

err := u.Execute(ctx)
Expand All @@ -189,7 +189,7 @@ func TestUpdateConnectorExecutionWithNewName(t *testing.T) {
gotLeveledOutput := logger.LeveledOutput()
wantLeveledOutput := fmt.Sprintf(`Updating connector %q...
Connector %q successfully updated!
`, u.args.Name, u.args.Name)
`, u.args.NameOrID, u.args.NameOrID)

if gotLeveledOutput != wantLeveledOutput {
t.Fatalf("expected output:\n%s\ngot:\n%s", wantLeveledOutput, gotLeveledOutput)
Expand Down Expand Up @@ -219,7 +219,7 @@ func TestUpdateConnectorExecutionWithNewConfig(t *testing.T) {
}

c := utils.GenerateConnector(0, "")
u.args.Name = c.Name
u.args.NameOrID = c.Name

newConfig := "{\"table.name.format\":\"public.copy\"}"
cfg := map[string]interface{}{}
Expand All @@ -237,7 +237,7 @@ func TestUpdateConnectorExecutionWithNewConfig(t *testing.T) {

client.
EXPECT().
UpdateConnector(ctx, u.args.Name, &cu).
UpdateConnector(ctx, u.args.NameOrID, &cu).
Return(&c, nil)

err = u.Execute(ctx)
Expand All @@ -249,7 +249,7 @@ func TestUpdateConnectorExecutionWithNewConfig(t *testing.T) {
gotLeveledOutput := logger.LeveledOutput()
wantLeveledOutput := fmt.Sprintf(`Updating connector %q...
Connector %q successfully updated!
`, u.args.Name, u.args.Name)
`, u.args.NameOrID, u.args.NameOrID)

if gotLeveledOutput != wantLeveledOutput {
t.Fatalf("expected output:\n%s\ngot:\n%s", wantLeveledOutput, gotLeveledOutput)
Expand Down
8 changes: 4 additions & 4 deletions cmd/meroxa/root/resources/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ var (
)

type describeResourceClient interface {
GetResourceByName(ctx context.Context, name string) (*meroxa.Resource, error)
GetResourceByNameOrID(ctx context.Context, nameOrID string) (*meroxa.Resource, error)
}

type Describe struct {
client describeResourceClient
logger log.Logger

args struct {
Name string
NameOrID string
}
}

Expand All @@ -58,7 +58,7 @@ func (d *Describe) Docs() builder.Docs {
}

func (d *Describe) Execute(ctx context.Context) error {
resource, err := d.client.GetResourceByName(ctx, d.args.Name)
resource, err := d.client.GetResourceByNameOrID(ctx, d.args.NameOrID)
if err != nil {
return err
}
Expand Down Expand Up @@ -94,6 +94,6 @@ func (d *Describe) ParseArgs(args []string) error {
return errors.New("requires resource name")
}

d.args.Name = args[0]
d.args.NameOrID = args[0]
return nil
}
8 changes: 4 additions & 4 deletions cmd/meroxa/root/resources/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func TestDescribeResourceArgs(t *testing.T) {
t.Fatalf("expected \"%s\" got \"%s\"", tt.err, err)
}

if tt.name != ar.args.Name {
t.Fatalf("expected \"%s\" got \"%s\"", tt.name, ar.args.Name)
if tt.name != ar.args.NameOrID {
t.Fatalf("expected \"%s\" got \"%s\"", tt.name, ar.args.NameOrID)
}
}
}
Expand All @@ -64,7 +64,7 @@ func TestDescribeResourceExecution(t *testing.T) {
r := utils.GenerateResource()
client.
EXPECT().
GetResourceByName(
GetResourceByNameOrID(
ctx,
r.Name,
).
Expand All @@ -74,7 +74,7 @@ func TestDescribeResourceExecution(t *testing.T) {
client: client,
logger: logger,
}
de.args.Name = r.Name
de.args.NameOrID = r.Name

err := de.Execute(ctx)
if err != nil {
Expand Down
Loading

0 comments on commit 2ddc6b1

Please sign in to comment.