diff --git a/.github/workflows/go-check.yml b/.github/workflows/go-check.yml index 25e1afde5..251f7faa9 100644 --- a/.github/workflows/go-check.yml +++ b/.github/workflows/go-check.yml @@ -11,12 +11,12 @@ jobs: env: RUNGOGENERATE: false steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: recursive - - uses: actions/setup-go@v2 + - uses: actions/setup-go@v3 with: - go-version: "1.18.x" + go-version: "1.19.x" - name: Run repo-specific setup uses: ./.github/actions/go-check-setup if: hashFiles('./.github/actions/go-check-setup') != '' @@ -27,7 +27,7 @@ jobs: echo "RUNGOGENERATE=true" >> $GITHUB_ENV fi - name: Install staticcheck - run: go install honnef.co/go/tools/cmd/staticcheck@d7e217c1ff411395475b2971c0824e1e7cc1af98 # 2022.1 (v0.3.0) + run: go install honnef.co/go/tools/cmd/staticcheck@376210a89477dedbe6fdc4484b233998650d7b3c # 2022.1.3 (v0.3.3) - name: Check that go.mod is tidy uses: protocol/multiple-go-modules@v1.2 with: diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index b86241a96..8a1697b2d 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -10,16 +10,16 @@ jobs: fail-fast: false matrix: os: [ "ubuntu", "windows", "macos" ] - go: [ "1.17.x", "1.18.x" ] + go: [ "1.18.x", "1.19.x" ] env: COVERAGES: "" runs-on: ${{ format('{0}-latest', matrix.os) }} name: ${{ matrix.os }} (go ${{ matrix.go }}) steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: recursive - - uses: actions/setup-go@v2 + - uses: actions/setup-go@v3 with: go-version: ${{ matrix.go }} - name: Go information @@ -43,7 +43,7 @@ jobs: # Use -coverpkg=./..., so that we include cross-package coverage. # If package ./A imports ./B, and ./A's tests also cover ./B, # this means ./B's coverage will be significantly higher than 0%. - run: go test -v -coverprofile=module-coverage.txt -coverpkg=./... ./... + run: go test -v -shuffle=on -coverprofile=module-coverage.txt -coverpkg=./... ./... - name: Run tests (32 bit) if: ${{ matrix.os != 'macos' }} # can't run 32 bit tests on OSX. uses: protocol/multiple-go-modules@v1.2 @@ -52,7 +52,7 @@ jobs: with: run: | export "PATH=${{ env.PATH_386 }}:$PATH" - go test -v ./... + go test -v -shuffle=on ./... - name: Run tests with race detector if: ${{ matrix.os == 'ubuntu' }} # speed things up. Windows and OSX VMs are slow uses: protocol/multiple-go-modules@v1.2 @@ -62,7 +62,7 @@ jobs: shell: bash run: echo "COVERAGES=$(find . -type f -name 'module-coverage.txt' | tr -s '\n' ',' | sed 's/,$//')" >> $GITHUB_ENV - name: Upload coverage to Codecov - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 with: files: '${{ env.COVERAGES }}' env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }} diff --git a/go.mod b/go.mod index e71c7029b..4a99ae192 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -go 1.17 +go 1.18 module github.com/ipfs/go-ipfs-api diff --git a/mfs_test.go b/mfs_test.go index bb1cf7326..ff8ec4c8e 100644 --- a/mfs_test.go +++ b/mfs_test.go @@ -4,7 +4,7 @@ import ( "bytes" "context" "fmt" - "io/ioutil" + "io" "os" "testing" @@ -144,7 +144,7 @@ func TestFilesRead(t *testing.T) { reader, err := s.FilesRead(context.Background(), "/testdata/readme", FilesRead.Offset(0), FilesRead.Count(5)) is.Nil(err) - resBytes, err := ioutil.ReadAll(reader) + resBytes, err := io.ReadAll(reader) is.Nil(err) is.Equal(string(resBytes), "Hello") } @@ -153,7 +153,7 @@ func TestFilesRm(t *testing.T) { is := is.New(t) s := NewShell(shellUrl) - file, _ := ioutil.ReadFile("./testdata/ping") + file, _ := os.ReadFile("./testdata/ping") err := s.FilesWrite(context.Background(), "/testdata/dir1/ping", bytes.NewBuffer(file), FilesWrite.Parents(true), FilesWrite.Create(true)) is.Nil(err) @@ -185,7 +185,7 @@ func TestFilesWrite(t *testing.T) { is := is.New(t) s := NewShell(shellUrl) - file, err := ioutil.ReadFile("./testdata/ping") + file, err := os.ReadFile("./testdata/ping") is.Nil(err) err = s.FilesWrite(context.Background(), "/testdata/ping", bytes.NewBuffer(file), FilesWrite.Create(true), FilesWrite.RawLeaves(true), FilesWrite.CidVersion(1), FilesWrite.Hash("sha3-256")) @@ -194,11 +194,11 @@ func TestFilesWrite(t *testing.T) { reader, err := s.FilesRead(context.Background(), "/testdata/ping") is.Nil(err) - resBytes, err := ioutil.ReadAll(reader) + resBytes, err := io.ReadAll(reader) is.Nil(err) is.Equal(string(resBytes), "ipfs") - file, err = ioutil.ReadFile("./testdata/ping") + file, err = os.ReadFile("./testdata/ping") is.Nil(err) err = s.FilesWrite(context.Background(), "/testdata/ping", bytes.NewBuffer(file), FilesWrite.Offset(0), FilesWrite.Count(2), FilesWrite.Truncate(true)) @@ -207,7 +207,10 @@ func TestFilesWrite(t *testing.T) { reader, err = s.FilesRead(context.Background(), "/testdata/ping") is.Nil(err) - resBytes, err = ioutil.ReadAll(reader) + resBytes, err = io.ReadAll(reader) is.Nil(err) is.Equal(string(resBytes), "ip") + + err = s.FilesRm(context.Background(), "/testdata/ping", true) + is.Nil(err) } diff --git a/request.go b/request.go index 7d3a72fd0..0df70238d 100644 --- a/request.go +++ b/request.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/url" "os" @@ -70,7 +69,7 @@ type Response struct { func (r *Response) Close() error { if r.Output != nil { // always drain output (response body) - _, err1 := io.Copy(ioutil.Discard, r.Output) + _, err1 := io.Copy(io.Discard, r.Output) err2 := r.Output.Close() if err1 != nil { return err1 @@ -147,7 +146,7 @@ func (r *Request) Send(c *http.Client) (*Response, error) { case resp.StatusCode == http.StatusNotFound: e.Message = "command not found" case contentType == "text/plain": - out, err := ioutil.ReadAll(resp.Body) + out, err := io.ReadAll(resp.Body) if err != nil { fmt.Fprintf(os.Stderr, "ipfs-shell: warning! response (%d) read error: %s\n", resp.StatusCode, err) } @@ -158,7 +157,7 @@ func (r *Request) Send(c *http.Client) (*Response, error) { } default: fmt.Fprintf(os.Stderr, "ipfs-shell: warning! unhandled response (%d) encoding: %s", resp.StatusCode, contentType) - out, err := ioutil.ReadAll(resp.Body) + out, err := io.ReadAll(resp.Body) if err != nil { fmt.Fprintf(os.Stderr, "ipfs-shell: response (%d) read error: %s\n", resp.StatusCode, err) } @@ -168,7 +167,7 @@ func (r *Request) Send(c *http.Client) (*Response, error) { nresp.Output = nil // drain body and close - io.Copy(ioutil.Discard, resp.Body) + io.Copy(io.Discard, resp.Body) resp.Body.Close() } diff --git a/shell.go b/shell.go index e2b0e503a..155b150ab 100644 --- a/shell.go +++ b/shell.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net" gohttp "net/http" "os" @@ -55,7 +54,7 @@ func NewLocalShell() *Shell { return nil } - api, err := ioutil.ReadFile(apiFile) + api, err := os.ReadFile(apiFile) if err != nil { return nil } @@ -145,7 +144,8 @@ type IdOutput struct { // ID gets information about a given peer. Arguments: // // peer: peer.ID of the node to look up. If no peer is specified, -// return information about the local peer. +// +// return information about the local peer. func (s *Shell) ID(peer ...string) (*IdOutput, error) { if len(peer) > 1 { return nil, fmt.Errorf("too many peer arguments") @@ -460,7 +460,7 @@ func (s *Shell) BlockGet(path string) ([]byte, error) { return nil, resp.Error } - return ioutil.ReadAll(resp.Output) + return io.ReadAll(resp.Output) } func (s *Shell) BlockPut(block []byte, format, mhtype string, mhlen int) (string, error) { diff --git a/shell_test.go b/shell_test.go index 5b3f62a33..1c742faa5 100644 --- a/shell_test.go +++ b/shell_test.go @@ -7,7 +7,6 @@ import ( "crypto/md5" "fmt" "io" - "io/ioutil" "math/rand" "net" "net/http" @@ -465,7 +464,7 @@ func TestNewShellWithUnixSocket(t *testing.T) { is := is.New(t) // setup uds temporary dir - path, err := ioutil.TempDir("", "uds-test") + path, err := os.MkdirTemp("", "uds-test") is.Nil(err) defer os.RemoveAll(path) diff --git a/tests/main.go b/tests/main.go index 7784a95c1..5beb1393f 100644 --- a/tests/main.go +++ b/tests/main.go @@ -6,7 +6,7 @@ import ( "math/rand" "time" - "github.com/ipfs/go-ipfs-api" + shell "github.com/ipfs/go-ipfs-api" u "github.com/ipfs/go-ipfs-util" )