Repository: prometheus/procfs
Pull request #268 (2020-02-26 12:18:30)

Enable golint tests
Enable golint testing for style fixes.
* Add exceptions to a couple places, mostly proc stat names.
* Fix up various issues.
* Update Makefile.common from upstream Prometheus.
* Remove default-enabled modules from golangci-lint config.

Signed-off-by: Ben Kochie <superq@gmail.com>

pgier: Sorry, looks like I caused the new test failures by merging #258.  I think you just have to remove the trailing else block in `proc_fdinfo.go`.

Patch:
diff --git a/.golangci.yml b/.golangci.yml
index 7c4ce1f..0aa09ed 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -1,4 +1,4 @@
+---
 linters:
   enable:
-  - staticcheck
-  - govet
+  - golint
diff --git a/bcache/bcache.go b/bcache/bcache.go
index 1db178c..df724ed 100644
--- a/bcache/bcache.go
+++ b/bcache/bcache.go
@@ -29,7 +29,7 @@ type Stats struct {
 }
 
 // BcacheStats contains statistics tied to a bcache ID.
-type BcacheStats struct {
+type BcacheStats struct { // nolint:golint
 	AverageKeySize        uint64
 	BtreeCacheSize        uint64
 	CacheAvailablePercent uint64
diff --git a/mountinfo.go b/mountinfo.go
index bb01bb5..9471136 100644
--- a/mountinfo.go
+++ b/mountinfo.go
@@ -29,10 +29,10 @@ import (
 // is described in the following man page.
 // http://man7.org/linux/man-pages/man5/proc.5.html
 type MountInfo struct {
-	// Unique Id for the mount
-	MountId int
-	// The Id of the parent mount
-	ParentId int
+	// Unique ID for the mount
+	MountID int
+	// The ID of the parent mount
+	ParentID int
 	// The value of `st_dev` for the files on this FS
 	MajorMinorVer string
 	// The pathname of the directory in the FS that forms
@@ -96,11 +96,11 @@ func parseMountInfoString(mountString string) (*MountInfo, error) {
 		SuperOptions:   mountOptionsParser(mountInfo[mountInfoLength-1]),
 	}
 
-	mount.MountId, err = strconv.Atoi(mountInfo[0])
+	mount.MountID, err = strconv.Atoi(mountInfo[0])
 	if err != nil {
 		return nil, fmt.Errorf("failed to parse mount ID")
 	}
-	mount.ParentId, err = strconv.Atoi(mountInfo[1])
+	mount.ParentID, err = strconv.Atoi(mountInfo[1])
 	if err != nil {
 		return nil, fmt.Errorf("failed to parse parent ID")
 	}
diff --git a/proc_fdinfo.go b/proc_fdinfo.go
index 8737a7f..0c9c402 100644
--- a/proc_fdinfo.go
+++ b/proc_fdinfo.go
@@ -111,9 +111,8 @@ func parseInotifyInfo(line string) (*InotifyInfo, error) {
 			Mask: mask,
 		}
 		return i, nil
-	} else {
-		return nil, errors.New("invalid inode entry: " + line)
 	}
+	return nil, errors.New("invalid inode entry: " + line)
 }
 
 // ProcFDInfos represents a list of ProcFDInfo structs.
diff --git a/proc_status.go b/proc_status.go
index 17b4516..c58346d 100644
--- a/proc_status.go
+++ b/proc_status.go
@@ -33,37 +33,37 @@ type ProcStatus struct {
 	TGID int
 
 	// Peak virtual memory size.
-	VmPeak uint64
+	VmPeak uint64 // nolint:golint
 	// Virtual memory size.
-	VmSize uint64
+	VmSize uint64 // nolint:golint
 	// Locked memory size.
-	VmLck uint64
+	VmLck uint64 // nolint:golint
 	// Pinned memory size.
-	VmPin uint64
+	VmPin uint64 // nolint:golint
 	// Peak resident set size.
-	VmHWM uint64
+	VmHWM uint64 // nolint:golint
 	// Resident set size (sum of RssAnnon RssFile and RssShmem).
-	VmRSS uint64
+	VmRSS uint64 // nolint:golint
 	// Size of resident anonymous memory.
-	RssAnon uint64
+	RssAnon uint64 // nolint:golint
 	// Size of resident file mappings.
-	RssFile uint64
+	RssFile uint64 // nolint:golint
 	// Size of resident shared memory.
-	RssShmem uint64
+	RssShmem uint64 // nolint:golint
 	// Size of data segments.
-	VmData uint64
+	VmData uint64 // nolint:golint
 	// Size of stack segments.
-	VmStk uint64
+	VmStk uint64 // nolint:golint
 	// Size of text segments.
-	VmExe uint64
+	VmExe uint64 // nolint:golint
 	// Shared library code size.
-	VmLib uint64
+	VmLib uint64 // nolint:golint
 	// Page table entries size.
-	VmPTE uint64
+	VmPTE uint64 // nolint:golint
 	// Size of second-level page tables.
-	VmPMD uint64
+	VmPMD uint64 // nolint:golint
 	// Swapped-out virtual memory size by anonymous private.
-	VmSwap uint64
+	VmSwap uint64 // nolint:golint
 	// Size of hugetlb memory portions
 	HugetlbPages uint64
 


Test patch:
diff --git a/iscsi/get_test.go b/iscsi/get_test.go
index a2c24d8..f21b1ab 100644
--- a/iscsi/get_test.go
+++ b/iscsi/get_test.go
@@ -160,45 +160,45 @@ func TestGetStats(t *testing.T) {
 				t.Errorf("unexpected iSCSI iops data :\nwant:\n%v\nhave:\n%v", readTests[i].iops, iops)
 			}
 			if stat.Tpgt[0].Luns[0].Backstore == "rd_mcp" {
-				have_rdmcp, err := sysconfigfs.GetRDMCPPath("119", "ramdisk_lio_1G")
+				haveRdmcp, err := sysconfigfs.GetRDMCPPath("119", "ramdisk_lio_1G")
 				if err != nil {
 					t.Errorf("fail rdmcp error %v", err)
 				}
 				// Name ObjectName
-				want_rdmcp := &iscsi.RDMCP{"rd_mcp_" + stat.Tpgt[0].Luns[0].TypeNumber, stat.Tpgt[0].Luns[0].ObjectName}
+				wantRdmcp := &iscsi.RDMCP{"rd_mcp_" + stat.Tpgt[0].Luns[0].TypeNumber, stat.Tpgt[0].Luns[0].ObjectName}
 
-				if !reflect.DeepEqual(want_rdmcp, have_rdmcp) {
-					t.Errorf("unexpected rdmcp data :\nwant:\n%v\nhave:\n%v", want_rdmcp, have_rdmcp)
+				if !reflect.DeepEqual(wantRdmcp, haveRdmcp) {
+					t.Errorf("unexpected rdmcp data :\nwant:\n%v\nhave:\n%v", wantRdmcp, haveRdmcp)
 				}
 			} else if stat.Tpgt[0].Luns[0].Backstore == "iblock" {
-				have_iblock, err := sysconfigfs.GetIblockUdev("0", "block_lio_rbd1")
+				haveIblock, err := sysconfigfs.GetIblockUdev("0", "block_lio_rbd1")
 				if err != nil {
 					t.Errorf("fail iblock error %v", err)
 				}
 				// Name Bnumber ObjectName Iblock
-				want_iblock := &iscsi.IBLOCK{"iblock_" + stat.Tpgt[0].Luns[0].TypeNumber, stat.Tpgt[0].Luns[0].TypeNumber, stat.Tpgt[0].Luns[0].ObjectName, "/dev/rbd1"}
-				if !reflect.DeepEqual(want_iblock, have_iblock) {
-					t.Errorf("unexpected iblock data :\nwant:\n%v\nhave:\n%v", want_iblock, have_iblock)
+				wantIblock := &iscsi.IBLOCK{"iblock_" + stat.Tpgt[0].Luns[0].TypeNumber, stat.Tpgt[0].Luns[0].TypeNumber, stat.Tpgt[0].Luns[0].ObjectName, "/dev/rbd1"}
+				if !reflect.DeepEqual(wantIblock, haveIblock) {
+					t.Errorf("unexpected iblock data :\nwant:\n%v\nhave:\n%v", wantIblock, haveIblock)
 				}
 			} else if stat.Tpgt[0].Luns[0].Backstore == "fileio" {
-				have_fileio, err := sysconfigfs.GetFileioUdev("1", "file_lio_1G")
+				haveFileIO, err := sysconfigfs.GetFileioUdev("1", "file_lio_1G")
 				if err != nil {
 					t.Errorf("fail fileio error %v", err)
 				}
 				// Name, Fnumber, ObjectName, Filename
-				want_fileio := &iscsi.FILEIO{"fileio_" + stat.Tpgt[0].Luns[0].TypeNumber, stat.Tpgt[0].Luns[0].TypeNumber, "file_lio_1G", "/home/iscsi/file_back_1G"}
-				if !reflect.DeepEqual(want_fileio, have_fileio) {
-					t.Errorf("unexpected fileio data :\nwant:\n%v\nhave:\n%v", want_fileio, have_fileio)
+				wantFileIO := &iscsi.FILEIO{"fileio_" + stat.Tpgt[0].Luns[0].TypeNumber, stat.Tpgt[0].Luns[0].TypeNumber, "file_lio_1G", "/home/iscsi/file_back_1G"}
+				if !reflect.DeepEqual(wantFileIO, haveFileIO) {
+					t.Errorf("unexpected fileio data :\nwant:\n%v\nhave:\n%v", wantFileIO, haveFileIO)
 				}
 			} else if stat.Tpgt[0].Luns[0].Backstore == "rbd" {
-				have_rbd, err := sysconfigfs.GetRBDMatch("0", "iscsi-images-demo")
+				haveRBD, err := sysconfigfs.GetRBDMatch("0", "iscsi-images-demo")
 				if err != nil {
 					t.Errorf("fail rbd error %v", err)
 				}
 				// Name, Rnumber, Pool, Image
-				want_rbd := &iscsi.RBD{"rbd_" + stat.Tpgt[0].Luns[0].TypeNumber, stat.Tpgt[0].Luns[0].TypeNumber, "iscsi-images", "demo"}
-				if !reflect.DeepEqual(want_rbd, have_rbd) {
-					t.Errorf("unexpected fileio data :\nwant:\n%v\nhave:\n%v", want_rbd, have_rbd)
+				wantRBD := &iscsi.RBD{"rbd_" + stat.Tpgt[0].Luns[0].TypeNumber, stat.Tpgt[0].Luns[0].TypeNumber, "iscsi-images", "demo"}
+				if !reflect.DeepEqual(wantRBD, haveRBD) {
+					t.Errorf("unexpected fileio data :\nwant:\n%v\nhave:\n%v", wantRBD, haveRBD)
 				}
 			}
 		}
diff --git a/mountinfo_test.go b/mountinfo_test.go
index 86fe85e..de0ecc1 100644
--- a/mountinfo_test.go
+++ b/mountinfo_test.go
@@ -29,8 +29,8 @@ func TestMountInfo(t *testing.T) {
 			s:       "16 21 0:16 / /sys rw,nosuid,nodev,noexec,relatime shared:7 - sysfs sysfs rw",
 			invalid: false,
 			mount: &MountInfo{
-				MountId:        16,
-				ParentId:       21,
+				MountID:        16,
+				ParentID:       21,
 				MajorMinorVer:  "0:16",
 				Root:           "/",
 				MountPoint:     "/sys",
@@ -50,8 +50,8 @@ func TestMountInfo(t *testing.T) {
 			name: "Tmpfs mounted at /run",
 			s:    "225 20 0:39 / /run/user/112 rw,nosuid,nodev,relatime shared:177 - tmpfs tmpfs rw,size=405096k,mode=700,uid=112,gid=116",
 			mount: &MountInfo{
-				MountId:        225,
-				ParentId:       20,
+				MountID:        225,
+				ParentID:       20,
 				MajorMinorVer:  "0:39",
 				Root:           "/",
 				MountPoint:     "/run/user/112",
@@ -67,8 +67,8 @@ func TestMountInfo(t *testing.T) {
 			name: "Tmpfs mounted at /run, but no optional values",
 			s:    "225 20 0:39 / /run/user/112 rw,nosuid,nodev,relatime  - tmpfs tmpfs rw,size=405096k,mode=700,uid=112,gid=116",
 			mount: &MountInfo{
-				MountId:        225,
-				ParentId:       20,
+				MountID:        225,
+				ParentID:       20,
 				MajorMinorVer:  "0:39",
 				Root:           "/",
 				MountPoint:     "/run/user/112",
@@ -84,8 +84,8 @@ func TestMountInfo(t *testing.T) {
 			name: "Tmpfs mounted at /run, with multiple optional values",
 			s:    "225 20 0:39 / /run/user/112 rw,nosuid,nodev,relatime shared:177 master:8 - tmpfs tmpfs rw,size=405096k,mode=700,uid=112,gid=116",
 			mount: &MountInfo{
-				MountId:        225,
-				ParentId:       20,
+				MountID:        225,
+				ParentID:       20,
 				MajorMinorVer:  "0:39",
 				Root:           "/",
 				MountPoint:     "/run/user/112",
@@ -101,8 +101,8 @@ func TestMountInfo(t *testing.T) {
 			name: "Tmpfs mounted at /run, with a mixture of valid and invalid optional values",
 			s:    "225 20 0:39 / /run/user/112 rw,nosuid,nodev,relatime shared:177 master:8 foo:bar - tmpfs tmpfs rw,size=405096k,mode=700,uid=112,gid=116",
 			mount: &MountInfo{
-				MountId:        225,
-				ParentId:       20,
+				MountID:        225,
+				ParentID:       20,
 				MajorMinorVer:  "0:39",
 				Root:           "/",
 				MountPoint:     "/run/user/112",
@@ -118,8 +118,8 @@ func TestMountInfo(t *testing.T) {
 			name: "CIFS mounted at /with/a-hyphen",
 			s:    "454 29 0:87 / /with/a-hyphen rw,relatime shared:255 - cifs //remote-storage/Path rw,vers=3.1.1,cache=strict,username=user,uid=1000,forceuid,gid=0,noforcegid,addr=127.0.0.1,file_mode=0755,dir_mode=0755,soft,nounix,serverino,mapposix,echo_interval=60,actimeo=1",
 			mount: &MountInfo{
-				MountId:        454,
-				ParentId:       29,
+				MountID:        454,
+				ParentID:       29,
 				MajorMinorVer:  "0:87",
 				Root:           "/",
 				MountPoint:     "/with/a-hyphen",
diff --git a/sysfs/net_class_test.go b/sysfs/net_class_test.go
index 39a7c27..41963db 100644
--- a/sysfs/net_class_test.go
+++ b/sysfs/net_class_test.go
@@ -65,7 +65,7 @@ func TestNetClass(t *testing.T) {
 		linkMode         int64 = 1
 		mtu              int64 = 1500
 		nameAssignType   int64 = 2
-		netDevGroup      int64 = 0
+		netDevGroup      int64
 		speed            int64 = 1000
 		txQueueLen       int64 = 1000
 		netType          int64 = 1