github.com/wynshop-open-source/gomplate@v3.5.0+incompatible/tests/integration/time_test.go (about) 1 //+build integration 2 3 package integration 4 5 import ( 6 "runtime" 7 "time" 8 9 "github.com/gotestyourself/gotestyourself/icmd" 10 . "gopkg.in/check.v1" 11 ) 12 13 type TimeSuite struct{} 14 15 var _ = Suite(&TimeSuite{}) 16 17 func (s *TimeSuite) TestTime(c *C) { 18 f := `Mon Jan 02 15:04:05 MST 2006` 19 i := `Fri Feb 13 23:31:30 UTC 2009` 20 inOutTest(c, `{{ (time.Parse "`+f+`" "`+i+`").Format "2006-01-02 15 -0700" }}`, 21 "2009-02-13 23 +0000") 22 23 if runtime.GOOS != "windows" { 24 result := icmd.RunCmd(icmd.Command(GomplateBin, "-i", 25 `{{ (time.ParseLocal time.Kitchen "6:00AM").Format "15:04 MST" }}`), func(cmd *icmd.Cmd) { 26 cmd.Env = []string{"TZ=Africa/Luanda"} 27 }) 28 result.Assert(c, icmd.Expected{ExitCode: 0, Out: "06:00 LMT"}) 29 30 result = icmd.RunCmd(icmd.Command(GomplateBin, "-i", 31 `{{ time.ZoneOffset }}`), func(cmd *icmd.Cmd) { 32 cmd.Env = []string{"TZ=UTC"} 33 }) 34 result.Assert(c, icmd.Expected{ExitCode: 0, Out: "0"}) 35 } 36 37 zname, _ := time.Now().Zone() 38 inOutTest(c, `{{ time.ZoneName }}`, zname) 39 40 inOutTest(c, `{{ (time.Now).Format "2006-01-02 15 -0700" }}`, 41 time.Now().Format("2006-01-02 15 -0700")) 42 43 inOutTest(c, `{{ (time.ParseInLocation time.Kitchen "Africa/Luanda" "6:00AM").Format "15:04 MST" }}`, 44 "06:00 LMT") 45 46 inOutTest(c, `{{ (time.Unix 1234567890).UTC.Format "2006-01-02 15 -0700" }}`, 47 "2009-02-13 23 +0000") 48 49 inOutTest(c, `{{ (time.Unix "1234567890").UTC.Format "2006-01-02 15 -0700" }}`, 50 "2009-02-13 23 +0000") 51 }