Skip to content

Commit

Permalink
ci(lint): ensure io/ioutil replacement (#1525)
Browse files Browse the repository at this point in the history
* ci(lint): enure ioutil replacement

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>

* Update host_solaris.go
* Update process_linux_test.go
* Update net_linux_test.go
* Update net_linux_test.go
* Update process_test.go
* Update process_linux_test.go
* Update process_linux_test.go

---------

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
  • Loading branch information
mmorel-35 committed Sep 12, 2023
1 parent 0e9f133 commit c806740
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 35 deletions.
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
with:
go-version: 1.17
cache: false
- name: Checkout repository
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- name: Setup golangci-lint
Expand Down
47 changes: 27 additions & 20 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
issues:
max-same-issues: 0
exclude-rules:
- linters:
- gosec
text: "G204"
- linters:
- revive
text: "var-naming"
- linters:
- revive
text: "exported"
- linters:
- revive
text: "empty-block"
- linters:
- revive
text: "unused-parameter"
exclude-rules:
- linters:
- gosec
text: "G204"
- linters:
- revive
text: "var-naming"
- linters:
- revive
text: "exported"
- linters:
- revive
text: "empty-block"
- linters:
- revive
text: "unused-parameter"
linters:
enable:
- asciicheck
Expand All @@ -26,6 +26,7 @@ linters:
- gofmt
- gofumpt
- goimports
- gomodguard
- gosec
- gosimple
- importas
Expand All @@ -46,10 +47,16 @@ linters:
- structcheck
- unused
- varcheck

linters-settings:
gci:
sections:
- standard
- default
- prefix(github.com/shirou)
- standard
- default
- prefix(github.com/shirou)
gomodguard:
blocked:
modules:
- io/ioutil:
recommandations:
- io
- os
3 changes: 1 addition & 2 deletions host/host_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/csv"
"fmt"
"io"
"io/ioutil"
"os"
"regexp"
"strconv"
Expand Down Expand Up @@ -60,7 +59,7 @@ func HostIDWithContext(ctx context.Context) (string, error) {

// Count number of processes based on the number of entries in /proc
func numProcs(ctx context.Context) (uint64, error) {
dirs, err := ioutil.ReadDir("/proc")
dirs, err := os.ReadDir("/proc")
if err != nil {
return 0, err
}
Expand Down
5 changes: 2 additions & 3 deletions net/net_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package net
import (
"context"
"fmt"
"io/ioutil"
"net"
"os"
"strings"
Expand All @@ -17,7 +16,7 @@ import (

func TestIOCountersByFileParsing(t *testing.T) {
// Prpare a temporary file, which will be read during the test
tmpfile, err := ioutil.TempFile("", "proc_dev_net")
tmpfile, err := os.CreateTemp("", "proc_dev_net")
defer os.Remove(tmpfile.Name()) // clean up

assert.Nil(t, err, "Temporary file creation failed: ", err)
Expand Down Expand Up @@ -195,7 +194,7 @@ func TestReverse(t *testing.T) {
}

func TestConntrackStatFileParsing(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "proc_net_stat_conntrack")
tmpfile, err := os.CreateTemp("", "proc_net_stat_conntrack")
defer os.Remove(tmpfile.Name())
assert.Nil(t, err, "Temporary file creation failed: ", err)

Expand Down
9 changes: 4 additions & 5 deletions process/process_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package process
import (
"context"
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -58,7 +57,7 @@ func Test_Process_splitProcStat(t *testing.T) {
}

func Test_Process_splitProcStat_fromFile(t *testing.T) {
pids, err := ioutil.ReadDir("testdata/linux/")
pids, err := os.ReadDir("testdata/linux/")
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -94,7 +93,7 @@ func Test_Process_splitProcStat_fromFile(t *testing.T) {
}

func Test_fillFromCommWithContext(t *testing.T) {
pids, err := ioutil.ReadDir("testdata/linux/")
pids, err := os.ReadDir("testdata/linux/")
if err != nil {
t.Error(err)
}
Expand All @@ -115,7 +114,7 @@ func Test_fillFromCommWithContext(t *testing.T) {
}

func Test_fillFromStatusWithContext(t *testing.T) {
pids, err := ioutil.ReadDir("testdata/linux/")
pids, err := os.ReadDir("testdata/linux/")
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -154,7 +153,7 @@ func Benchmark_fillFromStatusWithContext(b *testing.B) {
}

func Test_fillFromTIDStatWithContext_lx_brandz(t *testing.T) {
pids, err := ioutil.ReadDir("testdata/lx_brandz/")
pids, err := os.ReadDir("testdata/lx_brandz/")
if err != nil {
t.Error(err)
}
Expand Down
9 changes: 4 additions & 5 deletions process/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"os"
"os/exec"
Expand Down Expand Up @@ -303,7 +302,7 @@ func Test_Process_Name(t *testing.T) {
}

func Test_Process_Long_Name_With_Spaces(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "")
tmpdir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatalf("unable to create temp dir %v", err)
}
Expand Down Expand Up @@ -349,7 +348,7 @@ func Test_Process_Long_Name_With_Spaces(t *testing.T) {
}

func Test_Process_Long_Name(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "")
tmpdir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatalf("unable to create temp dir %v", err)
}
Expand Down Expand Up @@ -406,7 +405,7 @@ func Test_Process_Name_Against_Python(t *testing.T) {
t.Skipf("psutil not found for %s: %s", py3Path, out)
}

tmpdir, err := ioutil.TempDir("", "")
tmpdir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatalf("unable to create temp dir %v", err)
}
Expand Down Expand Up @@ -775,7 +774,7 @@ func Test_IsRunning(t *testing.T) {
}

func Test_Process_Environ(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "")
tmpdir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatalf("unable to create temp dir %v", err)
}
Expand Down

0 comments on commit c806740

Please sign in to comment.