Skip to content

Commit

Permalink
Merge pull request #39 from yulog/replace-ioutil
Browse files Browse the repository at this point in the history
replace ioutil
  • Loading branch information
Songmu authored Aug 30, 2024
2 parents e7f3bd9 + d6ec64c commit 481fdef
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
3 changes: 1 addition & 2 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"compress/flate"
"compress/gzip"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -128,7 +127,7 @@ func (bdr *builder) build() (string, error) {
pkg, bdr.platform.os, bdr.platform.arch, string(bs))
}
}
files, err := ioutil.ReadDir(workDir)
files, err := os.ReadDir(workDir)
if err != nil {
return "", err
}
Expand Down
12 changes: 6 additions & 6 deletions cli_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package goxz

import (
"io/ioutil"
"io"
"os"
"reflect"
"sort"
Expand All @@ -10,7 +10,7 @@ import (
)

func setup(t *testing.T) string {
tmpd, err := ioutil.TempDir("", "goxz-")
tmpd, err := os.MkdirTemp("", "goxz-")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -92,7 +92,7 @@ func TestCliRun(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
cl := &cli{outStream: ioutil.Discard, errStream: ioutil.Discard}
cl := &cli{outStream: io.Discard, errStream: io.Discard}
tmpd := setup(t)
defer os.RemoveAll(tmpd)
args := append([]string{"-d=" + tmpd}, tc.input...)
Expand All @@ -108,7 +108,7 @@ func TestCliRun(t *testing.T) {
t.Errorf("%s: error should be contains %q, but %q", tc.name, tc.errStr, err)
}
}
files, err := ioutil.ReadDir(tmpd)
files, err := os.ReadDir(tmpd)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -140,7 +140,7 @@ func TestCliRun_projDir(t *testing.T) {
"goxz_0.1.1_freebsd_arm64.tar.gz",
}

cl := &cli{outStream: ioutil.Discard, errStream: ioutil.Discard}
cl := &cli{outStream: io.Discard, errStream: io.Discard}
tmpd := setup(t)
// This deletion process is performed to check whether goxz itself creates
// a directory correctly
Expand All @@ -156,7 +156,7 @@ func TestCliRun_projDir(t *testing.T) {
t.Errorf("error should be nil but: %s", err)
}

files, err := ioutil.ReadDir(tmpd)
files, err := os.ReadDir(tmpd)
if err != nil {
t.Fatal(err)
}
Expand Down
7 changes: 3 additions & 4 deletions goxz.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package goxz
import (
"context"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -44,7 +43,7 @@ func (gx *goxz) run() error {
return err
}

gx.workDir, err = ioutil.TempDir(gx.dest, ".goxz-")
gx.workDir, err = os.MkdirTemp(gx.dest, ".goxz-")
if err != nil {
return err
}
Expand Down Expand Up @@ -185,12 +184,12 @@ func (gx *goxz) gatherResources() ([]string, error) {
dir := gx.projDir

var ret []string
files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
if err != nil {
return nil, err
}
for _, f := range files {
if !f.Mode().IsRegular() {
if !f.Type().IsRegular() {
continue
}
n := f.Name()
Expand Down
4 changes: 2 additions & 2 deletions goxz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package goxz
import (
"context"
"flag"
"io/ioutil"
"io"
"path/filepath"
"reflect"
"sort"
"testing"
)

func TestRun_help(t *testing.T) {
err := Run(context.Background(), []string{"-h"}, ioutil.Discard, ioutil.Discard)
err := Run(context.Background(), []string{"-h"}, io.Discard, io.Discard)
if err != flag.ErrHelp {
t.Errorf("somthing went wrong: %s", err)
}
Expand Down

0 comments on commit 481fdef

Please sign in to comment.