Skip to content

Commit

Permalink
Merge pull request #164 from scop/fix/current-uptodate-version
Browse files Browse the repository at this point in the history
Output current rather than latest version in up-to-date messages
  • Loading branch information
nao1215 authored Jun 27, 2024
2 parents 09a63e3 + 4c28986 commit 4f0f644
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/goutil/goutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (p *Package) SetLatestVer() {
// CurrentToLatestStr returns string about the current version and the latest version
func (p *Package) CurrentToLatestStr() string {
if p.IsAlreadyUpToDate() {
return "Already up-to-date: " + color.GreenString(p.Version.Latest) + " / " + color.GreenString(p.GoVersion.Current)
return "Already up-to-date: " + color.GreenString(p.Version.Current) + " / " + color.GreenString(p.GoVersion.Current)
}
var ret string
if p.Version.Current != p.Version.Latest {
Expand All @@ -96,7 +96,7 @@ func (p *Package) CurrentToLatestStr() string {
// VersionCheckResultStr returns string about command version check.
func (p *Package) VersionCheckResultStr() string {
if p.IsAlreadyUpToDate() {
return "Already up-to-date: " + color.GreenString(p.Version.Latest) + " / " + color.GreenString(p.GoVersion.Current)
return "Already up-to-date: " + color.GreenString(p.Version.Current) + " / " + color.GreenString(p.GoVersion.Current)
}
var ret string
// TODO: yellow only if latest > current
Expand Down
73 changes: 73 additions & 0 deletions internal/goutil/goutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"os"
"path/filepath"
"regexp"
"runtime"
"strings"
"testing"
Expand Down Expand Up @@ -673,6 +674,30 @@ func TestGoPaths_StartDryRunMode_fail_if_key_not_set(t *testing.T) {
// Type: Package
// ----------------------------------------------------------------------------

func TestPackage_CurrentToLatestStr_up_to_date(t *testing.T) {
pkgInfo := Package{
Name: "foo",
ImportPath: "github.com/dummy_name/dummy",
ModulePath: "github.com/dummy_name/dummy/foo",
Version: &Version{
Current: "v1.42.2",
Latest: "v1.9.1",
},
GoVersion: &Version{
Current: "go1.22.4",
Latest: "go1.22.4",
},
}

// Assert to contain the expected message
wantContain := "up-to-date: v1.42.2"
got := pkgInfo.CurrentToLatestStr()

if !strings.Contains(got, wantContain) {
t.Errorf("got: %v, want: %v", got, wantContain)
}
}

func TestPackage_CurrentToLatestStr_not_up_to_date(t *testing.T) {
pkgInfo := Package{
Name: "foo",
Expand All @@ -697,6 +722,30 @@ func TestPackage_CurrentToLatestStr_not_up_to_date(t *testing.T) {
}
}

func TestPackage_VersionCheckResultStr_up_to_date(t *testing.T) {
pkgInfo := Package{
Name: "foo",
ImportPath: "github.com/dummy_name/dummy",
ModulePath: "github.com/dummy_name/dummy/foo",
Version: &Version{
Current: "v2.5.0",
Latest: "v1.9.1",
},
GoVersion: &Version{
Current: "go1.22.4",
Latest: "go1.22.4",
},
}

// Assert to contain the expected message
wantContain := "up-to-date: v2.5.0"
got := pkgInfo.VersionCheckResultStr()

if !strings.Contains(got, wantContain) {
t.Errorf("got: %v, want: %v", got, wantContain)
}
}

func TestPackage_VersionCheckResultStr_not_up_to_date(t *testing.T) {
pkgInfo := Package{
Name: "foo",
Expand All @@ -721,6 +770,30 @@ func TestPackage_VersionCheckResultStr_not_up_to_date(t *testing.T) {
}
}

func TestPackage_VersionCheckResultStr_go_up_to_date(t *testing.T) {
pkgInfo := Package{
Name: "foo",
ImportPath: "github.com/dummy_name/dummy",
ModulePath: "github.com/dummy_name/dummy/foo",
Version: &Version{
Current: "v1.9.1",
Latest: "v1.9.1",
},
GoVersion: &Version{
Current: "go1.99.9",
Latest: "go1.22.4",
},
}

// Assert to contain the expected message
wantContain := regexp.MustCompile(`up-to-date:.* go1\.99\.9`)
got := pkgInfo.VersionCheckResultStr()

if !wantContain.MatchString(got) {
t.Errorf("got: %v, want: %v", got, wantContain)
}
}

func TestPackage_VersionCheckResultStr_go_not_up_to_date(t *testing.T) {
pkgInfo := Package{
Name: "foo",
Expand Down

0 comments on commit 4f0f644

Please sign in to comment.