Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: golangci-lint error #102

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions pkg/jsonrpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ func (c *Client) SendMsgWithTimeout(method string, params interface{}, timeout t
// For debug purpose
stdenc := json.NewEncoder(os.Stdin)
stdenc.SetIndent("", "\t")
stdenc.Encode(msg)
stdenc.Encode(&resp)
if encodeErr := stdenc.Encode(msg); encodeErr != nil {
logrus.WithError(encodeErr).Warn("failed to encode the request message")
}
if encodeErr := stdenc.Encode(&resp); encodeErr != nil {
logrus.WithError(encodeErr).Warn("failed to encode the response message")
}
}()

marshaledParams, err := json.Marshal(msg.Params)
Expand Down
9 changes: 7 additions & 2 deletions pkg/spdk/spdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import (

commonTypes "github.com/longhorn/go-common-libs/types"

"github.com/longhorn/go-spdk-helper/pkg/jsonrpc"
"github.com/longhorn/go-spdk-helper/pkg/nvme"
"github.com/longhorn/go-spdk-helper/pkg/spdk/client"
"github.com/longhorn/go-spdk-helper/pkg/spdk/target"
spdktypes "github.com/longhorn/go-spdk-helper/pkg/spdk/types"
"github.com/longhorn/go-spdk-helper/pkg/types"
"github.com/longhorn/go-spdk-helper/pkg/util"

spdktypes "github.com/longhorn/go-spdk-helper/pkg/spdk/types"
)

var (
Expand Down Expand Up @@ -111,7 +113,10 @@ func (s *TestSuite) TestSPDKBasic(c *C) {
c.Assert(err, IsNil)

// Do blindly cleanup
spdkCli.DeleteDevice(defaultDeviceName, defaultDeviceName)
err = spdkCli.DeleteDevice(defaultDeviceName, defaultDeviceName)
if err != nil {
c.Assert(jsonrpc.IsJSONRPCRespErrorNoSuchDevice(err), Equals, true)
}

bdevAioName, lvsName, lvsUUID, err := spdkCli.AddDevice(defaultDevicePath, defaultDeviceName, types.MiB)
c.Assert(err, IsNil)
Expand Down
4 changes: 0 additions & 4 deletions pkg/spdk/types/bdev.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@ type BdevGetBdevsRequest struct {
Timeout uint64 `json:"timeout,omitempty"`
}

type BdevGetBdevsResponse struct {
bdevs []BdevInfo
}

type BdevLvolFragmap struct {
ClusterSize uint64 `json:"cluster_size"`
NumClusters uint64 `json:"num_clusters"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func DetectDevice(path string, executor *commonNs.Executor) (*KernelDevice, erro
return nil, fmt.Errorf("invalid major:minor %s for device %s with path %s", dev.Nvme.Name, f[1], path)
}
}
break
break // nolint:staticcheck
}
if dev == nil {
return nil, fmt.Errorf("failed to get device with path %s", path)
Expand Down
16 changes: 2 additions & 14 deletions scripts/validate
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,8 @@ PACKAGES="$(find -name '*.go' | xargs -I{} dirname {} | cut -f2 -d/ | sort -u |
echo Running: go vet
go vet ${PACKAGES}

if [ ! -z "${DRONE_REPO}" ] && [ ! -z "${DRONE_PULL_REQUEST}" ]; then
wget https://github.com/$DRONE_REPO/pull/$DRONE_PULL_REQUEST.patch
echo "Running: golangci-lint run --new-from-patch=${DRONE_PULL_REQUEST}.patch"
golangci-lint run --new-from-patch="${DRONE_PULL_REQUEST}.patch"
rm "${DRONE_PULL_REQUEST}.patch"
elif [ ! -z "${DRONE_COMMIT_REF}" ]; then
echo "Running: golangci-lint run --new-from-rev=${DRONE_COMMIT_REF}"
golangci-lint run --new-from-rev=${DRONE_COMMIT_REF}
else
git symbolic-ref -q HEAD && REV="origin/HEAD" || REV="HEAD^"
headSHA=$(git rev-parse --short=12 ${REV})
echo "Running: golangci-lint run --new-from-rev=${headSHA}"
golangci-lint run --new-from-rev=${headSHA}
fi
echo "Running: golangci-lint"
golangci-lint run --timeout=5m

echo Running: go fmt
test -z "$(go fmt ${PACKAGES} | tee /dev/stderr)"