Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output current rather than latest version in up-to-date messages #164

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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