diff --git a/README.md b/README.md index 9e12c08..8215663 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,8 @@ -# Browser - -![](logo.png) - -
- - License: Apache-2.0 - - - Go Reference - - - Go report card - - - Build Status - - - Code coverage - -
+# browser [![MIT](https://img.shields.io/github/license/dineshgowda24/browser)](https://github.com/dineshgowda24/browser/blob/main/LICENSE) [![Go Reference](https://pkg.go.dev/badge/github.com/dineshgowda24/browser.svg)](https://pkg.go.dev/github.com/dineshgowda24/browser) [![Go report card](https://goreportcard.com/badge/github.com/dineshgowda24/browser)](https://goreportcard.com/report/github.com/dineshgowda24/browser) [![Build Status](https://dl.circleci.com/status-badge/img/circleci/MQTLZJuBejHgr2yqrojz3u/5NTLeuQeViQw2JaPQf7gKa/tree/main.svg?style=shield&circle-token=ab7a417fe410b8387c767f83568f7d2f2788ac4f)](https://dl.circleci.com/status-badge/redirect/circleci/MQTLZJuBejHgr2yqrojz3u/5NTLeuQeViQw2JaPQf7gKa/tree/main) [![Coverage](https://codecov.io/gh/dineshgowda24/browser/graph/badge.svg?token=XUA2VJW5FU)](https://codecov.io/gh/dineshgowda24/browser) [![X](https://img.shields.io/twitter/follow/_dineshgowda)](https://twitter.com/_dineshgowda) + +

+ +

