github.com/mattdotmatt/gauge@v0.3.2-0.20160421115137-425a4cdccb62/plugin/install/check_test.go (about) 1 // Copyright 2015 ThoughtWorks, Inc. 2 3 // This file is part of Gauge. 4 5 // Gauge is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 10 // Gauge is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 15 // You should have received a copy of the GNU General Public License 16 // along with Gauge. If not, see <http://www.gnu.org/licenses/>. 17 18 package install 19 20 import ( 21 "strings" 22 23 "github.com/getgauge/gauge/version" 24 . "gopkg.in/check.v1" 25 ) 26 27 var _ = Suite(&MySuite{}) 28 29 func (s *MySuite) TestCheckGaugeUpdateWhenThereIsAnUpdate(c *C) { 30 getLatestGaugeVersion = func(url string) (string, error) { 31 return "0.1.0", nil 32 } 33 version.CurrentGaugeVersion = &version.Version{0, 0, 1} 34 updateInfo := checkGaugeUpdate()[0] 35 c.Assert(updateInfo.CompatibleVersion, Equals, "0.1.0") 36 c.Assert(updateInfo.Name, Equals, "Gauge") 37 } 38 39 func (s *MySuite) TestCheckGaugeUpdateWhenThereIsNoUpdate(c *C) { 40 getLatestGaugeVersion = func(url string) (string, error) { 41 return "0.1.0", nil 42 } 43 version.CurrentGaugeVersion = &version.Version{0, 2, 0} 44 updateInfos := checkGaugeUpdate() 45 c.Assert(len(updateInfos), Equals, 0) 46 } 47 48 func (s *MySuite) TestCreatePluginUpdateDetailWhenThereIsAnUpdate(c *C) { 49 version.CurrentGaugeVersion = &version.Version{0, 1, 1} 50 ruby := "ruby" 51 i := installDescription{Name: ruby, Versions: []versionInstallDescription{versionInstallDescription{Version: "0.1.1", GaugeVersionSupport: version.VersionSupport{Minimum: "0.1.0", Maximum: "0.1.2"}}}} 52 updateDetails := createPluginUpdateDetail("0.1.0", i) 53 c.Assert(len(updateDetails), Equals, 1) 54 c.Assert(updateDetails[0].Name, Equals, ruby) 55 c.Assert(updateDetails[0].CompatibleVersion, Equals, "0.1.1") 56 c.Assert(updateDetails[0].Message, Equals, "Run 'gauge --update ruby'") 57 } 58 59 func (s *MySuite) TestCreatePluginUpdateDetailWhenThereIsNoUpdate(c *C) { 60 version.CurrentGaugeVersion = &version.Version{0, 1, 1} 61 ruby := "ruby" 62 i := installDescription{Name: ruby, Versions: []versionInstallDescription{versionInstallDescription{Version: "0.1.0", GaugeVersionSupport: version.VersionSupport{Minimum: "0.1.0", Maximum: "0.1.2"}}}} 63 updateDetails := createPluginUpdateDetail("0.1.0", i) 64 c.Assert(len(updateDetails), Equals, 0) 65 } 66 67 func (s *MySuite) TestGetGaugeVersionProperty(c *C) { 68 info := `version: 0.3.2 69 darwin86: a41ba21c1517583fd741645bb89ce1264f525f1e 70 darwin86_64: f2d3ef3dae561bf431e75a6bd46f3a4baff58499 71 linux86: 32d0c75521523e510b2cc61491ce79c37fdf03f3 72 linux86_64: c810361c4e0a622af528f8fa282b861baada769d 73 windows86: 570429e9a1f574cf0df2e117246690fe31c6fed0 74 windows86_64: a70281e005d97216a2535b6def57ef38df38b767` 75 r := strings.NewReader(info) 76 77 v, err := getGaugeVersionProperty(r) 78 79 c.Assert(err, Equals, nil) 80 c.Assert(v, Equals, "0.3.2") 81 }