Skip to content

Commit

Permalink
absorb new meroxa-go interface; small doc changes (#217)
Browse files Browse the repository at this point in the history
* Small doc changes

* absord new meroxa-go interface

* very subtle type mismatches

* formatting

* lint and updated interface

* tests

* try different version of linter

* lint

* latest interface changes

* feedback, formatting

* no flag changes

* test connector metadata

* no doc changes

* lint

* lint

* lint

* lint again

* chore: Use latest meroxa-go and update docs

Co-authored-by: Raúl Barroso <[email protected]>
  • Loading branch information
janelletavares and raulb authored Nov 19, 2021
1 parent 80d8ac9 commit 725bf81
Show file tree
Hide file tree
Showing 238 changed files with 3,166 additions and 2,658 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.42.0
version: v1.43.0
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ make gomod
make build
```

### Development Configuration
The [meroxa-dev CLI](https://github.com/meroxa/meroxa-dev#install) makes it convenient to set the necessary env vars for different dev environments.

## Release

A [goreleaser](https://github.com/goreleaser/goreleaser) GitHub Action is
Expand Down Expand Up @@ -123,4 +126,4 @@ Verify the correct setup, by running ` cat ~/.gitconfig`. You should see the fol
insteadOf = https://github.com
```

Run the `make gomod` command again, and you should see all depedencies being downloaded successfully.
Run the `make gomod` command again, and you should see all dependencies being downloaded successfully.
4 changes: 2 additions & 2 deletions cmd/meroxa/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/meroxa/cli/cmd/meroxa/global"
"github.com/meroxa/cli/config"
"github.com/meroxa/cli/log"
"github.com/meroxa/meroxa-go"
"github.com/meroxa/meroxa-go/pkg/meroxa"
)

