From 1d4ccd598f32459730deca0d39fcd0f92bcc15b8 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 20 Dec 2023 15:08:09 -0300 Subject: [PATCH] fix: ioutil and other lint issues removes deprecated usage of package ioutil, and fixes some other smaller lint issues. --- file_types_test.go | 8 ++------ rpm_test.go | 7 +++---- tar.go | 4 +--- tar_test.go | 4 +--- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/file_types_test.go b/file_types_test.go index 76f4c79..ee11d55 100644 --- a/file_types_test.go +++ b/file_types_test.go @@ -5,9 +5,7 @@ import ( ) func TestFileTypeSetting(t *testing.T) { - f := &RPMFile{ - Name: "Test", - } + f := &RPMFile{} if f.Type != GenericFile { t.Error("New RPMFile.Type should be a generic type") @@ -20,9 +18,7 @@ func TestFileTypeSetting(t *testing.T) { } func TestFileTypeCombining(t *testing.T) { - f := &RPMFile{ - Name: "Test", - } + f := &RPMFile{} f.Type |= ConfigFile | NoReplaceFile diff --git a/rpm_test.go b/rpm_test.go index 5713b12..d5c285d 100644 --- a/rpm_test.go +++ b/rpm_test.go @@ -2,7 +2,6 @@ package rpmpack import ( "io" - "io/ioutil" "reflect" "testing" @@ -29,7 +28,7 @@ func TestFileOwner(t *testing.T) { Owner: user, }) - if err := r.Write(ioutil.Discard); err != nil { + if err := r.Write(io.Discard); err != nil { t.Errorf("NewRPM returned error %v", err) } if r.fileowners[0] != user { @@ -52,7 +51,7 @@ func Test100644(t *testing.T) { Mode: 0100644, }) - if err := r.Write(ioutil.Discard); err != nil { + if err := r.Write(io.Discard); err != nil { t.Errorf("Write returned error %v", err) } if r.filemodes[0] != 0100644 { @@ -173,7 +172,7 @@ func TestAllowListDirs(t *testing.T) { r.AllowListDirs(map[string]bool{"/usr/local/dir1": true}) - if err := r.Write(ioutil.Discard); err != nil { + if err := r.Write(io.Discard); err != nil { t.Errorf("NewRPM returned error %v", err) } expected := map[string]RPMFile{"/usr/local/dir1": {Name: "/usr/local/dir1", Mode: 040000}} diff --git a/tar.go b/tar.go index dc40e10..6e21591 100644 --- a/tar.go +++ b/tar.go @@ -18,13 +18,11 @@ import ( "archive/tar" "fmt" "io" - "io/ioutil" "path" ) // FromTar reads a tar file and creates an rpm stuct. func FromTar(inp io.Reader, md RPMMetaData) (*RPM, error) { - r, err := NewRPM(md) if err != nil { return nil, fmt.Errorf("failed to create RPM structure: %w", err) @@ -45,7 +43,7 @@ func FromTar(inp io.Reader, md RPMMetaData) (*RPM, error) { body = []byte(h.Linkname) h.Mode |= 0120000 case tar.TypeReg: - b, err := ioutil.ReadAll(t) + b, err := io.ReadAll(t) if err != nil { return nil, fmt.Errorf("failed to read file (%q): %w", h.Name, err) } diff --git a/tar_test.go b/tar_test.go index 6c51457..e144b16 100644 --- a/tar_test.go +++ b/tar_test.go @@ -18,7 +18,6 @@ import ( "archive/tar" "bytes" "io" - "io/ioutil" "testing" "github.com/google/go-cmp/cmp" @@ -67,7 +66,6 @@ func createTar(t *testing.T) io.Reader { } func TestFromTar(t *testing.T) { - testCases := []struct { name string input io.Reader @@ -86,7 +84,7 @@ func TestFromTar(t *testing.T) { if err != nil { t.Errorf("FromTar returned err: %v", err) } - if err := r.Write(ioutil.Discard); err != nil { + if err := r.Write(io.Discard); err != nil { t.Errorf("r.Write() returned err: %v", err) } if r == nil {