Ensure that the upgraded version is really greater
This commit is contained in:
1
go.mod
1
go.mod
@@ -5,5 +5,6 @@ go 1.16
|
||||
require (
|
||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
|
||||
github.com/spf13/cobra v1.3.0
|
||||
golang.org/x/mod v0.5.1
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
|
||||
)
|
||||
|
2
go.sum
2
go.sum
@@ -387,6 +387,8 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
|
||||
golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
|
||||
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
|
@@ -9,6 +9,8 @@ import (
|
||||
"os"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"golang.org/x/mod/semver"
|
||||
)
|
||||
|
||||
var exe, _ = os.Executable()
|
||||
@@ -62,15 +64,17 @@ func CheckLatestVersion() (string, []Asset, error) {
|
||||
return "", nil, errors.New("No release found")
|
||||
}
|
||||
|
||||
// if the current version is the same as the latest version, don't update
|
||||
if Version == release.TagName {
|
||||
fmt.Println("You are using the latest version")
|
||||
return "", nil, errors.New("You are using the latest version")
|
||||
// compare the current version, if the current version is the same or lower than the latest version, don't update
|
||||
versions := []string{Version, release.TagName}
|
||||
semver.Sort(versions)
|
||||
if versions[1] == Version {
|
||||
return "", nil, errors.New("Current version is the latest version")
|
||||
}
|
||||
|
||||
return release.TagName, release.Assets, nil
|
||||
}
|
||||
|
||||
// DownloadLatestVersion will download the latest version of katenary.
|
||||
func DownloadLatestVersion(assets []Asset) error {
|
||||
// Download the latest version
|
||||
fmt.Println("Downloading the latest version...")
|
||||
@@ -118,6 +122,7 @@ func DownloadLatestVersion(assets []Asset) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// DownloadFile will download a url to a local file. It also ensure that the file is executable.
|
||||
func DownloadFile(url, exe string) error {
|
||||
// Download the url binary to exe path
|
||||
resp, err := http.Get(url)
|
||||
|
@@ -34,3 +34,19 @@ func TestDownloadLatestRelease(t *testing.T) {
|
||||
t.Errorf("Error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAlreadyUpToDate(t *testing.T) {
|
||||
Version = "99999.999.99"
|
||||
exe = "/tmp/test-katenary"
|
||||
defer os.Remove(exe)
|
||||
|
||||
// Call the version check
|
||||
version, _, err := CheckLatestVersion()
|
||||
|
||||
if err == nil {
|
||||
t.Errorf("Error: %s", err)
|
||||
}
|
||||
|
||||
t.Log("Version is already the most recent", version)
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user