doodle/pkg/updater/updater_test.go
Noah Petherbridge 1105d9312a Updater: Better SemVer version checks for updates
* Instead of a simple "cur. ver != latest ver" check, parse the Major,
  Minor and Patch components and do a detailed check.
* So a x.x.1 release could be made for a specific platform that had a
  bad build, and it won't mind when it sees the latest version is the
  older x.x.0 build that other platforms had working fine.
2021-07-11 14:09:18 -07:00

73 lines
1007 B
Go

package updater_test
import (
"testing"
"git.kirsle.net/apps/doodle/pkg/updater"
)
// Test the semver logic.
func TestParseSemver(t *testing.T) {
var tests = []struct {
A string // version strings
B string
Expect bool // expect B is newer version than A
}{
{
"0.1.0-alpha",
"0.1.0-alpha",
false,
},
{
"0.1.0-alpha",
"0.2.0-alpha",
true,
},
{
"0.2.0-alpha",
"0.2.0-alpha",
false,
},
{
"0.2.0-alpha",
"0.1.0-alpha",
false,
},
{
"0.2.0-alpha",
"0.2.1-alpha",
true,
},
{
"0.1.0-alpha",
"0.2.1-alpha",
true,
},
{
"0.2.1-alpha",
"0.3.0",
true,
},
{
"0.3.0",
"0.4.1",
true,
},
{
"0.1",
"0.2.0",
false,
},
}
for i, test := range tests {
result := updater.VersionInfo{
LatestVersion: test.B,
}.IsNewerVersionThan(test.A)
if result != test.Expect {
t.Errorf("Test %d: %s <> %s: expected %+v but got %+v",
i, test.A, test.B, test.Expect, result,
)
}
}
}