github.com/creativeprojects/go-selfupdate@v1.2.0/release_test.go (about) 1 package selfupdate 2 3 import ( 4 "testing" 5 6 "github.com/Masterminds/semver/v3" 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestReleaseLessThan(t *testing.T) { 11 testData := []struct { 12 current string 13 other string 14 lessThan bool 15 }{ 16 {"1.0", "1.0.0", false}, 17 {"1.0", "1.0.1", true}, 18 } 19 for _, testItem := range testData { 20 release := Release{ 21 version: semver.MustParse(testItem.current), 22 } 23 assert.Equal(t, testItem.lessThan, release.LessThan(testItem.other)) 24 } 25 } 26 27 func TestReleaseGreaterThan(t *testing.T) { 28 testData := []struct { 29 current string 30 other string 31 greaterThan bool 32 }{ 33 {"1.0", "1.0.0", false}, 34 {"1.0", "0.9", true}, 35 } 36 for _, testItem := range testData { 37 release := Release{ 38 version: semver.MustParse(testItem.current), 39 } 40 assert.Equal(t, testItem.greaterThan, release.GreaterThan(testItem.other)) 41 } 42 } 43 44 func TestReleaseLessOrEqual(t *testing.T) { 45 testData := []struct { 46 current string 47 other string 48 lessOrEqual bool 49 }{ 50 {"1.0", "1.0.0", true}, 51 {"1.0", "1.0.1", true}, 52 {"1.0", "0.9", false}, 53 {"1.0", "1.0.0-beta", false}, 54 } 55 for _, testItem := range testData { 56 release := Release{ 57 version: semver.MustParse(testItem.current), 58 } 59 assert.Equal(t, testItem.lessOrEqual, release.LessOrEqual(testItem.other)) 60 } 61 } 62 63 func TestReleasePointerGreaterOrEqual(t *testing.T) { 64 testData := []struct { 65 current string 66 other string 67 greaterOrEqual bool 68 }{ 69 {"1.0", "1.0.0", true}, 70 {"1.0", "0.9", true}, 71 {"1.0", "1.0.0-beta", true}, 72 } 73 for _, testItem := range testData { 74 release := &Release{ 75 version: semver.MustParse(testItem.current), 76 } 77 assert.Equal(t, testItem.greaterOrEqual, release.GreaterOrEqual(testItem.other)) 78 } 79 }