## Why? diff --git a/bot.go b/bot.go index 37ae92f..696360b 100644 --- a/bot.go +++ b/bot.go @@ -124,12 +124,7 @@ func (b *Bot) Name() string { return "" } - n := b.matcher.Name() - if n != "" { - return n - } - - return genericBotName + return b.matcher.Name() } // Why returns the reason why the user agent is a bot diff --git a/browser.go b/browser.go index 439c22a..9515beb 100644 --- a/browser.go +++ b/browser.go @@ -44,15 +44,8 @@ func NewBrowser(userAgent string) (*Browser, error) { return nil, ErrUserAgentSizeExceeded } - p, err := NewPlatform(userAgent) - if err != nil { - return nil, err - } - - d, err := NewDevice(userAgent) - if err != nil { - return nil, err - } + p, _ := NewPlatform(userAgent) + d, _ := NewDevice(userAgent) bot, err := NewBot(userAgent) if err != nil { diff --git a/browser_test.go b/browser_test.go index 67b8f9a..148758c 100644 --- a/browser_test.go +++ b/browser_test.go @@ -3,6 +3,7 @@ package browser import ( "log" "os" + "strings" "testing" . "github.com/smartystreets/goconvey/convey" @@ -50,6 +51,26 @@ func TestMain(m *testing.M) { os.Exit(exitCode) } +func TestNewBrowser(t *testing.T) { + Convey("Subject: #NewBrowser", t, func() { + Convey("When the user agent is not empty", func() { + Convey("It should return a browser", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.Windows) + So(b, ShouldNotBeNil) + }) + }) + + Convey("When the user agent is over 2kb", func() { + Convey("It should return an error", func() { + ua := strings.Repeat("a", 2049) + _, err := NewBrowser(ua) + So(err, ShouldEqual, ErrUserAgentSizeExceeded) + }) + }) + }) +} + func TestBrowserName(t *testing.T) { Convey("Subject: #Name", t, func() { Convey("When the browser is Alipay", func() { @@ -246,6 +267,36 @@ func TestBrowserShortVersion(t *testing.T) { }) } +func TestBrowserPlatform(t *testing.T) { + Convey("Subject: #Platform", t, func() { + Convey("It should return the platform", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.Windows) + So(b.Platform(), ShouldHaveSameTypeAs, &Platform{}) + }) + }) +} + +func TestBrowserDevice(t *testing.T) { + Convey("Subject: #Device", t, func() { + Convey("It should return the device", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.Windows) + So(b.Device(), ShouldHaveSameTypeAs, &Device{}) + }) + }) +} + +func TestBrowserBot(t *testing.T) { + Convey("Subject: #Bot", t, func() { + Convey("It should return the bot", func() { + ua := testUserAgents["googlebot"] + b, _ := NewBrowser(ua.Windows) + So(b.Bot(), ShouldHaveSameTypeAs, &Bot{}) + }) + }) +} + func TestBrowserIsAlipay(t *testing.T) { Convey("Subject: #IsAlipay", t, func() { Convey("When the browser is Alipay", func() { @@ -266,6 +317,46 @@ func TestBrowserIsAlipay(t *testing.T) { }) } +func TestBrowserIsNokia(t *testing.T) { + Convey("Subject: #IsNokia", t, func() { + Convey("When the browser is Nokia", func() { + Convey("It should return true", func() { + ua := testUserAgents["nokia"] + b, _ := NewBrowser(ua.Android) + So(b.IsNokia(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not Nokia", func() { + Convey("It should return false", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.Android) + So(b.IsNokia(), ShouldBeFalse) + }) + }) + }) +} + +func TestBrowserIsUCBrowser(t *testing.T) { + Convey("Subject: #IsUCBrowser", t, func() { + Convey("When the browser is UC Browser", func() { + Convey("It should return true", func() { + ua := testUserAgents["uc-browser"] + b, _ := NewBrowser(ua.Android) + So(b.IsUCBrowser(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not UC Browser", func() { + Convey("It should return false", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.Android) + So(b.IsUCBrowser(), ShouldBeFalse) + }) + }) + }) +} + func TestBrowserIsBlackBerry(t *testing.T) { Convey("Subject: #IsBlackBerry", t, func() { Convey("When the browser is BlackBerry", func() { @@ -306,6 +397,146 @@ func TestBrowserIsDuckDuckGo(t *testing.T) { }) } +func TestBrowserIsGoogleSearchApp(t *testing.T) { + Convey("Subject: #IsGoogleSearchApp", t, func() { + Convey("When the browser is Google Search App", func() { + Convey("It should return true", func() { + ua := testUserAgents["gsa"] + b, _ := NewBrowser(ua.Android) + So(b.IsGoogleSearchApp(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not Google Search App", func() { + Convey("It should return false", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.Android) + So(b.IsGoogleSearchApp(), ShouldBeFalse) + }) + }) + }) +} + +func TestBrowserIsHuaweiBrowser(t *testing.T) { + Convey("Subject: #IsHuaweiBrowser", t, func() { + Convey("When the browser is Huawei Browser", func() { + Convey("It should return true", func() { + ua := testUserAgents["huawei-browser"] + b, _ := NewBrowser(ua.Android) + So(b.IsHuaweiBrowser(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not Huawei Browser", func() { + Convey("It should return false", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.Android) + So(b.IsHuaweiBrowser(), ShouldBeFalse) + }) + }) + }) +} + +func TestBrowserIsKonqueror(t *testing.T) { + Convey("Subject: #IsKonqueror", t, func() { + Convey("When the browser is Konqueror", func() { + Convey("It should return true", func() { + ua := testUserAgents["konqueror"] + b, _ := NewBrowser(ua.Linux) + So(b.IsKonqueror(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not Konqueror", func() { + Convey("It should return false", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.Linux) + So(b.IsKonqueror(), ShouldBeFalse) + }) + }) + }) +} + +func TestBrowserIsMaxthon(t *testing.T) { + Convey("Subject: #IsMaxthon", t, func() { + Convey("When the browser is Maxthon", func() { + Convey("It should return true", func() { + ua := testUserAgents["maxthon"] + b, _ := NewBrowser(ua.Windows) + So(b.IsMaxthon(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not Maxthon", func() { + Convey("It should return false", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.Windows) + So(b.IsMaxthon(), ShouldBeFalse) + }) + }) + }) +} + +func TestBrowserIsMiuiBrowser(t *testing.T) { + Convey("Subject: #IsMiuiBrowser", t, func() { + Convey("When the browser is MiuiBrowser", func() { + Convey("It should return true", func() { + ua := testUserAgents["miui-browser"] + b, _ := NewBrowser(ua.Android) + So(b.IsMiuiBrowser(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not MiuiBrowser", func() { + Convey("It should return false", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.Android) + So(b.IsMiuiBrowser(), ShouldBeFalse) + }) + }) + }) +} + +func TestBrowserIsPaleMoon(t *testing.T) { + Convey("Subject: #IsPaleMoon", t, func() { + Convey("When the browser is Pale Moon", func() { + Convey("It should return true", func() { + ua := testUserAgents["pale-moon"] + b, _ := NewBrowser(ua.Windows) + So(b.IsPaleMoon(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not Pale Moon", func() { + Convey("It should return false", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.Windows) + So(b.IsPaleMoon(), ShouldBeFalse) + }) + }) + }) +} + +func TestBrowserIsPuffin(t *testing.T) { + Convey("Subject: #IsPuffin", t, func() { + Convey("When the browser is Puffin", func() { + Convey("It should return true", func() { + ua := testUserAgents["puffin"] + b, _ := NewBrowser(ua.Android) + So(b.IsPuffin(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not Puffin", func() { + Convey("It should return false", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.Android) + So(b.IsPuffin(), ShouldBeFalse) + }) + }) + }) +} + func TestBrowserIsOpera(t *testing.T) { Convey("Subject: #IsOpera", t, func() { Convey("When the browser is Opera", func() { @@ -346,6 +577,127 @@ func TestBrowserIsOtter(t *testing.T) { }) } +func TestBrowserIsInstagram(t *testing.T) { + Convey("Subject: #IsInstagram", t, func() { + Convey("When the browser is Instagram", func() { + Convey("It should return true", func() { + ua := testUserAgents["instagram"] + b, _ := NewBrowser(ua.IOS) + So(b.IsInstagram(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not Instagram", func() { + Convey("It should return false", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.IOS) + So(b.IsInstagram(), ShouldBeFalse) + }) + }) + }) +} + +func TestBrowserIsSnapchat(t *testing.T) { + Convey("Subject: #IsSnapchat", t, func() { + Convey("When the browser is Snapchat", func() { + Convey("It should return true", func() { + ua := testUserAgents["snapchat"] + b, _ := NewBrowser(ua.IOS) + So(b.IsSnapchat(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not Snapchat", func() { + Convey("It should return false", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.IOS) + So(b.IsSnapchat(), ShouldBeFalse) + }) + }) + }) +} + +func TestBrowserIsWeibo(t *testing.T) { + Convey("Subject: #IsWeibo", t, func() { + Convey("When the browser is Weibo", func() { + Convey("It should return true", func() { + ua := testUserAgents["weibo"] + b, _ := NewBrowser(ua.IOS) + So(b.IsWeibo(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not Weibo", func() { + Convey("It should return false", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.IOS) + So(b.IsWeibo(), ShouldBeFalse) + }) + }) + }) +} + +func TestBrowserIsMicroMessenger(t *testing.T) { + Convey("Subject: #IsMicroMessenger", t, func() { + Convey("When the browser is MicroMessenger", func() { + Convey("It should return true", func() { + ua := testUserAgents["micro-messenger"] + b, _ := NewBrowser(ua.Android) + So(b.IsMicroMessenger(), ShouldBeTrue) + So(b.IsWechat(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not MicroMessenger", func() { + Convey("It should return false", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.Android) + So(b.IsMicroMessenger(), ShouldBeFalse) + }) + }) + }) +} + +func TestBrowserIsQQ(t *testing.T) { + Convey("Subject: #IsQQ", t, func() { + Convey("When the browser is QQ", func() { + Convey("It should return true", func() { + ua := testUserAgents["qq"] + b, _ := NewBrowser(ua.Android) + So(b.IsQQ(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not QQ", func() { + Convey("It should return false", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.Android) + So(b.IsQQ(), ShouldBeFalse) + }) + }) + }) +} + +func TestBrowserIsElectron(t *testing.T) { + Convey("Subject: #IsElectron", t, func() { + Convey("When the browser is Electron", func() { + Convey("It should return true", func() { + ua := testUserAgents["electron"] + b, _ := NewBrowser(ua.Mac) + So(b.IsElectron(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not Electron", func() { + Convey("It should return false", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.Mac) + So(b.IsElectron(), ShouldBeFalse) + }) + }) + }) +} + func TestBrowserIsUnknown(t *testing.T) { Convey("Subject: #IsUnknown", t, func() { Convey("When the browser is Unknown", func() { @@ -412,6 +764,186 @@ func TestBrowserIsInternetExplorer(t *testing.T) { }) } +func TestBrowserIsSamsungBrowser(t *testing.T) { + Convey("Subject: #IsSamsungBrowser", t, func() { + Convey("When the browser is Samsung Browser", func() { + Convey("It should return true", func() { + ua := testUserAgents["samsung-browser"] + b, _ := NewBrowser(ua.Android) + So(b.IsSamsungBrowser(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not Samsung Browser", func() { + Convey("It should return false", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.Android) + So(b.IsSamsungBrowser(), ShouldBeFalse) + }) + }) + }) +} + +func TestBrowserIsSougouBrowser(t *testing.T) { + Convey("Subject: #IsSougouBrowser", t, func() { + Convey("When the browser is Sougou Browser", func() { + Convey("It should return true", func() { + ua := testUserAgents["sogou-browser"] + b, _ := NewBrowser(ua.Android) + So(b.IsSougouBrowser(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not Sougou Browser", func() { + Convey("It should return false", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.Windows) + So(b.IsSougouBrowser(), ShouldBeFalse) + }) + }) + }) +} + +func TestBrowserIsVivoBrowser(t *testing.T) { + Convey("Subject: #IsVivoBrowser", t, func() { + Convey("When the browser is Vivo Browser", func() { + Convey("It should return true", func() { + ua := testUserAgents["vivo-browser"] + b, _ := NewBrowser(ua.Android) + So(b.IsVivoBrowser(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not Vivo Browser", func() { + Convey("It should return false", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.Android) + So(b.IsVivoBrowser(), ShouldBeFalse) + }) + }) + }) +} + +func TestBrowserIsSputnik(t *testing.T) { + Convey("Subject: #IsSputnik", t, func() { + Convey("When the browser is Sputnik", func() { + Convey("It should return true", func() { + ua := testUserAgents["sputnik"] + b, _ := NewBrowser(ua.Windows) + So(b.IsSputnik(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not Sputnik", func() { + Convey("It should return false", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.Windows) + So(b.IsSputnik(), ShouldBeFalse) + }) + }) + }) +} + +func TestBrowserIsYaaniBrowser(t *testing.T) { + Convey("Subject: #IsYaaniBrowser", t, func() { + Convey("When the browser is YaaniBrowser", func() { + Convey("It should return true", func() { + ua := testUserAgents["yaani-browser"] + b, _ := NewBrowser(ua.Android) + So(b.IsYaaniBrowser(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not YaaniBrowser", func() { + Convey("It should return false", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.Android) + So(b.IsYaaniBrowser(), ShouldBeFalse) + }) + }) + }) +} + +func TestBrowserIsYandex(t *testing.T) { + Convey("Subject: #IsYandex", t, func() { + Convey("When the browser is Yandex", func() { + Convey("It should return true", func() { + ua := testUserAgents["yandex"] + b, _ := NewBrowser(ua.Windows) + So(b.IsYandex(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not Yandex", func() { + Convey("It should return false", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.Windows) + So(b.IsYandex(), ShouldBeFalse) + }) + }) + }) +} + +func TestBrowserIsChrome(t *testing.T) { + Convey("Subject: #IsChrome", t, func() { + Convey("When the browser is Chrome", func() { + Convey("It should return true", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.Windows) + So(b.IsChrome(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not Chrome", func() { + Convey("It should return false", func() { + ua := testUserAgents["alipay"] + b, _ := NewBrowser(ua.Android) + So(b.IsChrome(), ShouldBeFalse) + }) + }) + }) +} + +func TestBrowserIsSafari(t *testing.T) { + Convey("Subject: #IsSafari", t, func() { + Convey("When the browser is Safari", func() { + Convey("It should return true", func() { + ua := testUserAgents["safari"] + b, _ := NewBrowser(ua.Mac) + So(b.IsSafari(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not Safari", func() { + Convey("It should return false", func() { + ua := testUserAgents["alipay"] + b, _ := NewBrowser(ua.Android) + So(b.IsSafari(), ShouldBeFalse) + }) + }) + }) +} + +func TestBrowserIsSafariWebappMode(t *testing.T) { + Convey("Subject: #IsSafariWebappMode", t, func() { + Convey("When the browser is Safari Webapp Mode", func() { + Convey("It should return true", func() { + ua := testUserAgents["chrome"] + b, _ := NewBrowser(ua.IOS) + So(b.IsSafariWebappMode(), ShouldBeTrue) + }) + }) + + Convey("When the browser is not Safari Webapp Mode", func() { + Convey("It should return false", func() { + ua := testUserAgents["alipay"] + b, _ := NewBrowser(ua.Android) + So(b.IsSafariWebappMode(), ShouldBeFalse) + }) + }) + }) +} + func TestBrowserIsEdge(t *testing.T) { Convey("Subject: #IsEdge", t, func() { Convey("When the browser is Edge", func() { diff --git a/device_test.go b/device_test.go index 4d9b25c..58d2fb7 100644 --- a/device_test.go +++ b/device_test.go @@ -108,6 +108,13 @@ func TestDeviceIsIPodTouch(t *testing.T) { So(d.IsIPodTouch(), ShouldBeTrue) }) }) + + Convey("When the device is not an iPod touch", func() { + Convey("It should return false", func() { + d, _ := NewDevice(testDevices["iphone-7"]) + So(d.IsIPodTouch(), ShouldBeFalse) + }) + }) }) } @@ -215,6 +222,13 @@ func TestDeviceIsSwitch(t *testing.T) { So(d.IsConsole(), ShouldBeTrue) }) }) + + Convey("When the device is not a Switch", func() { + Convey("It should return false", func() { + d, _ := NewDevice(testDevices["wiiu-1"]) + So(d.IsSwitch(), ShouldBeFalse) + }) + }) }) } @@ -251,6 +265,13 @@ func TestDeviceIsKindleFire(t *testing.T) { So(d.IsKindleFire(), ShouldBeTrue) }) }) + + Convey("When the device is not a Kindle Fire", func() { + Convey("It should return false", func() { + d, _ := NewDevice(testDevices["kindle-1"]) + So(d.IsKindleFire(), ShouldBeFalse) + }) + }) }) } @@ -273,6 +294,13 @@ func TestDeviceIsSamsung(t *testing.T) { So(d.IsSamsung(), ShouldBeTrue) }) }) + + Convey("When the device is not a Samsung", func() { + Convey("It should return false", func() { + d, _ := NewDevice(testDevices["iphone-7"]) + So(d.IsSamsung(), ShouldBeFalse) + }) + }) }) } @@ -284,6 +312,13 @@ func TestDeviceIsTV(t *testing.T) { So(d.IsTV(), ShouldBeTrue) }) }) + + Convey("When the device is not a TV", func() { + Convey("It should return false", func() { + d, _ := NewDevice(testDevices["iphone-7"]) + So(d.IsTV(), ShouldBeFalse) + }) + }) }) } diff --git a/logo.png b/logo.png index 2911b8e..2a2ec38 100644 Binary files a/logo.png and b/logo.png differ diff --git a/matchers/miui_browser.go b/matchers/miui_browser.go index 04bbaf5..7983b98 100644 --- a/matchers/miui_browser.go +++ b/matchers/miui_browser.go @@ -1,4 +1,3 @@ - package matchers type MiuiBrowser struct { diff --git a/matchers/otter.go b/matchers/otter.go index 66ef840..bc09544 100644 --- a/matchers/otter.go +++ b/matchers/otter.go @@ -1,4 +1,3 @@ - package matchers type Otter struct { diff --git a/matchers/pale_moon.go b/matchers/pale_moon.go index ccf0701..e65ff50 100644 --- a/matchers/pale_moon.go +++ b/matchers/pale_moon.go @@ -4,7 +4,6 @@ type PaleMoon struct { base } - var ( paleMoonName = "Pale Moon" paleMoonVersionRegexp = []string{`PaleMoon/([\d.]+)`} diff --git a/matchers/sputnik.go b/matchers/sputnik.go index 1fd65a9..c2a8fca 100644 --- a/matchers/sputnik.go +++ b/matchers/sputnik.go @@ -1,4 +1,3 @@ - package matchers type Sputnik struct { diff --git a/matchers/weibo.go b/matchers/weibo.go index 3a62ac9..87072e6 100644 --- a/matchers/weibo.go +++ b/matchers/weibo.go @@ -1,4 +1,3 @@ - package matchers type Weibo struct { diff --git a/matchers/yandex.go b/matchers/yandex.go index a5b5a6f..9856bb1 100644 --- a/matchers/yandex.go +++ b/matchers/yandex.go @@ -1,4 +1,3 @@ - package matchers type Yandex struct { diff --git a/utils/version_test.go b/utils/version_test.go index ca87817..3bac964 100644 --- a/utils/version_test.go +++ b/utils/version_test.go @@ -21,6 +21,24 @@ func TestVersionGTE(t *testing.T) { }) }) + Convey("When the actual version is ''", func() { + Convey("It should return false", func() { + So(VersionGTE("", "1.0.0"), ShouldBeFalse) + }) + }) + + Convey("When the actual version is unparsable", func() { + Convey("It should return false", func() { + So(VersionGTE("@#", "1.0.0"), ShouldBeFalse) + }) + }) + + Convey("When the expected version is unparsable", func() { + Convey("It should return false", func() { + So(VersionGTE("1.0.0", "@#"), ShouldBeFalse) + }) + }) + Convey("When the actual version is less than the expected version", func() { Convey("It should return false", func() { So(VersionGTE("1.0.0", "1.0.1"), ShouldBeFalse) @@ -47,6 +65,24 @@ func TestVersionGT(t *testing.T) { }) }) + Convey("When the actual version is ''", func() { + Convey("It should return false", func() { + So(VersionGT("", "1.0.0"), ShouldBeFalse) + }) + }) + + Convey("When the actual version is unparsable", func() { + Convey("It should return false", func() { + So(VersionGT("@#", "1.0.0"), ShouldBeFalse) + }) + }) + + Convey("When the expected version is unparsable", func() { + Convey("It should return false", func() { + So(VersionGT("1.0.0", "@#"), ShouldBeFalse) + }) + }) + Convey("When the actual version is less than or equal to the expected version", func() { Convey("It should return false", func() { So(VersionGT("1.0.0", "1.0.0"), ShouldBeFalse) @@ -73,6 +109,24 @@ func TestVersionLTE(t *testing.T) { }) }) + Convey("When the actual version is ''", func() { + Convey("It should return true", func() { + So(VersionLTE("", "1.0.0"), ShouldBeTrue) + }) + }) + + Convey("When the actual version is unparsable", func() { + Convey("It should return false", func() { + So(VersionLTE("@#", "1.0.0"), ShouldBeFalse) + }) + }) + + Convey("When the expected version is unparsable", func() { + Convey("It should return false", func() { + So(VersionLTE("1.0.0", "@#"), ShouldBeFalse) + }) + }) + Convey("When the actual version is greater than the expected version", func() { Convey("It should return false", func() { So(VersionLTE("1.0.0", "0.9.0"), ShouldBeFalse) @@ -99,6 +153,24 @@ func TestVersionLT(t *testing.T) { }) }) + Convey("When the actual version is ''", func() { + Convey("It should return true", func() { + So(VersionLT("", "1.0.0"), ShouldBeTrue) + }) + }) + + Convey("When the actual version is unparsable", func() { + Convey("It should return false", func() { + So(VersionLT("@#", "1.0.0"), ShouldBeFalse) + }) + }) + + Convey("When the expected version is unparsable", func() { + Convey("It should return false", func() { + So(VersionLT("1.0.0", "@#"), ShouldBeFalse) + }) + }) + Convey("When the actual version is greater than or equal to the expected version", func() { Convey("It should return false", func() { So(VersionLT("1.0.0", "1.0.0"), ShouldBeFalse)