Skip to content

Commit

Permalink
Add script to check linting,vetting,format issues. Fix format issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rensyct committed Nov 8, 2021
1 parent 4fbdf4d commit c7c6767
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.podman
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Stage to build the driver
FROM golang:1.16.3 as builder
FROM golang:1.16 as builder
RUN mkdir -p /go/src
COPY csi-unity/ /go/src/csi-unity

Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,6 @@ clean:
.PHONY: integ-test
integ-test: go-build
go test -v ./test/...

check:
sh scripts/check.sh
50 changes: 50 additions & 0 deletions scripts/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/sh

if [ -f "../vendor" ]; then
# Tell the applicable Go tools to use the vendor directory, if it exists.
MOD_FLAGS="-mod=vendor"
fi
FMT_TMPFILE=/tmp/check_fmt
FMT_COUNT_TMPFILE=${FMT_TMPFILE}.count

fmt_count() {
if [ ! -f $FMT_COUNT_TMPFILE ]; then
echo "0"
fi

head -1 $FMT_COUNT_TMPFILE
}

fmt() {
gofmt -d ./service ./common/ ./core/ ./k8sutils/ ./provider/ | tee $FMT_TMPFILE
cat $FMT_TMPFILE | wc -l > $FMT_COUNT_TMPFILE
if [ ! `cat $FMT_COUNT_TMPFILE` -eq "0" ]; then
echo Found `cat $FMT_COUNT_TMPFILE` formatting issue\(s\).
return 1
fi
}

echo === Checking format...
fmt
FMT_RETURN_CODE=$?
echo === Finished

echo === Vetting...
go vet ${MOD_FLAGS} ./service/... ./common/...
VET_RETURN_CODE=$?
echo === Finished

echo === Linting...
(command -v golint >/dev/null 2>&1 \
|| GO111MODULE=off go get -insecure -u golang.org/x/lint/golint) \
&& golint --set_exit_status ./service/... ./common/...
LINT_RETURN_CODE=$?
echo === Finished

# Report output.
fail_checks=0
[ "${FMT_RETURN_CODE}" != "0" ] && echo "Formatting checks failed!" && fail_checks=1
[ "${VET_RETURN_CODE}" != "0" ] && echo "Vetting checks failed!" && fail_checks=1
[ "${LINT_RETURN_CODE}" != "0" ] && echo "Linting checks failed!" && fail_checks=1

exit ${fail_checks}
2 changes: 1 addition & 1 deletion service/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,7 @@ func (s *service) addNewNodeToArray(ctx context.Context, array *StorageArrayConf
var ipFormat = regexp.MustCompile(`(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}`)
for _, nodeIp := range nodeIps {
_, err = hostApi.CreateHostIpPort(ctx, hostContent.ID, nodeIp)
if err != nil && !ipFormat.MatchString(s.opts.NodeName){
if err != nil && !ipFormat.MatchString(s.opts.NodeName) {
return err
}
}
Expand Down
9 changes: 4 additions & 5 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"regexp"
"sync"
"sync/atomic"
"time"
"os"

"github.com/dell/dell-csi-extensions/podmon"
"google.golang.org/grpc"
Expand Down Expand Up @@ -175,15 +175,14 @@ func (s *service) BeforeServe(
var shortHostName string
//check its ip or not
var ipFormat = regexp.MustCompile(`(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}`)
if (ipFormat.MatchString(name)) {
if ipFormat.MatchString(name) {
shortHostName = name
}else{
} else {
shortHostName = strings.Split(name, ".")[0]
}
opts.NodeName = shortHostName
}


if kubeConfigPath, ok := csictx.LookupEnv(ctx, EnvKubeConfigPath); ok {
opts.KubeConfigPath = kubeConfigPath
}
Expand Down
4 changes: 2 additions & 2 deletions test/unit-test/unit_main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package unit_test

import (
"context"
"gopkg.in/yaml.v2"
"fmt"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
"strconv"
Expand All @@ -27,7 +27,7 @@ type StorageArrayList struct {
}

type StorageArrayConfig struct {
ArrayId string `yaml:"ArrayId"`
ArrayId string `yaml:"ArrayId"`
}

func TestMain(m *testing.M) {
Expand Down

0 comments on commit c7c6767

Please sign in to comment.