From fcc2486e87a08e18f605676f67a0dc62dd965926 Mon Sep 17 00:00:00 2001 From: otherview Date: Mon, 30 Dec 2024 15:11:00 +0000 Subject: [PATCH] lint --- .github/workflows/test.yaml | 8 ++++++++ cmd/cmd/api.go | 2 +- cmd/cmd/cmd.go | 2 +- cmd/cmd/root.go | 3 ++- entrypoint/api/http_api.go | 2 +- environments/local/local_test.go | 2 +- network/network.go | 3 +-- network/node/genesis/custom_genesis.go | 1 + network/node/node_base.go | 2 +- thorbuilder/thorbuilder_test.go | 2 -- 10 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 436e387..32258af 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -16,6 +16,14 @@ jobs: with: go-version: 1.22.x + - name: Install Dependencies + run: | + sudo apt-get update + sudo apt-get install -y make git build-essential + + - name: Pull Docker Image + run: docker pull vechain/thor:latest + - name: Make Test id: unit-test run: go test ./... -count=1 diff --git a/cmd/cmd/api.go b/cmd/cmd/api.go index fe08f9a..f69a99d 100644 --- a/cmd/cmd/api.go +++ b/cmd/cmd/api.go @@ -28,7 +28,7 @@ var apiCmd = &cobra.Command{ httpAPI := api.New(envManager, presets) if err := httpAPI.Start(); err != nil { - slog.Error("Shutting down.. Unexpected error in api - %w", err) + slog.Error("Shutting down.. Unexpected error in api", "err", err) return } slog.Info("Shutting down..") diff --git a/cmd/cmd/cmd.go b/cmd/cmd/cmd.go index e55f727..4d68a1c 100644 --- a/cmd/cmd/cmd.go +++ b/cmd/cmd/cmd.go @@ -90,7 +90,7 @@ var configureCmd = &cobra.Command{ // Read from the specified file data, err := os.ReadFile(args[0]) if err != nil { - slog.Error("Error reading config file: %v\n", err) + slog.Error("Error reading config file", "err", err) os.Exit(1) } diff --git a/cmd/cmd/root.go b/cmd/cmd/root.go index 9ed84e3..0566f7c 100644 --- a/cmd/cmd/root.go +++ b/cmd/cmd/root.go @@ -1,8 +1,9 @@ package cmd import ( - "github.com/spf13/cobra" "os" + + "github.com/spf13/cobra" ) // rootCmd represents the base command when called without any subcommands diff --git a/entrypoint/api/http_api.go b/entrypoint/api/http_api.go index c326c6b..4e52a5d 100644 --- a/entrypoint/api/http_api.go +++ b/entrypoint/api/http_api.go @@ -33,7 +33,7 @@ func (s *Server) Start() error { slog.Info("Server started on :8080") err := http.ListenAndServe(":8080", nil) if err != nil { - slog.Error("Error starting server:", err) + slog.Error("Error starting server", "err", err) } return nil } diff --git a/environments/local/local_test.go b/environments/local/local_test.go index dbe8133..b39f0c8 100644 --- a/environments/local/local_test.go +++ b/environments/local/local_test.go @@ -3,7 +3,6 @@ package local import ( "encoding/json" "fmt" - "github.com/vechain/networkhub/thorbuilder" "log/slog" "strings" "testing" @@ -12,6 +11,7 @@ import ( "github.com/stretchr/testify/require" "github.com/vechain/networkhub/network" "github.com/vechain/networkhub/preset" + "github.com/vechain/networkhub/thorbuilder" "github.com/vechain/networkhub/utils/client" "github.com/vechain/networkhub/utils/datagen" ) diff --git a/network/network.go b/network/network.go index cfc6b8c..e9d6c00 100644 --- a/network/network.go +++ b/network/network.go @@ -49,8 +49,7 @@ func UnmarshalNode(data []byte) (node.Node, error) { return nil, err } - var nodeType node.Node - nodeType = &node.BaseNode{} + nodeType := &node.BaseNode{} if genesisData, ok := raw["genesis"].(map[string]interface{}); ok { if forkConfig, ok := genesisData["forkConfig"].(map[string]interface{}); ok { // Handle AdditionalFields diff --git a/network/node/genesis/custom_genesis.go b/network/node/genesis/custom_genesis.go index 2143138..3d15193 100644 --- a/network/node/genesis/custom_genesis.go +++ b/network/node/genesis/custom_genesis.go @@ -2,6 +2,7 @@ package genesis import ( "fmt" + "github.com/vechain/thor/v2/genesis" "github.com/vechain/thor/v2/thor" ) diff --git a/network/node/node_base.go b/network/node/node_base.go index 8ac6ee4..14e37df 100644 --- a/network/node/node_base.go +++ b/network/node/node_base.go @@ -2,11 +2,11 @@ package node import ( "fmt" - "github.com/vechain/networkhub/network/node/genesis" "strings" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/p2p/discover" + "github.com/vechain/networkhub/network/node/genesis" ) type BaseNode struct { diff --git a/thorbuilder/thorbuilder_test.go b/thorbuilder/thorbuilder_test.go index 6919239..b44feb7 100644 --- a/thorbuilder/thorbuilder_test.go +++ b/thorbuilder/thorbuilder_test.go @@ -50,9 +50,7 @@ func TestBuilder(t *testing.T) { require.NoError(t, err) assert.Equal(t, filepath.Join(builder.downloadPath, "bin", "thor"), thorBinaryPath) }) -} -func TestErrorHandling(t *testing.T) { t.Run("Invalid Branch", func(t *testing.T) { branch := "invalid-branch" builder := New(branch, false)