Skip to content

Commit

Permalink
Merge pull request #855 from mmorel-35/linters
Browse files Browse the repository at this point in the history
enable durationcheck,  predeclared, unconvert, unused and wastedassign linters
  • Loading branch information
dcbw authored Mar 27, 2023
2 parents 16d05ec + 2fb0efe commit 8813bfe
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 34 deletions.
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ issues:
linters:
enable:
- contextcheck
- durationcheck
- gci
- gocritic
- gofumpt
- gosimple
- ineffassign
- misspell
- nonamedreturns
- predeclared
- revive
- staticcheck
- unconvert
- unused
- wastedassign
disable:
- errcheck

Expand Down
2 changes: 1 addition & 1 deletion pkg/testutils/echo/echo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ var _ = Describe("Echosvr", func() {
It("connects successfully using echo client", func() {
Eventually(session.Out).Should(gbytes.Say("\n"))
serverAddress := strings.TrimSpace(string(session.Out.Contents()))
fmt.Println("Server address", string(serverAddress))
fmt.Println("Server address", serverAddress)

cmd := exec.Command(clientBinaryPath, "-target", serverAddress, "-message", "hello")
clientSession, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
Expand Down
2 changes: 1 addition & 1 deletion plugins/main/bridge/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func (tc testCase) createCheckCmdArgs(targetNS ns.NetNS, config *Net) *skel.CmdA
ContainerID: fmt.Sprintf("dummy-%d", counter),
Netns: targetNS.Path(),
IfName: IFNAME,
StdinData: []byte(conf),
StdinData: conf,
}
}

Expand Down
12 changes: 6 additions & 6 deletions plugins/meta/bandwidth/ifb_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,19 @@ func createTBF(rateInBits, burstInBits uint64, linkIndex int) error {
}
rateInBytes := rateInBits / 8
burstInBytes := burstInBits / 8
bufferInBytes := buffer(uint64(rateInBytes), uint32(burstInBytes))
bufferInBytes := buffer(rateInBytes, uint32(burstInBytes))
latency := latencyInUsec(latencyInMillis)
limitInBytes := limit(uint64(rateInBytes), latency, uint32(burstInBytes))
limitInBytes := limit(rateInBytes, latency, uint32(burstInBytes))

qdisc := &netlink.Tbf{
QdiscAttrs: netlink.QdiscAttrs{
LinkIndex: linkIndex,
Handle: netlink.MakeHandle(1, 0),
Parent: netlink.HANDLE_ROOT,
},
Limit: uint32(limitInBytes),
Rate: uint64(rateInBytes),
Buffer: uint32(bufferInBytes),
Limit: limitInBytes,
Rate: rateInBytes,
Buffer: bufferInBytes,
}
err := netlink.QdiscAdd(qdisc)
if err != nil {
Expand All @@ -147,7 +147,7 @@ func createTBF(rateInBits, burstInBits uint64, linkIndex int) error {
}

func time2Tick(time uint32) uint32 {
return uint32(float64(time) * float64(netlink.TickInUsec()))
return uint32(float64(time) * netlink.TickInUsec())
}

func buffer(rate uint64, burst uint32) uint32 {
Expand Down
20 changes: 10 additions & 10 deletions plugins/meta/bandwidth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,9 @@ func cmdCheck(args *skel.CmdArgs) error {
if bandwidth.IngressRate > 0 && bandwidth.IngressBurst > 0 {
rateInBytes := bandwidth.IngressRate / 8
burstInBytes := bandwidth.IngressBurst / 8
bufferInBytes := buffer(uint64(rateInBytes), uint32(burstInBytes))
bufferInBytes := buffer(rateInBytes, uint32(burstInBytes))
latency := latencyInUsec(latencyInMillis)
limitInBytes := limit(uint64(rateInBytes), latency, uint32(burstInBytes))
limitInBytes := limit(rateInBytes, latency, uint32(burstInBytes))

qdiscs, err := SafeQdiscList(link)
if err != nil {
Expand All @@ -312,13 +312,13 @@ func cmdCheck(args *skel.CmdArgs) error {
if !isTbf {
break
}
if tbf.Rate != uint64(rateInBytes) {
if tbf.Rate != rateInBytes {
return fmt.Errorf("Rate doesn't match")
}
if tbf.Limit != uint32(limitInBytes) {
if tbf.Limit != limitInBytes {
return fmt.Errorf("Limit doesn't match")
}
if tbf.Buffer != uint32(bufferInBytes) {
if tbf.Buffer != bufferInBytes {
return fmt.Errorf("Buffer doesn't match")
}
}
Expand All @@ -327,9 +327,9 @@ func cmdCheck(args *skel.CmdArgs) error {
if bandwidth.EgressRate > 0 && bandwidth.EgressBurst > 0 {
rateInBytes := bandwidth.EgressRate / 8
burstInBytes := bandwidth.EgressBurst / 8
bufferInBytes := buffer(uint64(rateInBytes), uint32(burstInBytes))
bufferInBytes := buffer(rateInBytes, uint32(burstInBytes))
latency := latencyInUsec(latencyInMillis)
limitInBytes := limit(uint64(rateInBytes), latency, uint32(burstInBytes))
limitInBytes := limit(rateInBytes, latency, uint32(burstInBytes))

ifbDeviceName := getIfbDeviceName(bwConf.Name, args.ContainerID)

Expand All @@ -351,13 +351,13 @@ func cmdCheck(args *skel.CmdArgs) error {
if !isTbf {
break
}
if tbf.Rate != uint64(rateInBytes) {
if tbf.Rate != rateInBytes {
return fmt.Errorf("Rate doesn't match")
}
if tbf.Limit != uint32(limitInBytes) {
if tbf.Limit != limitInBytes {
return fmt.Errorf("Limit doesn't match")
}
if tbf.Buffer != uint32(bufferInBytes) {
if tbf.Buffer != bufferInBytes {
return fmt.Errorf("Buffer doesn't match")
}
}
Expand Down
16 changes: 8 additions & 8 deletions plugins/meta/firewall/firewall_firewalld_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func spawnSessionDbus(wg *sync.WaitGroup) (string, *exec.Cmd) {
// Wait for dbus-daemon to print the bus address
bytes, err := bufio.NewReader(stdout).ReadString('\n')
Expect(err).NotTo(HaveOccurred())
busAddr := strings.TrimSpace(string(bytes))
busAddr := strings.TrimSpace(bytes)
Expect(strings.HasPrefix(busAddr, "unix:abstract")).To(BeTrue())

var startWg sync.WaitGroup
Expand Down Expand Up @@ -197,9 +197,9 @@ var _ = Describe("firewalld test", func() {
ContainerID: "dummy",
Netns: targetNs.Path(),
IfName: ifname,
StdinData: []byte(conf),
StdinData: conf,
}
_, _, err := testutils.CmdAdd(targetNs.Path(), args.ContainerID, ifname, []byte(conf), func() error {
_, _, err := testutils.CmdAdd(targetNs.Path(), args.ContainerID, ifname, conf, func() error {
return cmdAdd(args)
})
Expect(err).NotTo(HaveOccurred())
Expand All @@ -223,9 +223,9 @@ var _ = Describe("firewalld test", func() {
ContainerID: "dummy",
Netns: targetNs.Path(),
IfName: ifname,
StdinData: []byte(conf),
StdinData: conf,
}
_, _, err := testutils.CmdAdd(targetNs.Path(), args.ContainerID, ifname, []byte(conf), func() error {
_, _, err := testutils.CmdAdd(targetNs.Path(), args.ContainerID, ifname, conf, func() error {
return cmdAdd(args)
})
Expect(err).NotTo(HaveOccurred())
Expand All @@ -241,9 +241,9 @@ var _ = Describe("firewalld test", func() {
ContainerID: "dummy",
Netns: targetNs.Path(),
IfName: ifname,
StdinData: []byte(conf),
StdinData: conf,
}
r, _, err := testutils.CmdAdd(targetNs.Path(), args.ContainerID, ifname, []byte(conf), func() error {
r, _, err := testutils.CmdAdd(targetNs.Path(), args.ContainerID, ifname, conf, func() error {
return cmdAdd(args)
})
Expect(err).NotTo(HaveOccurred())
Expand All @@ -265,7 +265,7 @@ var _ = Describe("firewalld test", func() {
ContainerID: "dummy",
Netns: targetNs.Path(),
IfName: ifname,
StdinData: []byte(conf),
StdinData: conf,
}
r, _, err := testutils.CmdAddWithArgs(args, func() error {
return cmdAdd(args)
Expand Down
2 changes: 1 addition & 1 deletion plugins/meta/tuning/tuning.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func restoreBackup(ifName, containerID, backupPath string) error {
}

config := configToRestore{}
if err = json.Unmarshal([]byte(file), &config); err != nil {
if err = json.Unmarshal(file, &config); err != nil {
return nil
}

Expand Down
12 changes: 6 additions & 6 deletions plugins/meta/tuning/tuning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ var _ = Describe("tuning plugin", func() {

if testutils.SpecVersionHasCHECK(ver) {
n := &TuningConf{}
err = json.Unmarshal([]byte(conf), &n)
err = json.Unmarshal(conf, &n)
Expect(err).NotTo(HaveOccurred())

_, confString, err := buildOneConfig("testConfig", ver, n, r)
Expand Down Expand Up @@ -395,7 +395,7 @@ var _ = Describe("tuning plugin", func() {

if testutils.SpecVersionHasCHECK(ver) {
n := &TuningConf{}
err = json.Unmarshal([]byte(conf), &n)
err = json.Unmarshal(conf, &n)
Expect(err).NotTo(HaveOccurred())

_, confString, err := buildOneConfig("testConfig", ver, n, r)
Expand Down Expand Up @@ -541,7 +541,7 @@ var _ = Describe("tuning plugin", func() {

if testutils.SpecVersionHasCHECK(ver) {
n := &TuningConf{}
err = json.Unmarshal([]byte(conf), &n)
err = json.Unmarshal(conf, &n)
Expect(err).NotTo(HaveOccurred())

_, confString, err := buildOneConfig("testConfig", ver, n, r)
Expand Down Expand Up @@ -687,7 +687,7 @@ var _ = Describe("tuning plugin", func() {

if testutils.SpecVersionHasCHECK(ver) {
n := &TuningConf{}
err = json.Unmarshal([]byte(conf), &n)
err = json.Unmarshal(conf, &n)
Expect(err).NotTo(HaveOccurred())

_, confString, err := buildOneConfig("testConfig", ver, n, r)
Expand Down Expand Up @@ -839,7 +839,7 @@ var _ = Describe("tuning plugin", func() {

if testutils.SpecVersionHasCHECK(ver) {
n := &TuningConf{}
err = json.Unmarshal([]byte(conf), &n)
err = json.Unmarshal(conf, &n)
Expect(err).NotTo(HaveOccurred())

_, confString, err := buildOneConfig("testConfig", ver, n, r)
Expand Down Expand Up @@ -918,7 +918,7 @@ var _ = Describe("tuning plugin", func() {

if testutils.SpecVersionHasCHECK(ver) {
n := &TuningConf{}
err = json.Unmarshal([]byte(conf), &n)
err = json.Unmarshal(conf, &n)
Expect(err).NotTo(HaveOccurred())

_, confString, err := buildOneConfig("testConfig", ver, n, r)
Expand Down
2 changes: 1 addition & 1 deletion plugins/meta/vrf/vrf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ var _ = Describe("vrf plugin", func() {
defer GinkgoRecover()
cniVersion := "0.4.0"
n := &VRFNetConf{}
err = json.Unmarshal([]byte(conf), &n)
err = json.Unmarshal(conf, &n)
_, confString, err := buildOneConfig("testConfig", cniVersion, n, prevRes)
Expect(err).NotTo(HaveOccurred())

Expand Down

0 comments on commit 8813bfe

Please sign in to comment.