From ffc015fe1d76acd4aa4a97c2a5c30fa17e0c44df Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 28 Sep 2015 11:07:20 -0700 Subject: [PATCH] Add more tests, coverage now stands for 42.6% --- config_test.go | 8 ++++++++ mc_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/config_test.go b/config_test.go index e8b37c26..3c8d30bb 100644 --- a/config_test.go +++ b/config_test.go @@ -23,6 +23,14 @@ import ( . "gopkg.in/check.v1" ) +func (s *TestSuite) TestConfigVersionContext(c *C) { + console.IsExited = false + err := app.Run([]string{os.Args[0], "config", "version"}) + c.Assert(err, IsNil) + c.Assert(console.IsExited, Equals, false) + console.IsExited = false +} + func (s *TestSuite) TestConfigAliasContext(c *C) { console.IsExited = false diff --git a/mc_test.go b/mc_test.go index 99271f0a..a19fd67c 100644 --- a/mc_test.go +++ b/mc_test.go @@ -23,6 +23,7 @@ import ( "runtime" "sync" "testing" + "time" "net/http/httptest" @@ -275,6 +276,47 @@ func (s *TestSuite) TestEmptyExpansions(c *C) { c.Assert(url, Equals, "hello") } +func (s *TestSuite) TestHumanizedTime(c *C) { + hTime := timeDurationToHumanizedTime(time.Duration(10) * time.Second) + c.Assert(hTime.Minutes, Equals, int64(0)) + c.Assert(hTime.Hours, Equals, int64(0)) + c.Assert(hTime.Days, Equals, int64(0)) + + hTime = timeDurationToHumanizedTime(time.Duration(10) * time.Minute) + c.Assert(hTime.Hours, Equals, int64(0)) + c.Assert(hTime.Days, Equals, int64(0)) + + hTime = timeDurationToHumanizedTime(time.Duration(10) * time.Hour) + c.Assert(hTime.Days, Equals, int64(0)) + + hTime = timeDurationToHumanizedTime(time.Duration(24) * time.Hour) + c.Assert(hTime.Days, Not(Equals), int64(0)) +} + +func (s *TestSuite) TestVersionContext(c *C) { + console.IsExited = false + + err := app.Run([]string{os.Args[0], "version"}) + c.Assert(err, IsNil) + c.Assert(console.IsExited, Equals, false) + + // reset back + console.IsExited = false +} + +func (s *TestSuite) TestCommonPrefix(c *C) { + c.Assert(commonPrefix("/usr", "/usr/local"), Equals, "/usr") + c.Assert(commonPrefix("/uabbf", "/ursfad/ccc"), Equals, "/u") + c.Assert(commonPrefix("/usr/local/lib", "/usr/local/test"), Equals, "/usr/local/") +} + +func (s *TestSuite) TestVersions(c *C) { + v1 := newVersion("1.5.1") + v2 := newVersion("1.5.0") + c.Assert(v2.LessThan(v1), Equals, true) + c.Assert(v1.LessThan(v2), Equals, false) +} + func (s *TestSuite) TestApp(c *C) { err := app.Run([]string{""}) c.Assert(err, IsNil)