Exemple #1
0
func timeToDT(t time.Time) string {
	var lists []orm.ParamsList
	e := models.Expire{"TestDID", t}
	e.Save()
	o.Raw("SELECT expire_time FROM expire WHERE document_id = ?", "TestDID").ValuesList(&lists)
	o.Raw("DELETE FROM expire WHERE document_id = ?", "TestDID").Exec()
	return lists[0][0].(string)
}
Exemple #2
0
func TestSpec(t *testing.T) {
	Convey("Given a expire time and save it to the database", t, func() {
		curTime := time.Now()
		exp := models.Expire{"76441e7c-310c-405a-89ce-c39bcd288c03", curTime}
		exp.Save()
		temp := GetExpiredTime(exp.DocumentId)
		Convey("Returned expire time should not be empty", func() {
			So(temp, ShouldNotBeEmpty)
		})
		Convey("Expire time should be correctly saved", func() {
			count := isSameTime(temp, timeToDT(exp.ExpireTime))
			So(count, ShouldBeGreaterThan, 19)
		})
		Convey("Expire time should be correctly updated", func() {
			exp.Update(time.Now())
			uTemp := GetExpiredTime(exp.DocumentId)
			count := isSameTime(uTemp, timeToDT(exp.ExpireTime))
			So(count, ShouldBeGreaterThan, 19)
		})
	})
}