当前位置: 首页>>代码示例>>Golang>>正文


Golang T.Unix方法代码示例

本文整理汇总了Golang中testing.T.Unix方法的典型用法代码示例。如果您正苦于以下问题:Golang T.Unix方法的具体用法?Golang T.Unix怎么用?Golang T.Unix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在testing.T的用法示例。


在下文中一共展示了T.Unix方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestFileIndex

func TestFileIndex(t *testing.T) {
	Convey("Indexes", t, func() {
		Convey("Newer", func() {
			f := defaultGenerator.NewFake()
			t := time.Now()
			f.LastUsage = time.Now().Unix()
			keyOlder := f.indexKey()
			f.LastUsage = time.Now().Unix() + 50
			keyNewer := f.indexKey()
			// keyOlder should be less than keyNewer
			So(bytes.Compare(keyOlder[:], keyNewer[:]), ShouldEqual, -1)
			Convey("Extract ID", func() {
				hash := getIDFromIndexKey(f.indexKey())
				So(bytes.Compare(hash, f.ByteID()), ShouldEqual, 0)
			})
			Convey("Start/end", func() {
				f.LastUsage = t.Unix()
				start := getIndexStart(t)
				end := getIndexEnd(t)
				So(bytes.Compare(start, f.indexKey()), ShouldEqual, -1)
				So(bytes.Compare(f.indexKey(), end), ShouldEqual, -1)
			})
		})
		Convey("Start/end", func() {
			t := time.Now()
			start := getIndexStart(t)
			end := getIndexEnd(t)
			log.Println(start, end)
			So(bytes.Compare(start, end), ShouldEqual, -1)
		})
	})
}
开发者ID:RyuaNerin,项目名称:hath,代码行数:32,代码来源:file_test.go

示例2: TestModelPageToml

func TestModelPageToml(t *testing.T) {
	Convey("ParseTomlFrontMatter", t, func() {
		p, err := NewPageOfMarkdown("testdata/page/page_toml.md", "page/page_toml", nil)
		if err != nil {
			So(err, ShouldNotBeNil)
			return
		}
		So(p.Title, ShouldEqual, "Welcome")

		t, _ := time.Parse("2006-01-02 15:04:05", "2016-03-25 12:20:20")
		So(p.Date, ShouldEqual, "2016-03-25 12:20:20")
		So(p.Created().Unix(), ShouldEqual, t.Unix())
		So(p.Updated().Format("2006-01-02"), ShouldEqual, "2016-03-26")
		So(p.IsUpdated(), ShouldEqual, true)

		So(p.Content(), ShouldHaveLength, 1768)
		So(p.Draft, ShouldEqual, false)

		So(p.URL(), ShouldEqual, "/page/page_toml.html")
		So(p.SourceURL(), ShouldEqual, "testdata/page/page_toml.md")

		So(p.Meta, ShouldContainKey, "key")

		Convey("PageSetURL", func() {
			p.SetURL("/welcome.html")
			So(p.URL(), ShouldEqual, "/welcome.html")

			p.SetDestURL("dest/welcome.html")
			So(p.DestURL(), ShouldEqual, "dest/welcome.html")
		})

	})
}
开发者ID:go-xiaohei,项目名称:pugo,代码行数:33,代码来源:page_test.go

示例3: TestSubscriber

func TestSubscriber(t *testing.T) {
	Convey("When creating a subscriber", t, func() {
		email := "[email protected]"
		lastPayed := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
		nextPayment := time.Date(2009, time.December, 10, 23, 0, 0, 0, time.UTC)
		s, _ := NewSubscriber(email, lastPayed, nextPayment, PaymentStatusDelayed)
		dbCfg := DBConfig()
		db := postgres.GetDatabase(dbCfg)
		err := s.Create(db)
		Convey("We can create a subscriber successfully", func() {
			So(err, ShouldEqual, nil)
		})
		Convey("We can retrieve a saved subscriber", func() {
			var newSub Subscriber
			GetSubscriber(email, &newSub, db)
			So(newSub.LastPayed.Unix(), ShouldEqual, s.LastPayed.Unix())
		})
		Convey("We can update an already saved subscriber", func() {
			var newSub Subscriber
			t := time.Date(2015, time.November, 10, 23, 0, 0, 0, time.UTC)
			s.LastPayed = t
			s.NextPayment = t.AddDate(0, 1, 0)
			s.Save(db)
			GetSubscriber(email, &newSub, db)
			So(newSub.LastPayed.Unix(), ShouldEqual, t.Unix())
		})
		db.Exec("TRUNCATE TABLE subscribers")
	})
}
开发者ID:asvins,项目名称:subscription,代码行数:29,代码来源:subscriber_test.go

