diff --git a/.travis.yml b/.travis.yml index d4173b8..51f3490 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ go: - "1.12" - "1.13" - "1.14" + - "1.17" env: - GO111MODULE=on before_install: diff --git a/cmd/goversioninfo/main.go b/cmd/goversioninfo/main.go index 74e30df..a1f5f93 100644 --- a/cmd/goversioninfo/main.go +++ b/cmd/goversioninfo/main.go @@ -6,7 +6,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "log" "os" @@ -81,7 +80,7 @@ func main() { } // Read the config file. - jsonBytes, err := ioutil.ReadAll(input) + jsonBytes, err := io.ReadAll(input) input.Close() if err != nil { log.Printf("Error reading %q: %v", configFile, err) diff --git a/go.mod b/go.mod index 3840882..0fd970a 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,14 @@ module github.com/josephspurrier/goversioninfo -go 1.12 +go 1.17 require ( github.com/akavel/rsrc v0.10.2 github.com/stretchr/testify v1.6.1 ) + +require ( + github.com/davecgh/go-spew v1.1.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect +) diff --git a/goversioninfo.go b/goversioninfo.go index 42701c0..9b04efb 100644 --- a/goversioninfo.go +++ b/goversioninfo.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "log" "os" "reflect" @@ -230,7 +229,7 @@ func (vi *VersionInfo) WriteSyso(filename string, arch string) error { // WriteHex creates a hex file for debugging version info func (vi *VersionInfo) WriteHex(filename string) error { - return ioutil.WriteFile(filename, vi.Buffer.Bytes(), 0655) + return os.WriteFile(filename, vi.Buffer.Bytes(), 0655) } // WriteGo creates a Go file that contains the version info so you can access diff --git a/goversioninfo_test.go b/goversioninfo_test.go index 43a5cba..cdf42f7 100644 --- a/goversioninfo_test.go +++ b/goversioninfo_test.go @@ -3,7 +3,6 @@ package goversioninfo import ( "bytes" "io" - "io/ioutil" "log" "os" "path/filepath" @@ -29,7 +28,7 @@ func TestFile1(t *testing.T) { func testFile(t *testing.T, filename string) { path, _ := filepath.Abs("./testdata/json/" + filename + ".json") - jsonBytes, err := ioutil.ReadFile(path) + jsonBytes, err := os.ReadFile(path) assert.NoError(t, err) // Create a new container @@ -49,9 +48,9 @@ func testFile(t *testing.T, filename string) { // This is for easily exporting results when the algorithm improves /*path3, _ := filepath.Abs("./testdata/" + filename + ".out") - ioutil.WriteFile(path3, vi.Buffer.Bytes(), 0655)*/ + os.WriteFile(path3, vi.Buffer.Bytes(), 0655)*/ - expected, err := ioutil.ReadFile(path2) + expected, err := os.ReadFile(path2) assert.NoError(t, err) if !bytes.Equal(vi.Buffer.Bytes(), expected) { @@ -59,18 +58,18 @@ func testFile(t *testing.T, filename string) { } // Test the Go file generation. - tmpdir, err := ioutil.TempDir("", "generate_go") + tmpdir, err := os.MkdirTemp("", "generate_go") assert.NoError(t, err) defer os.RemoveAll(tmpdir) path4 := filepath.Join(tmpdir, filename+".go") err = vi.WriteGo(path4, "") assert.NoError(t, err) - gen, err := ioutil.ReadFile(path4) + gen, err := os.ReadFile(path4) assert.NoError(t, err) path5, _ := filepath.Abs("./testdata/gofile/" + filename + ".go") - expected5, err := ioutil.ReadFile(path5) + expected5, err := os.ReadFile(path5) if err != nil { t.Error("Could not load "+path5, err) } @@ -104,7 +103,7 @@ func doTestWrite(t *testing.T, arch string) { path, _ := filepath.Abs("./testdata/json/" + filename + ".json") - jsonBytes, err := ioutil.ReadFile(path) + jsonBytes, err := os.ReadFile(path) assert.NoError(t, err) // Create a new container @@ -120,7 +119,7 @@ func doTestWrite(t *testing.T, arch string) { // Write the data to a buffer vi.Walk() - tmpdir, err := ioutil.TempDir("", "resource") + tmpdir, err := os.MkdirTemp("", "resource") assert.NoError(t, err) defer os.RemoveAll(tmpdir) file := filepath.Join(tmpdir, "resource.syso") @@ -128,7 +127,7 @@ func doTestWrite(t *testing.T, arch string) { err = vi.WriteSyso(file, arch) assert.NoError(t, err) - _, err = ioutil.ReadFile(file) + _, err = os.ReadFile(file) assert.NoError(t, err) } @@ -137,7 +136,7 @@ func TestMalformedJSON(t *testing.T) { path, _ := filepath.Abs("./testdata/json/" + filename + ".json") - jsonBytes, err := ioutil.ReadFile(path) + jsonBytes, err := os.ReadFile(path) assert.NoError(t, err) // Create a new container @@ -154,7 +153,7 @@ func TestIcon(t *testing.T) { path, _ := filepath.Abs("./testdata/json/" + filename + ".json") - jsonBytes, err := ioutil.ReadFile(path) + jsonBytes, err := os.ReadFile(path) assert.NoError(t, err) // Create a new container @@ -173,7 +172,7 @@ func TestIcon(t *testing.T) { // Write the data to a buffer vi.Walk() - tmpdir, err := ioutil.TempDir("", "resource") + tmpdir, err := os.MkdirTemp("", "resource") assert.NoError(t, err) defer os.RemoveAll(tmpdir) file := filepath.Join(tmpdir, "resource.syso") @@ -181,7 +180,7 @@ func TestIcon(t *testing.T) { err = vi.WriteSyso(file, "386") assert.NoError(t, err) - _, err = ioutil.ReadFile(file) + _, err = os.ReadFile(file) assert.NoError(t, err) } @@ -190,7 +189,7 @@ func TestBadIcon(t *testing.T) { path, _ := filepath.Abs("./testdata/json/" + filename + ".json") - jsonBytes, err := ioutil.ReadFile(path) + jsonBytes, err := os.ReadFile(path) assert.NoError(t, err) // Create a new container @@ -209,7 +208,7 @@ func TestBadIcon(t *testing.T) { // Write the data to a buffer vi.Walk() - tmpdir, err := ioutil.TempDir("", "resource") + tmpdir, err := os.MkdirTemp("", "resource") assert.NoError(t, err) defer os.RemoveAll(tmpdir) file := filepath.Join(tmpdir, "resource.syso") @@ -219,7 +218,7 @@ func TestBadIcon(t *testing.T) { t.Errorf("Error is missing because it should throw an error") } - _, err = ioutil.ReadFile(file) + _, err = os.ReadFile(file) if err == nil { t.Error("File should not exist "+file, err) } @@ -230,7 +229,7 @@ func TestTimestamp(t *testing.T) { path, _ := filepath.Abs("./testdata/json/" + filename + ".json") - jsonBytes, err := ioutil.ReadFile(path) + jsonBytes, err := os.ReadFile(path) assert.NoError(t, err) // Create a new container @@ -249,7 +248,7 @@ func TestTimestamp(t *testing.T) { // Write the data to a buffer vi.Walk() - tmpdir, err := ioutil.TempDir("", "resource") + tmpdir, err := os.MkdirTemp("", "resource") assert.NoError(t, err) defer os.RemoveAll(tmpdir) file := filepath.Join(tmpdir, "resource.syso") @@ -257,7 +256,7 @@ func TestTimestamp(t *testing.T) { err = vi.WriteSyso(file, "386") assert.NoError(t, err) - _, err = ioutil.ReadFile(file) + _, err = os.ReadFile(file) assert.NoError(t, err) } @@ -266,7 +265,7 @@ func TestVersionString(t *testing.T) { path, _ := filepath.Abs("./testdata/json/" + filename + ".json") - jsonBytes, err := ioutil.ReadFile(path) + jsonBytes, err := os.ReadFile(path) assert.NoError(t, err) // Create a new container @@ -286,7 +285,7 @@ func TestWriteHex(t *testing.T) { path, _ := filepath.Abs("./testdata/json/" + filename + ".json") - jsonBytes, err := ioutil.ReadFile(path) + jsonBytes, err := os.ReadFile(path) assert.NoError(t, err) // Create a new container @@ -302,7 +301,7 @@ func TestWriteHex(t *testing.T) { // Write the data to a buffer vi.Walk() - tmpdir, err := ioutil.TempDir("", "resource") + tmpdir, err := os.MkdirTemp("", "resource") assert.NoError(t, err) defer os.RemoveAll(tmpdir) file := filepath.Join(tmpdir, "resource.syso") @@ -310,7 +309,7 @@ func TestWriteHex(t *testing.T) { err = vi.WriteHex(file) assert.NoError(t, err) - _, err = ioutil.ReadFile(file) + _, err = os.ReadFile(file) assert.NoError(t, err) } @@ -319,7 +318,7 @@ func testdatatr2Uint32(t *testing.T) { in string out uint32 }{{"0", 0}, {"", 0}, {"FFEF", 65519}, {"\x00\x00", 0}} { - log.SetOutput(ioutil.Discard) + log.SetOutput(io.Discard) got := str2Uint32(tt.in) if got != tt.out { t.Errorf("%q: awaited %d, got %d.", tt.in, tt.out, got) @@ -358,7 +357,7 @@ func TestCharsetID(t *testing.T) { } func TestWriteCoff(t *testing.T) { - tempFh, err := ioutil.TempFile("", "goversioninfo-test-") + tempFh, err := os.CreateTemp("", "goversioninfo-test-") if err != nil { t.Fatalf("temp file: %v", err) } diff --git a/icon_test.go b/icon_test.go index 37550ec..43dc0c1 100644 --- a/icon_test.go +++ b/icon_test.go @@ -1,7 +1,6 @@ package goversioninfo import ( - "io/ioutil" "os" "path/filepath" "runtime" @@ -11,7 +10,7 @@ import ( func TestIconReleaseFileHandle(t *testing.T) { icoPath := "testdata/resource/icon.ico" icoPath2 := "testdata/resource/icon2.ico" - tmpdir, err := ioutil.TempDir("", "resource") + tmpdir, err := os.MkdirTemp("", "resource") if err != nil { t.Error("Could not create temp dir", err) }