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

feat!: Update to SDK V4 & fix infinite loop on transactions #10

Merged
merged 10 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
go-version-file: go.mod
cache: true
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
with:
version: v1.50.1
version: v1.59.1
- name: Get dependencies
run: go get -t -d ./...
- name: Build
Expand Down
122 changes: 122 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
run:
tests: true
skip-dirs:
- bin
- docs
- client/mocks
- resources/forks
- codegen
- internal/trello
timeout: 15m
build-tags:
- all

linters-settings:
errcheck:
check-blank: false
ignore: fmt:.*,[rR]ead|[wW]rite|[cC]lose,io:Copy
gocritic:
disabled-checks:
- commentFormatting
dupl:
# tokens count to trigger issue, 150 by default
threshold: 500

misspell:
ignore-words:
- hdinsight

revive:
enable-all-rules: true
rules:
- name: cyclomatic
disabled: true
- name: argument-limit
disabled: true
- name: function-length
disabled: true
- name: function-result-limit
disabled: true
- name: line-length-limit
disabled: true
- name: file-header
disabled: true
- name: cognitive-complexity
disabled: true
- name: banned-characters
disabled: true
- name: max-public-structs
disabled: true
- name: add-constant
disabled: true
- name: unhandled-error
disabled: true
- name: var-naming
disabled: true
- name: deep-exit
disabled: true
- name: exported
disabled: false
arguments:
- 'disableStutteringCheck'
- name: unused-parameter
disabled: true
- name: confusing-naming
disabled: true
- name: confusing-results
disabled: true
- name: flag-parameter
disabled: true
- name: nested-structs
disabled: true
- name: unchecked-type-assertion
disabled: true
- name: import-alias-naming
disabled: true
- name: redundant-import-alias
disabled: true

gofmt:
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'
- pattern: 'a[b:len(a)]'
replacement: 'a[b:]'


linters:
enable:
- asciicheck
- bodyclose
- dupl
- errcheck
- gocritic
- gofmt
- gosimple
- govet
- ineffassign
- importas
- misspell
- nakedret
- prealloc
- revive
- staticcheck
- unconvert
- unparam
- unused

issues:
exclude-rules:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- dupl
- gocritic
# Exclude some linters from running on resource files.
- path: resources(\\|\/).*\.go
linters:
- dupl
# Exclude some linters from running on services files.
- path: services\.go
linters:
- dupl
9 changes: 4 additions & 5 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import (
"context"
"encoding/json"
"fmt"
"strings"

"github.com/cloudquery/plugin-pb-go/specs"
"github.com/cloudquery/plugin-sdk/v3/plugins/source"
"github.com/cloudquery/plugin-sdk/v3/schema"
"github.com/hashicorp/go-retryablehttp"
"github.com/plaid/plaid-go/v10/plaid"
"github.com/rs/zerolog"
Expand All @@ -19,9 +17,10 @@
ClientId string
Secret string
AccessToken string
Spec Spec
}

func (c *Client) ID() string {

Check failure on line 23 in client/client.go

View workflow job for this annotation

GitHub Actions / test

unused-receiver: method receiver 'c' is not referenced in method's body, consider removing or renaming it as _ (revive)
candiduslynx marked this conversation as resolved.
Show resolved Hide resolved
return "plaid"
}

Expand All @@ -37,10 +36,10 @@
}
}

func New(ctx context.Context, logger zerolog.Logger, s specs.Source, opts source.Options) (schema.ClientMeta, error) {
func New(ctx context.Context, logger zerolog.Logger, s []byte) (*Client, error) {
var pluginSpec Spec

if err := s.UnmarshalSpec(&pluginSpec); err != nil {
if err := json.Unmarshal(s, &pluginSpec); err != nil {
return nil, fmt.Errorf("failed to unmarshal plugin spec: %w", err)
}

Expand Down
2 changes: 1 addition & 1 deletion client/resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

"github.com/cloudquery/plugin-sdk/v3/schema"
"github.com/cloudquery/plugin-sdk/v4/schema"
"github.com/plaid/plaid-go/v10/plaid"
"github.com/thoas/go-funk"
)
Expand Down
104 changes: 62 additions & 42 deletions client/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
"testing"
"time"

"github.com/cloudquery/plugin-pb-go/specs"
"github.com/cloudquery/plugin-sdk/v3/plugins/source"
"github.com/cloudquery/plugin-sdk/v3/schema"
"github.com/cloudquery/plugin-sdk/v4/plugin"
"github.com/cloudquery/plugin-sdk/v4/scheduler"
"github.com/cloudquery/plugin-sdk/v4/schema"
"github.com/cloudquery/plugin-sdk/v4/transformers"
"github.com/plaid/plaid-go/v10/plaid"
"github.com/rs/zerolog"
)
Expand All @@ -28,49 +29,68 @@
return ts
}