示例4: TestPassengerFindDriver

func TestPassengerFindDriver(t *testing.T) {
	buff.WriteString("\n\n\n========================================================\n")
	buff.WriteString("Test PassengerFindDriver begin\n\n\n")
	// uid int64, startTime int64, sLat float64,
	// sLng float64, eLat float64, eLng float64, sCity string, eCity string
	buff.WriteString("\n***********************缺失参数寻找**********************\n")
	buff.WriteString("########缺失uid#########")
	str := "/route/dadd?startTime=%v&sPlace=%v&ePlace=%v&sLat=%v&sLng=%v&eLat=%v&eLng=%v&sCity=%v&eCity=%v&distance=%v"
	s, err := ts.G(str, unixTime, csLat, csLng, ceLat, ceLng, "003", "002")
	writeString(s, err)
	buff.WriteString("########缺失startTime#########")
	str := "/route/dadd?uid=%v&sPlace=%v&ePlace=%v&sLat=%v&sLng=%v&eLat=%v&eLng=%v&sCity=%v&eCity=%v&distance=%v"
	s, err := ts.G(str, uidSlice[11], csLat, csLng, ceLat, ceLng, "003", "002")
	writeString(s, err)
	buff.WriteString("########缺失sLat#########")
	str := "/route/dadd?uid=%v&startTime=%v&sPlace=%v&ePlace=%v&sLng=%v&eLat=%v&eLng=%v&sCity=%v&eCity=%v&distance=%v"
	s, err := ts.G(str, uidSlice[11], unixTime, csLng, ceLat, ceLng, "003", "002")
	writeString(s, err)
	buff.WriteString("########缺失sLng#########")
	str := "/route/dadd?uid=%v&startTime=%v&sPlace=%v&ePlace=%v&sLat=%v&eLat=%v&eLng=%v&sCity=%v&eCity=%v&distance=%v"
	s, err := ts.G(str, uidSlice[11], unixTime, csLat, ceLat, ceLng, "003", "002")
	writeString(s, err)
	buff.WriteString("########缺失eLat#########")
	str := "/route/dadd?uid=%v&startTime=%v&sPlace=%v&ePlace=%v&sLat=%v&sLng=%v&eLng=%v&sCity=%v&eCity=%v&distance=%v"
	s, err := ts.G(str, uidSlice[11], unixTime, csLat, csLng, ceLng, "003", "002")
	writeString(s, err)
	buff.WriteString("########缺失eLng#########")
	str := "/route/dadd?uid=%v&startTime=%v&sPlace=%v&ePlace=%v&sLat=%v&sLng=%v&eLat=%v&sCity=%v&eCity=%v&distance=%v"
	s, err := ts.G(str, uidSlice[11], unixTime, csLat, csLng, ceLat, "003", "002")
	writeString(s, err)
	buff.WriteString("########缺失sCity#########")
	str := "/route/dadd?uid=%v&startTime=%v&sPlace=%v&ePlace=%v&sLat=%v&sLng=%v&eLat=%v&eLng=%v&eCity=%v&distance=%v"
	s, err := ts.G(str, uidSlice[11], unixTime, csLat, csLng, ceLat, ceLng, "002")
	writeString(s, err)
	buff.WriteString("########缺失eCity#########")
	str := "/route/dadd?uid=%v&startTime=%v&sPlace=%v&ePlace=%v&sLat=%v&sLng=%v&eLat=%v&eLng=%v&sCity=%v&distance=%v"
	s, err := ts.G(str, uidSlice[11], unixTime, csLat, csLng, ceLat, ceLng, "003")
	writeString(s, err)

	buff.WriteString("\n***********************错误参数格式寻找****************\n")
	str := "/route/dadd?uid=%v&startTime=%v&sLat=%v&sLng=%v&eLat=%v&eLng=%v&sCity=%v&eCity=%v"
	s, err := ts.G(str, "userid", "unixTime", "csLat", "csLng", "ceLat", "ceLng", "003", "002")
	writeString(s, err)

	buff.WriteString("\n***********************正常参数寻找****************\n")
	unixTime := t.Unix()
	str := "/route/dadd?uid=%v&startTime=%v&sLat=%v&sLng=%v&eLat=%v&eLng=%v&sCity=%v&eCity=%v"
	for i := 10; i < 20; i++ {
		s, err := ts.G(str, uidSlice[i], unixTime, csLat, csLng, ceLat, ceLng, "001", "002")
		writeString(s, err)
		routes := []bean.FindDriverRoute{}
		util.J2Ss(s, routes)
		if len(routes) > 0 {
			tmpFinds = append(tmpFinds, tmpFind{routes[0].Drid, routes[0].Duid})
		} else {
			tmpFinds = append(tmpFinds, tmpFind{-1, -1})
		}
	}
}
开发者ID:caowenhua,项目名称:gocar,代码行数:59,代码来源:routeapi_test.go

