Skip to content

Commit 4f0f644

Browse files
authored
Merge pull request #164 from scop/fix/current-uptodate-version
Output current rather than latest version in up-to-date messages
2 parents 09a63e3 + 4c28986 commit 4f0f644

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

internal/goutil/goutil.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (p *Package) SetLatestVer() {
7878
// CurrentToLatestStr returns string about the current version and the latest version
7979
func (p *Package) CurrentToLatestStr() string {
8080
if p.IsAlreadyUpToDate() {
81-
return "Already up-to-date: " + color.GreenString(p.Version.Latest) + " / " + color.GreenString(p.GoVersion.Current)
81+
return "Already up-to-date: " + color.GreenString(p.Version.Current) + " / " + color.GreenString(p.GoVersion.Current)
8282
}
8383
var ret string
8484
if p.Version.Current != p.Version.Latest {
@@ -96,7 +96,7 @@ func (p *Package) CurrentToLatestStr() string {
9696
// VersionCheckResultStr returns string about command version check.
9797
func (p *Package) VersionCheckResultStr() string {
9898
if p.IsAlreadyUpToDate() {
99-
return "Already up-to-date: " + color.GreenString(p.Version.Latest) + " / " + color.GreenString(p.GoVersion.Current)
99+
return "Already up-to-date: " + color.GreenString(p.Version.Current) + " / " + color.GreenString(p.GoVersion.Current)
100100
}
101101
var ret string
102102
// TODO: yellow only if latest > current

internal/goutil/goutil_test.go

+73
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"os"
77
"path/filepath"
8+
"regexp"
89
"runtime"
910
"strings"
1011
"testing"
@@ -673,6 +674,30 @@ func TestGoPaths_StartDryRunMode_fail_if_key_not_set(t *testing.T) {
673674
// Type: Package
674675
// ----------------------------------------------------------------------------
675676

677+
func TestPackage_CurrentToLatestStr_up_to_date(t *testing.T) {
678+
pkgInfo := Package{
679+
Name: "foo",
680+
ImportPath: "github.com/dummy_name/dummy",
681+
ModulePath: "github.com/dummy_name/dummy/foo",
682+
Version: &Version{
683+
Current: "v1.42.2",
684+
Latest: "v1.9.1",
685+
},
686+
GoVersion: &Version{
687+
Current: "go1.22.4",
688+
Latest: "go1.22.4",
689+
},
690+
}
691+
692+
// Assert to contain the expected message
693+
wantContain := "up-to-date: v1.42.2"
694+
got := pkgInfo.CurrentToLatestStr()
695+
696+
if !strings.Contains(got, wantContain) {
697+
t.Errorf("got: %v, want: %v", got, wantContain)
698+
}
699+
}
700+
676701
func TestPackage_CurrentToLatestStr_not_up_to_date(t *testing.T) {
677702
pkgInfo := Package{
678703
Name: "foo",
@@ -697,6 +722,30 @@ func TestPackage_CurrentToLatestStr_not_up_to_date(t *testing.T) {
697722
}
698723
}
699724

725+
func TestPackage_VersionCheckResultStr_up_to_date(t *testing.T) {
726+
pkgInfo := Package{
727+
Name: "foo",
728+
ImportPath: "github.com/dummy_name/dummy",
729+
ModulePath: "github.com/dummy_name/dummy/foo",
730+
Version: &Version{
731+
Current: "v2.5.0",
732+
Latest: "v1.9.1",
733+
},
734+
GoVersion: &Version{
735+
Current: "go1.22.4",
736+
Latest: "go1.22.4",
737+
},
738+
}
739+
740+
// Assert to contain the expected message
741+
wantContain := "up-to-date: v2.5.0"
742+
got := pkgInfo.VersionCheckResultStr()
743+
744+
if !strings.Contains(got, wantContain) {
745+
t.Errorf("got: %v, want: %v", got, wantContain)
746+
}
747+
}
748+
700749
func TestPackage_VersionCheckResultStr_not_up_to_date(t *testing.T) {
701750
pkgInfo := Package{
702751
Name: "foo",
@@ -721,6 +770,30 @@ func TestPackage_VersionCheckResultStr_not_up_to_date(t *testing.T) {
721770
}
722771
}
723772

773+
func TestPackage_VersionCheckResultStr_go_up_to_date(t *testing.T) {
774+
pkgInfo := Package{
775+
Name: "foo",
776+
ImportPath: "github.com/dummy_name/dummy",
777+
ModulePath: "github.com/dummy_name/dummy/foo",
778+
Version: &Version{
779+
Current: "v1.9.1",
780+
Latest: "v1.9.1",
781+
},
782+
GoVersion: &Version{
783+
Current: "go1.99.9",
784+
Latest: "go1.22.4",
785+
},
786+
}
787+
788+
// Assert to contain the expected message
789+
wantContain := regexp.MustCompile(`up-to-date:.* go1\.99\.9`)
790+
got := pkgInfo.VersionCheckResultStr()
791+
792+
if !wantContain.MatchString(got) {
793+
t.Errorf("got: %v, want: %v", got, wantContain)
794+
}
795+
}
796+
724797
func TestPackage_VersionCheckResultStr_go_not_up_to_date(t *testing.T) {
725798
pkgInfo := Package{
726799
Name: "foo",

0 commit comments

Comments
 (0)