func remove(s schema.ColumnList, i string) schema.ColumnList {

Check failure on line 32 in client/testing.go

View workflow job for this annotation

GitHub Actions / test

empty-lines: extra empty line at the end of a block (revive)
for j, c := range s {
if c.Name == i {
return append(s[:j], s[j+1:]...)
}
}

return s

candiduslynx marked this conversation as resolved.
Show resolved Hide resolved
}

func TestHelper(t *testing.T, table *schema.Table, ts *httptest.Server) {
version := "vDev"
table.IgnoreInTests = false
t.Helper()
l := zerolog.New(zerolog.NewTestWriter(t)).Output(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.StampMicro}).Level(zerolog.DebugLevel).With().Timestamp().Logger()

newTestExecutionClient := func(ctx context.Context, logger zerolog.Logger, spec specs.Source, opts source.Options) (schema.ClientMeta, error) {
configuration := plaid.NewConfiguration()
configuration.UseEnvironment(plaid.Development)
urlParts := strings.Split(ts.URL, "://")
configuration.Scheme = urlParts[0]
configuration.Host = urlParts[1]
client := plaid.NewAPIClient(configuration)
s := Spec{
ClientId: "test",
Secret: "test",
AccessToken: "test",
}
s.SetDefaults()
err := s.Validate()
if err != nil {
return nil, err
}
return &Client{
Logger: l,
Services: client,
ClientId: s.ClientId,
Secret: s.Secret,
}, nil
l := zerolog.New(zerolog.NewTestWriter(t)).Output(
zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.StampMicro},
).Level(zerolog.DebugLevel).With().Timestamp().Logger()
sched := scheduler.NewScheduler(scheduler.WithLogger(l))

configuration := plaid.NewConfiguration()
configuration.UseEnvironment(plaid.Development)
urlParts := strings.Split(ts.URL, "://")
configuration.Scheme = urlParts[0]
configuration.Host = urlParts[1]
client := plaid.NewAPIClient(configuration)
s := Spec{
ClientId: "test",
Secret: "test",
AccessToken: "test",
}
p := source.NewPlugin(
table.Name,
version,
[]*schema.Table{
table,
},
newTestExecutionClient)
p.SetLogger(l)
source.TestPluginSync(t, p, specs.Source{
Name: "dev",
Path: "cloudquery/dev",
Version: version,
Tables: []string{table.Name},
Destinations: []string{"mock-destination"},
s.SetDefaults()
err := s.Validate()
if err != nil {
t.Fatal(err)
}

c := &Client{
Logger: l,
Services: client,
ClientId: s.ClientId,
Secret: s.Secret,
AccessToken: s.AccessToken,
}

tables := schema.Tables{table}
if err := transformers.TransformTables(tables); err != nil {
t.Fatal(err)
}

// We need to remove additional_properties column from the table as faker cannot generate data with interface{} type
err = transformers.Apply(tables, func(table *schema.Table) error {
table.Columns = remove(table.Columns, "additional_properties")
return nil
})
if err != nil {
t.Fatal(err)
}

messages, err := sched.SyncAll(context.Background(), c, tables)
if err != nil {
t.Fatalf("failed to sync: %v", err)
}
plugin.ValidateNoEmptyColumns(t, tables, messages)
}
6 changes: 3 additions & 3 deletions client/transformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package client
import (
"reflect"

"github.com/apache/arrow/go/v13/arrow"
"github.com/cloudquery/plugin-sdk/v3/schema"
"github.com/cloudquery/plugin-sdk/v3/transformers"
"github.com/apache/arrow/go/v16/arrow"
"github.com/cloudquery/plugin-sdk/v4/schema"
"github.com/cloudquery/plugin-sdk/v4/transformers"
"github.com/plaid/plaid-go/v10/plaid"
)

Expand Down
Loading
Loading