hs-test: added go style targets 66/40966/4
authorAdrian Villin <[email protected]>
Tue, 11 Jun 2024 08:32:08 +0000 (10:32 +0200)
committerDave Wallace <[email protected]>
Wed, 12 Jun 2024 16:08:49 +0000 (16:08 +0000)
- added checkstyle-go and fixstyle-go
- comments in stats_fs.go were missing a space

Type: make

Change-Id: I520acab5ff61eaf9d0ccfd9425bdc41f74559198
Signed-off-by: Adrian Villin <[email protected]>
Makefile
extras/hs-test/Makefile
extras/vpp_stats_fs/stats_fs.go

index 18908fa..cf5d185 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -777,6 +777,14 @@ checkstyle-test:
 checkstyle-python:
        @$(MAKE) -C test checkstyle-python-all
 
+.PHONY: checkstyle-go
+checkstyle-go:
+       @$(MAKE) -C extras/hs-test checkstyle-go
+
+.PHONY: fixstyle-go
+fixstyle-go:
+       @$(MAKE) -C extras/hs-test fixstyle-go
+
 .PHONY: checkstyle-all
 checkstyle-all: checkstyle-commit checkstyle checkstyle-python docs-spell
 
index d459d9d..118afef 100644 (file)
@@ -1,5 +1,10 @@
 export HS_ROOT=$(CURDIR)
 
+# sets WS_ROOT if called from extras/hs-test
+ifeq ($(WS_ROOT),)
+export WS_ROOT=$(HS_ROOT)/../..
+endif
+
 ifeq ($(VERBOSE),)
 VERBOSE=false
 endif
@@ -60,7 +65,8 @@ help:
        @echo " build-cov                        - coverage build of VPP and Docker images"
        @echo " build-debug          - build test infra (vpp debug image)"
        @echo " build-go             - just build golang files"
-       @echo " fixstyle             - format .go source files"
+       @echo " checkstyle-go        - check style of .go source files"
+       @echo " fixstyle-go          - format .go source files"
        @echo " list-tests           - list all tests"
        @echo
        @echo "make build arguments:"
@@ -171,7 +177,26 @@ install-deps:
        fi
        @touch .deps.ok
 
-.PHONY: fixstyle
-fixstyle:
-       @gofmt -w .
+.PHONY: checkstyle-go
+checkstyle-go:
+       @output=$$(gofmt -d $${WS_ROOT}); \
+    if [ -z "$$output" ]; then \
+        echo "*******************************************************************"; \
+        echo "Checkstyle OK."; \
+        echo "*******************************************************************"; \
+    else \
+        echo "$$output"; \
+        echo "*******************************************************************"; \
+        echo "Checkstyle failed. Use 'make fixstyle-go' or fix errors manually."; \
+        echo "*******************************************************************"; \
+        exit 1; \
+    fi
+
+.PHONY: fixstyle-go
+fixstyle-go:
+       @echo "Modified files:"
+       @gofmt -w -l $(WS_ROOT)
        @go mod tidy
+       @echo "*******************************************************************"
+       @echo "Fixstyle done."
+       @echo "*******************************************************************"
index 80c1509..7b0f1ec 100644 (file)
@@ -132,7 +132,7 @@ func getCounterContent(index uint32, client *statsclient.StatsClient) (content s
        return content, fs.OK
 }
 
-//The dirNode structure represents directories
+// The dirNode structure represents directories
 type dirNode struct {
        fs.Inode
        client *statsclient.StatsClient
@@ -175,7 +175,7 @@ func (dn *dirNode) Opendir(ctx context.Context) syscall.Errno {
        return status
 }
 
-//The statNode structure represents counters
+// The statNode structure represents counters
 type statNode struct {
        fs.Inode
        client *statsclient.StatsClient
@@ -192,7 +192,7 @@ func (fh *statNode) Getattr(ctx context.Context, f fs.FileHandle, out *fuse.Attr
        return 0
 }
 
-//When a file is opened, the correpsonding counter value is dumped and a file handle is created
+// When a file is opened, the correpsonding counter value is dumped and a file handle is created
 func (sn *statNode) Open(ctx context.Context, flags uint32) (fs.FileHandle, uint32, syscall.Errno) {
        content, status := getCounterContent(sn.index, sn.client)
        if status == syscall.ENOENT {
@@ -220,7 +220,7 @@ func (fh *statFH) Read(ctx context.Context, data []byte, off int64) (fuse.ReadRe
        return fuse.ReadResultData(fh.data[off:end]), fs.OK
 }
 
-//NewStatsFileSystem creates the fs for the stat segment.
+// NewStatsFileSystem creates the fs for the stat segment.
 func NewStatsFileSystem(sc *statsclient.StatsClient) (root fs.InodeEmbedder, err error) {
        return &dirNode{client: sc}, nil
 }