示例5: TestValidate

func TestValidate(t *testing.T) {
	now := time.Date(2015, 1, 1, 0, 0, 0, 0, time.UTC)
	before, after := now.Add(-time.Minute), now.Add(time.Minute)
	leeway := 10 * time.Second

	exp := func(t time.Time) jwt.Claims {
		return jwt.Claims{"exp": t.Unix()}
	}
	nbf := func(t time.Time) jwt.Claims {
		return jwt.Claims{"nbf": t.Unix()}
	}

	var tests = []struct {
		desc      string
		c         jwt.Claims
		now       time.Time
		expLeeway time.Duration
		nbfLeeway time.Duration
		err       error
	}{
		// test for nbf < now <= exp
		{desc: "exp == nil && nbf == nil", c: jwt.Claims{}, now: now, err: nil},

		{desc: "now > exp", now: now, c: exp(before), err: jwt.ErrTokenIsExpired},
		{desc: "now = exp", now: now, c: exp(now), err: nil},
		{desc: "now < exp", now: now, c: exp(after), err: nil},

		{desc: "nbf < now", c: nbf(before), now: now, err: nil},
		{desc: "nbf = now", c: nbf(now), now: now, err: jwt.ErrTokenNotYetValid},
		{desc: "nbf > now", c: nbf(after), now: now, err: jwt.ErrTokenNotYetValid},

		// test for nbf-x < now <= exp+y
		{desc: "now < exp+x", now: now.Add(leeway - time.Second), expLeeway: leeway, c: exp(now), err: nil},
		{desc: "now = exp+x", now: now.Add(leeway), expLeeway: leeway, c: exp(now), err: nil},
		{desc: "now > exp+x", now: now.Add(leeway + time.Second), expLeeway: leeway, c: exp(now), err: jwt.ErrTokenIsExpired},

		{desc: "nbf-x > now", c: nbf(now), nbfLeeway: leeway, now: now.Add(-leeway + time.Second), err: nil},
		{desc: "nbf-x = now", c: nbf(now), nbfLeeway: leeway, now: now.Add(-leeway), err: jwt.ErrTokenNotYetValid},
		{desc: "nbf-x < now", c: nbf(now), nbfLeeway: leeway, now: now.Add(-leeway - time.Second), err: jwt.ErrTokenNotYetValid},
	}

	for i, tt := range tests {
		if got, want := tt.c.Validate(tt.now, tt.expLeeway, tt.nbfLeeway), tt.err; got != want {
			t.Errorf("%d - %q: got %v want %v", i, tt.desc, got, want)
		}
	}
}
开发者ID:SermoDigital,项目名称:jose,代码行数:47,代码来源:claims_test.go

示例6: TestNanosecondsToUTCAndBack

func TestNanosecondsToUTCAndBack(t *testing.T) {
	f := func(nsec int64) bool {
		t := Unix(0, nsec).UTC()
		ns := t.Unix()*1e9 + int64(t.Nanosecond())
		return ns == nsec
	}
	f32 := func(nsec int32) bool { return f(int64(nsec)) }
	cfg := &quick.Config{MaxCount: 10000}

	// Try a small date first, then the large ones. (The span is only a few hundred years
	// for nanoseconds in an int64.)
	if err := quick.Check(f32, cfg); err != nil {
		t.Fatal(err)
	}
	if err := quick.Check(f, cfg); err != nil {
		t.Fatal(err)
	}
}
开发者ID:Ericean,项目名称:go,代码行数:18,代码来源:time_test.go

