Skip to content

Commit

Permalink
Enable golint tests (prometheus#268)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
SuperQ authored Feb 26, 2020
1 parent 056510d commit f98e067
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 56 deletions.
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
linters:
enable:
- staticcheck
- govet
- golint
2 changes: 1 addition & 1 deletion bcache/bcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions iscsi/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions mountinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down
24 changes: 12 additions & 12 deletions mountinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions proc_fdinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
32 changes: 16 additions & 16 deletions proc_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion sysfs/net_class_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f98e067

Please sign in to comment.