5
5
"errors"
6
6
"os"
7
7
"path/filepath"
8
+ "regexp"
8
9
"runtime"
9
10
"strings"
10
11
"testing"
@@ -673,6 +674,30 @@ func TestGoPaths_StartDryRunMode_fail_if_key_not_set(t *testing.T) {
673
674
// Type: Package
674
675
// ----------------------------------------------------------------------------
675
676
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
+
676
701
func TestPackage_CurrentToLatestStr_not_up_to_date (t * testing.T ) {
677
702
pkgInfo := Package {
678
703
Name : "foo" ,
@@ -697,6 +722,30 @@ func TestPackage_CurrentToLatestStr_not_up_to_date(t *testing.T) {
697
722
}
698
723
}
699
724
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
+
700
749
func TestPackage_VersionCheckResultStr_not_up_to_date (t * testing.T ) {
701
750
pkgInfo := Package {
702
751
Name : "foo" ,
@@ -721,6 +770,30 @@ func TestPackage_VersionCheckResultStr_not_up_to_date(t *testing.T) {
721
770
}
722
771
}
723
772
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
+
724
797
func TestPackage_VersionCheckResultStr_go_not_up_to_date (t * testing.T ) {
725
798
pkgInfo := Package {
726
799
Name : "foo" ,
0 commit comments