示例7: TestModelPostToml

func TestModelPostToml(t *testing.T) {
	Convey("ParseTomlFrontMatter", t, func() {
		p, err := NewPostOfMarkdown("testdata/post/post_toml.md", nil)
		if err != nil {
			So(err, ShouldNotBeNil)
			return
		}
		So(p.Title, ShouldEqual, "Welcome")
		So(p.Tags[0].Name, ShouldEqual, "pugo")

		t, _ := time.Parse("2006-01-02 15:04:05", "2016-03-25 12:20:20")
		So(p.Date, ShouldEqual, "2016-03-25 12:20:20")
		So(p.Created().Unix(), ShouldEqual, t.Unix())
		So(p.Updated().Format("2006-01-02"), ShouldEqual, "2016-03-26")
		So(p.IsUpdated(), ShouldEqual, true)

		So(p.Content(), ShouldHaveLength, 1768)
		So(p.Brief(), ShouldHaveLength, 1043)
		So(p.Draft, ShouldEqual, false)

		So(p.URL(), ShouldEqual, "/2016/3/25/welcome.html")
		So(p.SourceURL(), ShouldEqual, "testdata/post/post_toml.md")

		Convey("PostSetURL", func() {
			p.SetURL("/welcome.html")
			So(p.URL(), ShouldEqual, "/welcome.html")

			p.SetDestURL("dest/welcome.html")
			So(p.DestURL(), ShouldEqual, "dest/welcome.html")
		})

		Convey("PostSetPlaceholder", func() {
			p.SetPlaceholder(r, hr)
			So(p.Thumb, ShouldEqual, "/media/golang.png")
		})
	})
}
开发者ID:go-xiaohei,项目名称:pugo,代码行数:37,代码来源:post_test.go

示例8: TestDriverAddRoute