type Command interface {
Expand Down Expand Up @@ -64,7 +64,7 @@ type CommandWithArgs interface {
type CommandWithClient interface {
Command
// Client provides the meroxa client to the command.
Client(*meroxa.Client)
Client(meroxa.Client)
}

type CommandWithConfig interface {
Expand Down
6 changes: 3 additions & 3 deletions cmd/meroxa/global/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import (
"time"

"github.com/spf13/viper"

"github.com/meroxa/meroxa-go"
"golang.org/x/oauth2"

"github.com/meroxa/meroxa-go/pkg/meroxa"
)

func noUserInfo(actor, actorUUID string) bool {
Expand Down Expand Up @@ -118,7 +118,7 @@ func GetUserToken() (accessToken, refreshToken string, err error) {
return accessToken, refreshToken, nil
}

func NewClient() (*meroxa.Client, error) {
func NewClient() (meroxa.Client, error) {
accessToken, refreshToken, err := GetUserToken()

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/meroxa/global/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package global

import (
"io/ioutil"
"io"
"os"

"github.com/meroxa/cli/log"
Expand All @@ -27,7 +27,7 @@ func NewLogger() log.Logger {
var (
logLevel = log.Info
leveledLoggerOut = os.Stdout
jsonLoggerOut = ioutil.Discard
jsonLoggerOut = io.Discard
)

if flagJSON {
Expand Down
8 changes: 4 additions & 4 deletions cmd/meroxa/root/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import (
"context"
"encoding/json"
"errors"
"io/ioutil"
"io"
"net/http"
"net/url"
"strings"

"github.com/meroxa/cli/log"
"github.com/meroxa/meroxa-go"
"github.com/meroxa/meroxa-go/pkg/meroxa"

"github.com/meroxa/cli/cmd/meroxa/builder"
)
Expand Down Expand Up @@ -68,7 +68,7 @@ meroxa api POST /v1/endpoints '{"protocol": "HTTP", "stream": "resource-2-499379
}
}

func (a *API) Client(client *meroxa.Client) {
func (a *API) Client(client meroxa.Client) {
a.client = client
}

Expand Down Expand Up @@ -98,7 +98,7 @@ func (a *API) Execute(ctx context.Context) error {
}
defer resp.Body.Close()

b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/meroxa/root/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
"testing"

"github.com/golang/mock/gomock"
"github.com/meroxa/cli/log"
mock "github.com/meroxa/cli/mock-cmd"
"github.com/meroxa/meroxa-go/pkg/mock"
)

func TestDescribeAPIArgs(t *testing.T) {
Expand Down Expand Up @@ -92,7 +92,7 @@ func TestDescribeAPIArgs(t *testing.T) {
func TestAPIExecution(t *testing.T) {
ctx := context.Background()
ctrl := gomock.NewController(t)
client := mock.NewMockAPIClient(ctrl)
client := mock.NewMockClient(ctrl)
logger := log.NewTestLogger()

a := &API{
Expand All @@ -107,7 +107,7 @@ func TestAPIExecution(t *testing.T) {
var httpResponse = &http.Response{
Status: "200 OK",
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewReader([]byte(bodyResponse))),
Body: io.NopCloser(bytes.NewReader([]byte(bodyResponse))),
}

client.
Expand Down
3 changes: 1 addition & 2 deletions cmd/meroxa/root/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -232,7 +231,7 @@ func (l *Login) getAccessTokenAuth(
// process the response
defer res.Body.Close()
var responseData map[string]interface{}
body, _ := ioutil.ReadAll(res.Body)
body, _ := io.ReadAll(res.Body)

// unmarshal the json into a string map
err = json.Unmarshal(body, &responseData)
Expand Down
4 changes: 2 additions & 2 deletions cmd/meroxa/root/auth/whoami.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/meroxa/cli/cmd/meroxa/builder"
"github.com/meroxa/cli/config"
"github.com/meroxa/cli/log"
"github.com/meroxa/meroxa-go"
"github.com/meroxa/meroxa-go/pkg/meroxa"
)

type getUserClient interface {
Expand Down Expand Up @@ -58,7 +58,7 @@ func (w *WhoAmI) Docs() builder.Docs {
}
}

func (w *WhoAmI) Client(client *meroxa.Client) {
func (w *WhoAmI) Client(client meroxa.Client) {
w.client = client
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/meroxa/root/auth/whoami_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import (

"github.com/meroxa/cli/config"
"github.com/meroxa/cli/log"
"github.com/meroxa/meroxa-go"
"github.com/meroxa/meroxa-go/pkg/meroxa"

"github.com/golang/mock/gomock"
mock "github.com/meroxa/cli/mock-cmd"
"github.com/meroxa/meroxa-go/pkg/mock"
)

func TestWhoAmIExecution(t *testing.T) {
ctx := context.Background()
ctrl := gomock.NewController(t)
client := mock.NewMockGetUserClient(ctrl)
client := mock.NewMockClient(ctrl)
logger := log.NewTestLogger()

cfg := config.NewInMemoryConfig()
Expand Down
4 changes: 2 additions & 2 deletions cmd/meroxa/root/connectors/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package connectors
import (
"context"

"github.com/meroxa/meroxa-go"
"github.com/meroxa/meroxa-go/pkg/meroxa"

"github.com/meroxa/cli/cmd/meroxa/builder"
"github.com/meroxa/cli/log"
Expand All @@ -37,7 +37,7 @@ type Connect struct {
}
}

func (c *Connect) Client(client *meroxa.Client) {
func (c *Connect) Client(client meroxa.Client) {
c.client = client
}

Expand Down
39 changes: 19 additions & 20 deletions cmd/meroxa/root/connectors/connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import (
"testing"

"github.com/golang/mock/gomock"
"github.com/meroxa/cli/log"
mock "github.com/meroxa/cli/mock-cmd"
"github.com/meroxa/meroxa-go"

"github.com/meroxa/cli/cmd/meroxa/builder"
"github.com/meroxa/cli/log"
"github.com/meroxa/cli/utils"
"github.com/meroxa/meroxa-go/pkg/meroxa"
"github.com/meroxa/meroxa-go/pkg/mock"
)

func TestConnectFlags(t *testing.T) {
Expand Down Expand Up @@ -67,7 +67,7 @@ func TestConnectFlags(t *testing.T) {
func TestConnectExecution(t *testing.T) {
ctx := context.Background()
ctrl := gomock.NewController(t)
client := mock.NewMockCreateConnectorClient(ctrl)
client := mock.NewMockClient(ctrl)
logger := log.NewTestLogger()

c := &Connect{
Expand All @@ -85,15 +85,15 @@ func TestConnectExecution(t *testing.T) {
c.flags.Pipeline = "my-pipeline"

cSource := utils.GenerateConnector(0, "")
cSource.Metadata = map[string]interface{}{"mx:connectorType": "source"}
cSource.Type = meroxa.ConnectorTypeSource

cDestination := utils.GenerateConnector(0, "")
cDestination.Metadata = map[string]interface{}{"mx:connectorType": "destination"}
cDestination.Type = meroxa.ConnectorTypeDestination

// Create source
client.
EXPECT().
GetResourceByName(
GetResourceByNameOrID(
ctx,
rSource.Name,
).
Expand All @@ -103,45 +103,44 @@ func TestConnectExecution(t *testing.T) {
EXPECT().
CreateConnector(
ctx,
meroxa.CreateConnectorInput{
&meroxa.CreateConnectorInput{
Name: "",
ResourceID: rSource.ID,
Configuration: map[string]interface{}{
"key": "value",
"input": "my-resource.Table",
},
Metadata: map[string]interface{}{
"mx:connectorType": "source",
"key": "value",
},
Metadata: map[string]interface{}{},
PipelineName: c.flags.Pipeline,
Input: "my-resource.Table",
Type: meroxa.ConnectorTypeSource,
},
).
Return(&cSource, nil)

// Create destination
client.
EXPECT().
GetResourceByName(
GetResourceByNameOrID(
ctx,
rDestination.Name,
).
AnyTimes().
Return(&rDestination, nil)

client.
EXPECT().
CreateConnector(
ctx,
meroxa.CreateConnectorInput{
&meroxa.CreateConnectorInput{
Name: "",
ResourceID: rDestination.ID,
Configuration: map[string]interface{}{
"key": "value",
"input": "my-resource.Table",
},
Metadata: map[string]interface{}{
"mx:connectorType": "destination",
"key": "value",
},
Metadata: map[string]interface{}{},
PipelineName: c.flags.Pipeline,
Input: "my-resource.Table",
Type: meroxa.ConnectorTypeDestination,
},
).
Return(&cDestination, nil)
Expand Down
Loading

0 comments on commit 725bf81

Please sign in to comment.