Write tests for version checks
MODIFY
version/check.go
version/check.go
@@ -19,10 +19,14 @@ func IsLocalOutdated(dontRemindFor string) bool {
return false
}
+ return isCurrentOlder(Version, GetLatestRemoteVersion())
+}
+
+func isCurrentOlder(current, other string) bool {
var yearRemote, monthRemote, dayRemote int
- fmt.Sscanf(GetLatestRemoteVersion(), "%04d-%02d-%02d", &yearRemote, &monthRemote, &dayRemote)
+ fmt.Sscanf(other, "%04d-%02d-%02d", &yearRemote, &monthRemote, &dayRemote)
var yearLocal, monthLocal, dayLocal int
- fmt.Sscanf(Version, "%04d-%02d-%02d", &yearLocal, &monthLocal, &dayLocal)
+ fmt.Sscanf(current, "%04d-%02d-%02d", &yearLocal, &monthLocal, &dayLocal)
return !(yearLocal >= yearRemote && monthLocal >= monthRemote && dayLocal >= dayRemote)
}

ADD
version/check_test.go
+package version
+
+import "testing"
+
+func Test_isCurrentOlder(t *testing.T) {
+ type args struct {
+ current string
+ other string
+ }
+ tests := []struct {
+ name string
+ args args
+ want bool
+ }{
+ {
+ name: "current older",
+ args: args{
+ current: "2018-10-10",
+ other: "2018-10-11",
+ },
+ want: true,
+ }, {
+ name: "same",
+ args: args{
+ current: "2018-10-11",
+ other: "2018-10-11",
+ },
+ want: false,
+ }, {
+ name: "current newer",
+ args: args{
+ current: "2018-10-12",
+ other: "2018-10-11",
+ },
+ want: false,
+ }, {
+ name: "current day higher, but month and year older",
+ args: args{
+ current: "2018-09-12",
+ other: "2018-10-11",
+ },
+ want: true,
+ }, {
+ name: "current older; additional gibberish behind current",
+ args: args{
+ current: "2018-10-10R2",
+ other: "2018-10-11",
+ },
+ want: true,
+ }, {
+ name: "current older; additional gibberish behind other",
+ args: args{
+ current: "2018-10-10",
+ other: "2018-10-11R2",
+ },
+ want: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := isCurrentOlder(tt.args.current, tt.args.other); got != tt.want {
+ t.Errorf("isCurrentOlder() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}

Write tests for version checks