func TestDriverAddRoute(t *testing.T) {
	buff.WriteString("\n\n\n========================================================\n")
	buff.WriteString("Test DriverAddRoute begin\n\n\n")

	buff.WriteString("\n***********************缺失参数加入**********************\n")
	buff.WriteString("########缺失uid#########")
	str := "/route/dadd?startTime=%v&sPlace=%v&ePlace=%v&sLat=%v&sLng=%v&eLat=%v&eLng=%v&sCity=%v&eCity=%v&distance=%v"
	s, err := ts.G(str, unixTime, "sPlace18", "ePlace18", csLat, csLng, ceLat, ceLng, "003", "002", 8.2)
	writeString(s, err)
	buff.WriteString("########缺失startTime#########")
	str := "/route/dadd?uid=%v&sPlace=%v&ePlace=%v&sLat=%v&sLng=%v&eLat=%v&eLng=%v&sCity=%v&eCity=%v&distance=%v"
	s, err := ts.G(str, uidSlice[8], "sPlace28", "ePlace28", csLat, csLng, ceLat, ceLng, "003", "002", 8.2)
	writeString(s, err)
	buff.WriteString("########缺失sPlace#########")
	str := "/route/dadd?uid=%v&startTime=%v&ePlace=%v&sLat=%v&sLng=%v&eLat=%v&eLng=%v&sCity=%v&eCity=%v&distance=%v"
	s, err := ts.G(str, uidSlice[8], unixTime, "ePlace38", csLat, csLng, ceLat, ceLng, "003", "002", 8.2)
	writeString(s, err)
	buff.WriteString("########缺失ePlace#########")
	str := "/route/dadd?uid=%v&startTime=%v&sPlace=%v&sLat=%v&sLng=%v&eLat=%v&eLng=%v&sCity=%v&eCity=%v&distance=%v"
	s, err := ts.G(str, uidSlice[8], unixTime, "sPlace38", csLat, csLng, ceLat, ceLng, "003", "002", 8.2)
	writeString(s, err)
	buff.WriteString("########缺失sLat#########")
	str := "/route/dadd?uid=%v&startTime=%v&sPlace=%v&ePlace=%v&sLng=%v&eLat=%v&eLng=%v&sCity=%v&eCity=%v&distance=%v"
	s, err := ts.G(str, uidSlice[8], unixTime, "sPlace48", "ePlace48", csLng, ceLat, ceLng, "003", "002", 8.2)
	writeString(s, err)
	buff.WriteString("########缺失sLng#########")
	str := "/route/dadd?uid=%v&startTime=%v&sPlace=%v&ePlace=%v&sLat=%v&eLat=%v&eLng=%v&sCity=%v&eCity=%v&distance=%v"
	s, err := ts.G(str, uidSlice[8], unixTime, "sPlace58", "ePlace58", csLat, ceLat, ceLng, "003", "002", 8.2)
	writeString(s, err)
	buff.WriteString("########缺失eLat#########")
	str := "/route/dadd?uid=%v&startTime=%v&sPlace=%v&ePlace=%v&sLat=%v&sLng=%v&eLng=%v&sCity=%v&eCity=%v&distance=%v"
	s, err := ts.G(str, uidSlice[8], unixTime, "sPlace68", "ePlace68", csLat, csLng, ceLng, "003", "002", 8.2)
	writeString(s, err)
	buff.WriteString("########缺失eLng#########")
	str := "/route/dadd?uid=%v&startTime=%v&sPlace=%v&ePlace=%v&sLat=%v&sLng=%v&eLat=%v&sCity=%v&eCity=%v&distance=%v"
	s, err := ts.G(str, uidSlice[8], unixTime, "sPlace78", "ePlace78", csLat, csLng, ceLat, "003", "002", 8.2)
	writeString(s, err)
	buff.WriteString("########缺失sCity#########")
	str := "/route/dadd?uid=%v&startTime=%v&sPlace=%v&ePlace=%v&sLat=%v&sLng=%v&eLat=%v&eLng=%v&eCity=%v&distance=%v"
	s, err := ts.G(str, uidSlice[8], unixTime, "sPlace88", "ePlace88", csLat, csLng, ceLat, ceLng, "002", 8.2)
	writeString(s, err)
	buff.WriteString("########缺失eCity#########")
	str := "/route/dadd?uid=%v&startTime=%v&sPlace=%v&ePlace=%v&sLat=%v&sLng=%v&eLat=%v&eLng=%v&sCity=%v&distance=%v"
	s, err := ts.G(str, uidSlice[8], unixTime, "sPlace98", "ePlace98", csLat, csLng, ceLat, ceLng, "003", 8.2)
	writeString(s, err)
	buff.WriteString("########缺失distance#########")
	str := "/route/dadd?uid=%v&startTime=%v&sPlace=%v&ePlace=%v&sLat=%v&sLng=%v&eLat=%v&eLng=%v&sCity=%v&eCity=%v"
	s, err := ts.G(str, uidSlice[8], unixTime, "sPlace08", "ePlace08", csLat, csLng, ceLat, ceLng, "003", "002")
	writeString(s, err)

	buff.WriteString("\n***********************错误参数格式加入****************\n")
	str := "/route/dadd?uid=%v&startTime=%v&sPlace=%v&ePlace=%v&sLat=%v&sLng=%v&eLat=%v&eLng=%v&sCity=%v&eCity=%v&distance=%v"
	s, err := ts.G(str, "userid", "unixTime", "sPlace8", "ePlace8", "csLat", "csLng", "ceLat", "ceLng", "003", "002", "8.2")
	writeString(s, err)

	buff.WriteString("\n***********************正常参数加入****************\n")
	unixTime := t.Unix()
	str := "/route/dadd?uid=%v&startTime=%v&sPlace=%v&ePlace=%v&sLat=%v&sLng=%v&eLat=%v&eLng=%v&sCity=%v&eCity=%v&distance=%v"
	for i := 0; i < 8; i++ {
		f := rand.Float64() * 0.0015
		s, err := ts.G(str, uidSlice[i], unixTime, "sPlace"+strconv.Itoa(i), "ePlace"+strconv.Itoa(i), csLat+f, csLng+f/2, ceLat+f, ceLng+f/2, "001", "002", 8.2)
		writeString(s, err)
	}
	//起点城市不一致
	s, err := ts.G(str, uidSlice[8], unixTime, "sPlace8", "ePlace8", csLat, csLng, ceLat, ceLng, "003", "002", 8.2)
	writeString(s, err)
	//终点城市不一致
	s, err := ts.G(str, uidSlice[9], unixTime, "sPlace9", "ePlace9", csLat, csLng, ceLat, ceLng, "001", "003", 8.2)
	writeString(s, err)

}
开发者ID:caowenhua,项目名称:gocar,代码行数:71,代码来源:routeapi_test.go


注:本文中的testing.T.Unix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。