From f1fa3ba0f065db34f413b9172b074be7b1857793 Mon Sep 17 00:00:00 2001 From: Derek Smart Date: Tue, 15 Nov 2022 09:10:18 -0500 Subject: [PATCH 1/6] update base to go 1.19 Signed-off-by: Derek Smart --- go.mod | 4 ++-- go.sum | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index c68878d..e6948dd 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,12 @@ module package-manager -go 1.18 +go 1.19 require ( github.com/google/go-github/v39 v39.2.0 github.com/hashicorp/go-version v1.6.0 github.com/spf13/cobra v1.6.1 + github.com/vifraa/gopom v0.2.1 golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f ) @@ -14,7 +15,6 @@ require ( github.com/google/go-querystring v1.1.0 // indirect github.com/inconshreveable/mousetrap v1.0.1 // indirect github.com/spf13/pflag v1.0.5 // indirect - github.com/vifraa/gopom v0.2.1 // indirect golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect golang.org/x/net v0.0.0-20210716203947-853a461950ff // indirect google.golang.org/appengine v1.6.7 // indirect diff --git a/go.sum b/go.sum index ff9e590..2fab0e9 100644 --- a/go.sum +++ b/go.sum @@ -40,6 +40,7 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= @@ -117,6 +118,7 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= @@ -127,6 +129,7 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/vifraa/gopom v0.2.1 h1:MYVMAMyiGzXPPy10EwojzKIL670kl5Zbae+o3fFvQEM= github.com/vifraa/gopom v0.2.1/go.mod h1:oPa1dcrGrtlO37WPDBm5SqHAT+wTgF8An1Q71Z6Vv4o= @@ -384,6 +387,7 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From b49223605ce782d1badb8abf0eebad2976cae797 Mon Sep 17 00:00:00 2001 From: Derek Smart Date: Tue, 15 Nov 2022 09:19:02 -0500 Subject: [PATCH 2/6] update workflows to go 1.19 Signed-off-by: Derek Smart --- .github/workflows/nightly-e2e-tests.yml | 2 +- .github/workflows/nightly-update-packages.yml | 2 +- .github/workflows/pull-request.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/nightly-e2e-tests.yml b/.github/workflows/nightly-e2e-tests.yml index a8272da..bd64197 100644 --- a/.github/workflows/nightly-e2e-tests.yml +++ b/.github/workflows/nightly-e2e-tests.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/setup-go@v2 with: - go-version: '^1.16.0' + go-version: '^1.19.0' - name: Setup GO environment run: | diff --git a/.github/workflows/nightly-update-packages.yml b/.github/workflows/nightly-update-packages.yml index 82341fe..3a6fe7f 100644 --- a/.github/workflows/nightly-update-packages.yml +++ b/.github/workflows/nightly-update-packages.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/setup-go@v2 with: - go-version: '^1.16.0' + go-version: '^1.19.0' - name: Setup GO environment run: | diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 003349a..d2d3d12 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -11,7 +11,7 @@ jobs: - uses: actions/setup-go@v2 with: - go-version: '^1.16.0' + go-version: '^1.19.0' - name: Setup GO environment run: | From 034decccd4995958a5cf048e78ebeca3ce4654b9 Mon Sep 17 00:00:00 2001 From: Derek Smart Date: Tue, 15 Nov 2022 09:39:41 -0500 Subject: [PATCH 3/6] replace ioutil ReadDir method Signed-off-by: Derek Smart --- internal/app/utils/IOUtils.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 internal/app/utils/IOUtils.go diff --git a/internal/app/utils/IOUtils.go b/internal/app/utils/IOUtils.go new file mode 100644 index 0000000..75d0a3f --- /dev/null +++ b/internal/app/utils/IOUtils.go @@ -0,0 +1,22 @@ +package utils + +import ( + "io/fs" + "os" + "sort" +) + +// ReadDir replace deprecated ioutil package +func ReadDir(dirname string) ([]fs.FileInfo, error) { + f, err := os.Open(dirname) + if err != nil { + return nil, err + } + list, err := f.Readdir(-1) + f.Close() + if err != nil { + return nil, err + } + sort.Slice(list, func(i, j int) bool { return list[i].Name() < list[j].Name() }) + return list, nil +} From 17c5f08f3437f1369189ebfc0a45a2817aa425bf Mon Sep 17 00:00:00 2001 From: Derek Smart Date: Tue, 15 Nov 2022 09:42:44 -0500 Subject: [PATCH 4/6] remove deprecated ioutil package Signed-off-by: Derek Smart --- internal/app/App.go | 29 ++++++++++--------- internal/app/commands/root.go | 8 ++--- internal/app/commands/update.go | 4 +-- internal/app/dependencies/Dependencies.go | 19 ++++++------ .../app/dependencies/dependencies_test.go | 14 ++++----- internal/app/packages/Version.go | 19 ++++++------ internal/app/packages/package_test.go | 4 +-- internal/app/packages/packages_test.go | 22 +++++++------- internal/app/packages/version_test.go | 6 ++-- internal/app/utils/Http.go | 12 ++++---- internal/app/utils/{IOUtils.go => IO.go} | 0 11 files changed, 68 insertions(+), 69 deletions(-) rename internal/app/utils/{IOUtils.go => IO.go} (100%) diff --git a/internal/app/App.go b/internal/app/App.go index b337ac3..6fedde4 100644 --- a/internal/app/App.go +++ b/internal/app/App.go @@ -4,34 +4,35 @@ import ( _ "embed" // Embed Import for Package Files "encoding/json" "io/fs" - "io/ioutil" "os" "package-manager/internal/app/errors" "package-manager/internal/app/packages" + "package-manager/internal/app/utils" ) //go:embed "VERSION" var version string -//PackagesJSON is embedded for first time run +// PackagesJSON is embedded for first time run +// //go:embed "packages.json" var PackagesJSON []byte -//PackageFile exported for overwrite +// PackageFile exported for overwrite var PackageFile = "packages.json" -//Classpath exported for overwrite +// Classpath exported for overwrite var Classpath string -//ClasspathFiles exported for overwrite +// ClasspathFiles exported for overwrite var ClasspathFiles []fs.FileInfo -//Version output from embedded file +// Version output from embedded file func Version() string { return version } -//SetClasspath to switch between global and local modules +// SetClasspath to switch between global and local modules func SetClasspath(global bool, globalpath string, globalpathFiles []fs.FileInfo) { if global { Classpath = globalpath @@ -42,25 +43,25 @@ func SetClasspath(global bool, globalpath string, globalpathFiles []fs.FileInfo) errors.Exit(err.Error(), 1) } Classpath = pwd + "/liquibase_libs/" - ClasspathFiles, _ = ioutil.ReadDir(Classpath) + ClasspathFiles, _ = utils.ReadDir(Classpath) } } -//PackagesInClassPath is the packages.json file in global classpath +// PackagesInClassPath is the packages.json file in global classpath func PackagesInClassPath(cp string) bool { _, err := os.Stat(cp + PackageFile) return err == nil } -//CopyPackagesToClassPath install packages.json to global classpath +// CopyPackagesToClassPath install packages.json to global classpath func CopyPackagesToClassPath(cp string, p []byte) { - err := ioutil.WriteFile(cp+PackageFile, p, 0664) + err := os.WriteFile(cp+PackageFile, p, 0664) if err != nil { errors.Exit(err.Error(), 1) } } -//LoadPackages get packages from bytes from file +// LoadPackages get packages from bytes from file func LoadPackages(b []byte) packages.Packages { var e packages.Packages err := json.Unmarshal(b, &e) @@ -70,7 +71,7 @@ func LoadPackages(b []byte) packages.Packages { return e } -//WritePackages write packages back to file +// WritePackages write packages back to file func WritePackages(p packages.Packages) { b, err := json.MarshalIndent(p, "", " ") if err != nil { @@ -80,7 +81,7 @@ func WritePackages(p packages.Packages) { if err != nil { errors.Exit(err.Error(), 1) } - err = ioutil.WriteFile(pwd+"/internal/app/packages.json", b, 0664) + err = os.WriteFile(pwd+"/internal/app/packages.json", b, 0664) if err != nil { errors.Exit(err.Error(), 1) } diff --git a/internal/app/commands/root.go b/internal/app/commands/root.go index c232174..ef921af 100644 --- a/internal/app/commands/root.go +++ b/internal/app/commands/root.go @@ -2,8 +2,8 @@ package commands import ( "github.com/spf13/cobra" + "io" "io/fs" - "io/ioutil" "os" "package-manager/internal/app" "package-manager/internal/app/errors" @@ -27,12 +27,12 @@ var rootCmd = &cobra.Command{ Search for, install, and uninstall liquibase drivers, extensions, and utilities.`, } -//Execute main entry point for CLI +// Execute main entry point for CLI func Execute(cp string, s string) { var err error liquibase = utils.LoadLiquibase(cp) globalpath = liquibase.Homepath + "lib" + s - globalpathFiles, err = ioutil.ReadDir(globalpath) + globalpathFiles, err = utils.ReadDir(globalpath) if err != nil { errors.Exit(err.Error(), 1) } @@ -62,7 +62,7 @@ func initConfig() { if err != nil { errors.Exit(err.Error(), 1) } - b, _ := ioutil.ReadAll(jsonFile) + b, _ := io.ReadAll(jsonFile) //Load Bytes to Packages packs = app.LoadPackages(b) diff --git a/internal/app/commands/update.go b/internal/app/commands/update.go index 61eb576..c522594 100644 --- a/internal/app/commands/update.go +++ b/internal/app/commands/update.go @@ -3,7 +3,7 @@ package commands import ( "fmt" "github.com/spf13/cobra" - "io/ioutil" + "io" "os" "package-manager/internal/app" "package-manager/internal/app/errors" @@ -33,7 +33,7 @@ var updateCmd = &cobra.Command{ if err != nil { errors.Exit(err.Error(), 1) } - bytes, err = ioutil.ReadAll(file) + bytes, err = io.ReadAll(file) if err != nil { errors.Exit(err.Error(), 1) } diff --git a/internal/app/dependencies/Dependencies.go b/internal/app/dependencies/Dependencies.go index b78b612..7f91e2c 100644 --- a/internal/app/dependencies/Dependencies.go +++ b/internal/app/dependencies/Dependencies.go @@ -2,12 +2,11 @@ package dependencies import ( "encoding/json" - "io/ioutil" "os" "package-manager/internal/app/errors" ) -//FileLocation exported for testing overwrite +// FileLocation exported for testing overwrite var FileLocation string func init() { @@ -18,12 +17,12 @@ func init() { FileLocation = pwd + "/liquibase.json" } -//Dependencies main wrapper for liquibase.json objects +// Dependencies main wrapper for liquibase.json objects type Dependencies struct { Dependencies []Dependency `json:"dependencies"` } -//CreateFile init liquibase.json file in pwd +// CreateFile init liquibase.json file in pwd func (d Dependencies) CreateFile() { file, err := os.Create(FileLocation) if err != nil { @@ -33,19 +32,19 @@ func (d Dependencies) CreateFile() { d.Write() } -//Write dump contents to liquibase.json +// Write dump contents to liquibase.json func (d Dependencies) Write() { file, err := json.MarshalIndent(d, "", " ") if err != nil { errors.Exit(err.Error(), 1) } - err = ioutil.WriteFile(FileLocation, file, 0664) + err = os.WriteFile(FileLocation, file, 0664) if err != nil { errors.Exit(err.Error(), 1) } } -//Read get contents from liquibase.json +// Read get contents from liquibase.json func (d *Dependencies) Read() { file, _ := os.Open(FileLocation) defer file.Close() @@ -55,17 +54,17 @@ func (d *Dependencies) Read() { } } -//FileExists does the liquibase.json file exist +// FileExists does the liquibase.json file exist func (d Dependencies) FileExists() bool { _, err := os.Stat(FileLocation) return err == nil } -//Remove remove specific dependency from group +// Remove remove specific dependency from group func (d *Dependencies) Remove(n string) { for i, m := range d.Dependencies { if m.GetName() == n { d.Dependencies = append(d.Dependencies[:i], d.Dependencies[i+1:]...) } } -} \ No newline at end of file +} diff --git a/internal/app/dependencies/dependencies_test.go b/internal/app/dependencies/dependencies_test.go index 0de5d3f..2b04fb6 100644 --- a/internal/app/dependencies/dependencies_test.go +++ b/internal/app/dependencies/dependencies_test.go @@ -1,7 +1,7 @@ package dependencies import ( - "io/ioutil" + "os" "os/exec" "path/filepath" "reflect" @@ -21,13 +21,13 @@ func TestDependencies_CreateFile(t *testing.T) { d.CreateFile() _, file := filepath.Split(FileLocation) if file != "liquibase.json" { - t.Fatalf("Expected %s but got %s", "liquibase.json", file ) + t.Fatalf("Expected %s but got %s", "liquibase.json", file) } } func TestDependencies_FileExists(t *testing.T) { if d.FileExists() != true { - t.Fatalf( "Unable to verify liquibase.json file exists." ) + t.Fatalf("Unable to verify liquibase.json file exists.") } } @@ -35,7 +35,7 @@ func TestDependencies_Write(t *testing.T) { d.Dependencies = append(d.Dependencies, Dependency{"package": "tag"}) d.Write() - file, _ := ioutil.ReadFile(FileLocation) + file, _ := os.ReadFile(FileLocation) content := `{ "dependencies": [ { @@ -44,7 +44,7 @@ func TestDependencies_Write(t *testing.T) { ] }` if string(file) != content { - t.Fatalf( "Unable to verify liquibase.json json contents." ) + t.Fatalf("Unable to verify liquibase.json json contents.") } } @@ -66,7 +66,7 @@ func TestDependencies_Read(t *testing.T) { func TestDependencies_Remove(t *testing.T) { d.Remove("package") - if len(d.Dependencies) != 0 { - t.Fatalf( "Unable to remove dependency" ) + if len(d.Dependencies) != 0 { + t.Fatalf("Unable to remove dependency") } } diff --git a/internal/app/packages/Version.go b/internal/app/packages/Version.go index 7581b39..7fa9882 100644 --- a/internal/app/packages/Version.go +++ b/internal/app/packages/Version.go @@ -7,7 +7,6 @@ import ( "fmt" "io" "io/fs" - "io/ioutil" "os" "package-manager/internal/app/errors" "package-manager/internal/app/utils" @@ -15,7 +14,7 @@ import ( "strings" ) -//Version struct +// Version struct type Version struct { Tag string `json:"tag"` Path string `json:"path"` @@ -24,13 +23,13 @@ type Version struct { LiquibaseCore string `json:"liquibaseCore"` } -//GetFilename from version +// GetFilename from version func (v Version) GetFilename() string { _, f := filepath.Split(v.Path) return f } -//InClassPath version is installed in classpath +// InClassPath version is installed in classpath func (v Version) InClassPath(files []fs.FileInfo) bool { r := false for _, f := range files { @@ -41,12 +40,12 @@ func (v Version) InClassPath(files []fs.FileInfo) bool { return r } -//PathIsHTTP remote or local file path +// PathIsHTTP remote or local file path func (v Version) PathIsHTTP() bool { return strings.HasPrefix(v.Path, "http") } -//CopyToClassPath install local version to classpath +// CopyToClassPath install local version to classpath func (v Version) CopyToClassPath(cp string) { if !ClasspathExists(cp) { createClasspath(cp) @@ -56,7 +55,7 @@ func (v Version) CopyToClassPath(cp string) { errors.Exit("Unable to open "+v.Path, 1) } defer source.Close() - b, err := ioutil.ReadAll(source) + b, err := io.ReadAll(source) if err != nil { errors.Exit(err.Error(), 1) } @@ -88,7 +87,7 @@ func (v Version) calcChecksum(b []byte) string { return r } -//DownloadToClassPath install remote version to classpath +// DownloadToClassPath install remote version to classpath func (v Version) DownloadToClassPath(cp string) { if !ClasspathExists(cp) { createClasspath(cp) @@ -103,12 +102,12 @@ func (v Version) DownloadToClassPath(cp string) { writeToDestination(cp+v.GetFilename(), body, v.GetFilename()) } -//createClasspath creates a proper directory at the specified location +// createClasspath creates a proper directory at the specified location func createClasspath(cp string) error { return os.Mkdir(cp, 0775) } -//ClasspathExists checks to see if classpath directory is created +// ClasspathExists checks to see if classpath directory is created func ClasspathExists(cp string) bool { _, err := os.Stat(cp) return err == nil diff --git a/internal/app/packages/package_test.go b/internal/app/packages/package_test.go index dea61d4..aa68332 100644 --- a/internal/app/packages/package_test.go +++ b/internal/app/packages/package_test.go @@ -3,8 +3,8 @@ package packages import ( "github.com/hashicorp/go-version" "io/fs" - "io/ioutil" "os/exec" + "package-manager/internal/app/utils" "reflect" "strings" "testing" @@ -171,7 +171,7 @@ func TestPackage_GetInstalledVersion(t *testing.T) { } rootPath, _ := exec.Command("git", "rev-parse", "--show-toplevel").Output() - var files, _ = ioutil.ReadDir(strings.TrimRight(string(rootPath), "\n") + "/tests/mocks/installed") + var files, _ = utils.ReadDir(strings.TrimRight(string(rootPath), "\n") + "/tests/mocks/installed") tests := []struct { name string diff --git a/internal/app/packages/packages_test.go b/internal/app/packages/packages_test.go index 7ec2df4..bd10c1c 100644 --- a/internal/app/packages/packages_test.go +++ b/internal/app/packages/packages_test.go @@ -2,8 +2,8 @@ package packages import ( "io/fs" - "io/ioutil" "os/exec" + "package-manager/internal/app/utils" "reflect" "strings" "testing" @@ -23,19 +23,19 @@ func TestPackages_FilterByCategory(t *testing.T) { }{ { name: "Can Filter by Driver", - ps: ps, + ps: ps, args: args{"driver"}, want: []Package{driver}, }, { name: "Can Filter by Extension", - ps: ps, + ps: ps, args: args{"extension"}, want: []Package{extension}, }, { name: "Can Filter by Pro", - ps: ps, + ps: ps, args: args{"pro"}, want: []Package{pro}, }, @@ -73,7 +73,7 @@ func TestPackages_GetByName(t *testing.T) { }, { name: "Can Get Package (Pro) by Name", - ps: ps, + ps: ps, args: args{"pro"}, want: pro, }, @@ -93,8 +93,8 @@ func TestPackages_Display(t *testing.T) { } rootPath, _ := exec.Command("git", "rev-parse", "--show-toplevel").Output() - var installed, _ = ioutil.ReadDir(strings.TrimRight(string(rootPath), "\n") + "/tests/mocks/installed") - var files, _ = ioutil.ReadDir(strings.TrimRight(string(rootPath), "\n") + "/tests/mocks/classpath") + var installed, _ = utils.ReadDir(strings.TrimRight(string(rootPath), "\n") + "/tests/mocks/installed") + var files, _ = utils.ReadDir(strings.TrimRight(string(rootPath), "\n") + "/tests/mocks/classpath") tests := []struct { name string @@ -104,7 +104,7 @@ func TestPackages_Display(t *testing.T) { }{ { name: "Can Display Installed Formatted Lists", - ps: ps, + ps: ps, args: args{installed}, want: []string{ " Package Category", @@ -115,9 +115,9 @@ func TestPackages_Display(t *testing.T) { }, { name: "Can Display Uninstalled Formatted Lists", - ps: ps, + ps: ps, args: args{files}, - want : []string{ + want: []string{ " Package Category", "├── driver driver", "├── extension extension", @@ -132,4 +132,4 @@ func TestPackages_Display(t *testing.T) { } }) } -} \ No newline at end of file +} diff --git a/internal/app/packages/version_test.go b/internal/app/packages/version_test.go index aff8b01..7501f2d 100644 --- a/internal/app/packages/version_test.go +++ b/internal/app/packages/version_test.go @@ -2,9 +2,9 @@ package packages import ( "io/fs" - "io/ioutil" "os" "os/exec" + "package-manager/internal/app/utils" "strings" "testing" ) @@ -69,7 +69,7 @@ func init() { func TestVersion_CopyToClassPath(t *testing.T) { extensionV1.Path = testPath + "/tests/mocks/files/extension-0.0.2.txt" extensionV1.CopyToClassPath(testPath + "/tests/mocks/classpath/") - var files, _ = ioutil.ReadDir(testPath + "/tests/mocks/classpath/") + var files, _ = utils.ReadDir(testPath + "/tests/mocks/classpath/") if files[1].Name() != "extension-0.0.2.txt" { t.Fatalf("Expected %s but got %s", "extension-0.0.2.txt", files[0].Name()) @@ -112,7 +112,7 @@ func TestVersion_InClassPath(t *testing.T) { files []fs.FileInfo } - var files, _ = ioutil.ReadDir(testPath + "/tests/mocks/installed") + var files, _ = utils.ReadDir(testPath + "/tests/mocks/installed") tests := []struct { name string diff --git a/internal/app/utils/Http.go b/internal/app/utils/Http.go index cf43011..fac7d16 100644 --- a/internal/app/utils/Http.go +++ b/internal/app/utils/Http.go @@ -1,15 +1,15 @@ package utils import ( - "io/ioutil" + "io" "net/http" "package-manager/internal/app/errors" ) -//HTTPUtil struct -type HTTPUtil struct {} +// HTTPUtil struct +type HTTPUtil struct{} -//Get contencts from URL as bytes +// Get contencts from URL as bytes func (h HTTPUtil) Get(url string) []byte { client := http.Client{ CheckRedirect: func(r *http.Request, via []*http.Request) error { @@ -19,11 +19,11 @@ func (h HTTPUtil) Get(url string) []byte { } r, err := client.Get(url) if err != nil { - errors.Exit("Unable to download from " + url, 1) + errors.Exit("Unable to download from "+url, 1) } defer r.Body.Close() - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { errors.Exit(err.Error(), 1) } diff --git a/internal/app/utils/IOUtils.go b/internal/app/utils/IO.go similarity index 100% rename from internal/app/utils/IOUtils.go rename to internal/app/utils/IO.go From b577a07e5bac0b81a607b4fba04f5497de6eaf95 Mon Sep 17 00:00:00 2001 From: Derek Smart Date: Tue, 15 Nov 2022 09:43:40 -0500 Subject: [PATCH 5/6] bump version for release Signed-off-by: Derek Smart --- VERSION | 2 +- internal/app/VERSION | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index a1e1395..341cf11 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.7 \ No newline at end of file +0.2.0 \ No newline at end of file diff --git a/internal/app/VERSION b/internal/app/VERSION index a1e1395..341cf11 100644 --- a/internal/app/VERSION +++ b/internal/app/VERSION @@ -1 +1 @@ -0.1.7 \ No newline at end of file +0.2.0 \ No newline at end of file From fc5c7be6ddbe8067fbdc0033edbd9d49616f151f Mon Sep 17 00:00:00 2001 From: Derek Smart Date: Tue, 15 Nov 2022 09:50:06 -0500 Subject: [PATCH 6/6] add support for darwin arm64 Signed-off-by: Derek Smart --- Makefile | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 6851fa2..24151ca 100644 --- a/Makefile +++ b/Makefile @@ -2,25 +2,29 @@ VERSION=`cat $(PWD)/VERSION` VEXRUN_FILE := $(PWD)/utils/vexrun.jar VEXRUN := java -jar $(VEXRUN_FILE) -.PHONY: build darwin windows linux rpi s390x +.PHONY: build darwin_amd64 darwin_arm64 windows linux_amd64 linux_arm64 s390x -release: updateVersion darwin windows linux rpi s390x +release: updateVersion darwin_amd64 darwin_arm64 windows linux_amd64 linux_arm64 s390x windows: GOOS=windows GOARCH=amd64 go build -o $(PWD)/bin/windows/lpm.exe $(PWD)/cmd/lpm/windows.go cd $(PWD)/bin/windows && zip lpm-$(VERSION)-windows.zip lpm.exe -darwin: - GOOS=darwin GOARCH=amd64 go build -o $(PWD)/bin/darwin/lpm $(PWD)/cmd/lpm/darwin.go - cd $(PWD)/bin/darwin && zip lpm-$(VERSION)-darwin.zip lpm +darwin_amd64: + GOOS=darwin GOARCH=amd64 go build -o $(PWD)/bin/darwin_amd64/lpm $(PWD)/cmd/lpm/darwin.go + cd $(PWD)/bin/darwin_amd64 && zip lpm-$(VERSION)-darwin.zip lpm -linux: - GOOS=linux GOARCH=amd64 GOARM=7 go build -o $(PWD)/bin/linux/lpm $(PWD)/cmd/lpm/darwin.go - cd $(PWD)/bin/linux && zip lpm-$(VERSION)-linux.zip lpm +darwin_arm64: + GOOS=darwin GOARCH=arm64 go build -o $(PWD)/bin/darwin_arm64/lpm $(PWD)/cmd/lpm/darwin.go + cd $(PWD)/bin/darwin_arm64 && zip lpm-$(VERSION)-darwin-arm64.zip lpm -rpi: - GOOS=linux GOARCH=arm64 GOARM=7 go build -o $(PWD)/bin/rpi/lpm $(PWD)/cmd/lpm/darwin.go - cd $(PWD)/bin/rpi && zip lpm-$(VERSION)-rpi.zip lpm +linux_amd64: + GOOS=linux GOARCH=amd64 GOARM=7 go build -o $(PWD)/bin/linux_amd64/lpm $(PWD)/cmd/lpm/darwin.go + cd $(PWD)/bin/linux_amd64 && zip lpm-$(VERSION)-linux.zip lpm + +linux_arm64: + GOOS=linux GOARCH=arm64 GOARM=7 go build -o $(PWD)/bin/linux_arm64/lpm $(PWD)/cmd/lpm/darwin.go + cd $(PWD)/bin/linux_arm64 && zip lpm-$(VERSION)-linux-arm64.zip lpm s390x: GOOS=linux GOARCH=s390x go build -o $(PWD)/bin/s390x/lpm $(PWD)/cmd/lpm/darwin.go