Skip to content

Commit

Permalink
fix linter; fix linter script for mac
Browse files Browse the repository at this point in the history
  • Loading branch information
krehermann committed May 16, 2024
1 parent 71444a2 commit 1d8c865
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 62 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.21

require (
github.com/confluentinc/confluent-kafka-go/v2 v2.3.0
github.com/dominikbraun/graph v0.23.0
github.com/fxamacker/cbor/v2 v2.5.0
github.com/go-json-experiment/json v0.0.0-20231102232822-2e55bd4e08b0
github.com/google/uuid v1.3.1
Expand Down Expand Up @@ -37,8 +38,6 @@ require (
google.golang.org/protobuf v1.31.0
)

require github.com/dominikbraun/graph v0.23.0

require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions pkg/workflows/dependency_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/dominikbraun/graph"

"github.com/smartcontractkit/chainlink-common/pkg/capabilities"
)

Expand Down
3 changes: 2 additions & 1 deletion pkg/workflows/dependency_graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package workflows_test
import (
"testing"

"github.com/smartcontractkit/chainlink-common/pkg/workflows"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/workflows"
)

func TestParseDependencyGraph(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/workflows/models_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/capabilities"
)

func GenerateJsonSchema() ([]byte, error) {
func GenerateJSONSchema() ([]byte, error) {
schema := jsonschema.Reflect(&workflowSpecYaml{})

return json.MarshalIndent(schema, "", " ")
Expand Down
64 changes: 8 additions & 56 deletions pkg/workflows/models_yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,54 +17,6 @@ import (

var fixtureDir = "./testdata/fixtures/workflows/"

const testWorkflowYAML = `
triggers:
- id: "mercury-trigger"
config:
feedIds:
- "0x1111111111111111111100000000000000000000000000000000000000000000"
- "0x2222222222222222222200000000000000000000000000000000000000000000"
- "0x3333333333333333333300000000000000000000000000000000000000000000"
consensus:
- id: "offchain_reporting"
ref: "evm_median"
inputs:
observations:
- "$(trigger.outputs)"
config:
aggregation_method: "data_feeds_2_0"
aggregation_config:
"0x1111111111111111111100000000000000000000000000000000000000000000":
deviation: "0.001"
heartbeat: 3600
"0x2222222222222222222200000000000000000000000000000000000000000000":
deviation: "0.001"
heartbeat: 3600
"0x3333333333333333333300000000000000000000000000000000000000000000":
deviation: "0.001"
heartbeat: 3600
encoder: "EVM"
encoder_config:
abi: "mercury_reports bytes[]"
targets:
- id: "write_polygon-testnet-mumbai"
inputs:
report: "$(evm_median.outputs.report)"
config:
address: "0x3F3554832c636721F1fD1822Ccca0354576741Ef"
params: ["$(report)"]
abi: "receive(report bytes)"
- id: "write_ethereum-testnet-sepolia"
inputs:
report: "$(evm_median.outputs.report)"
config:
address: "0x54e220867af6683aE6DcBF535B4f952cB5116510"
params: ["$(report)"]
abi: "receive(report bytes)"
`

// yamlFixtureReaderObj reads a yaml fixture file and returns the parsed object
func yamlFixtureReaderObj(t *testing.T, testCase string) func(name string) any {
testFixtureReader := yamlFixtureReaderBytes(t, testCase)
Expand Down Expand Up @@ -115,12 +67,12 @@ func TestWorkflowSpecMarshalling(t *testing.T) {
err = yaml.Unmarshal(workflowBytes, &rawSpec)
require.NoError(t, err)

workflowspecJson, err := json.MarshalIndent(spec, "", " ")
workflowspecJSON, err := json.MarshalIndent(spec, "", " ")
require.NoError(t, err)
rawWorkflowSpecJson, err := json.MarshalIndent(rawSpec, "", " ")
rawworkflowspecJSON, err := json.MarshalIndent(rawSpec, "", " ")
require.NoError(t, err)

if diff := cmp.Diff(rawWorkflowSpecJson, workflowspecJson, transformJSON); diff != "" {
if diff := cmp.Diff(rawworkflowspecJSON, workflowspecJSON, transformJSON); diff != "" {
t.Errorf("ParseWorkflowWorkflowSpecFromString() mismatch (-want +got):\n%s", diff)
t.FailNow()
}
Expand Down Expand Up @@ -176,12 +128,12 @@ func TestWorkflowSpecMarshalling(t *testing.T) {
err = yaml.Unmarshal(workflowBytes, &rawSpec)
require.NoError(t, err)

workflowspecJson, err := json.MarshalIndent(spec, "", " ")
workflowspecJSON, err := json.MarshalIndent(spec, "", " ")
require.NoError(t, err)
rawWorkflowSpecJson, err := json.MarshalIndent(rawSpec, "", " ")
rawworkflowspecJSON, err := json.MarshalIndent(rawSpec, "", " ")
require.NoError(t, err)

if diff := cmp.Diff(rawWorkflowSpecJson, workflowspecJson, transformJSON); diff != "" {
if diff := cmp.Diff(rawworkflowspecJSON, workflowspecJSON, transformJSON); diff != "" {
t.Errorf("ParseWorkflowWorkflowSpecFromString() mismatch (-want +got):\n%s", diff)
t.FailNow()
}
Expand Down Expand Up @@ -220,7 +172,7 @@ func TestJsonSchema(t *testing.T) {
t.Parallel()
t.Run("GenerateJsonSchema", func(t *testing.T) {
expectedSchemaPath := fixtureDir + "workflow_schema.json"
generatedSchema, err := GenerateJsonSchema()
generatedSchema, err := GenerateJSONSchema()
require.NoError(t, err)

// change this to update golden file
Expand All @@ -240,7 +192,7 @@ func TestJsonSchema(t *testing.T) {
})

t.Run("ValidateJsonSchema", func(t *testing.T) {
generatedSchema, err := GenerateJsonSchema()
generatedSchema, err := GenerateJSONSchema()
require.NoError(t, err)

// test version regex
Expand Down
6 changes: 4 additions & 2 deletions script/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# run_linter.sh
# This script runs golangci-lint either locally or in a Docker container based on version matching.

# Parameters
GOLANGCI_LINT_VERSION="$1"
COMMON_OPTS="$2"
Expand All @@ -16,7 +15,7 @@ mkdir -p "$DIRECTORY"
DOCKER_CMD="docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v$GOLANGCI_LINT_VERSION golangci-lint run $COMMON_OPTS $EXTRA_OPTS"

if command -v golangci-lint >/dev/null 2>&1; then
LOCAL_VERSION=$(golangci-lint version 2>&1 | grep -oP 'version \K[\d.]+')
LOCAL_VERSION=$(golangci-lint version 2>&1 | grep -oE "version .[{0-9}.]+" | sed "s|version .||")

if [ "$LOCAL_VERSION" = "$GOLANGCI_LINT_VERSION" ]; then
echo "Local golangci-lint version ($LOCAL_VERSION) matches desired version ($GOLANGCI_LINT_VERSION). Using local version."
Expand All @@ -32,3 +31,6 @@ else
echo "Local golangci-lint not found. Using Docker version."
$DOCKER_CMD > "$OUTPUT_FILE"
fi

echo "Linting complete. Results saved to $OUTPUT_FILE"

0 comments on commit 1d8c865

Please sign in to comment.