Exemplo n.º 1
0
func TestPt1Record_Start(t *testing.T) {
	assert := wcg.NewAssert(t)
	now := time.Now()

	tvrecord := tv.NewTvRecord(
		"Title",
		"Category",
		now,
		now.Add(time.Duration(5)*time.Second),
		"cid",
		"sid",
		"uid",
	)
	util.WithTempDir(func(dir string) {
		record := NewPt1Record(tvrecord, genPt1Config(dir))
		err := record.Start()
		assert.Nil(err, "Pt1Record started.")
		time.Sleep(1 * time.Second)
		assert.Ok(record.IsRunning(), "Pt1Record is running.")

		err = record.Stop()
		assert.Nil(err, "Stop record.")

		err = util.WaitFor(func() bool {
			return record.IsRunning() == false
		}, 10)
		assert.Nil(err, "Pt1Record has stopped.")

		content, _ := ioutil.ReadFile(record.filepath)
		lines := bytes.Split(content, []byte("\n"))
		assert.EqStr("OK", string(lines[len(lines)-1]), "Check the mock record content.")
	})
}
Exemplo n.º 2
0
func genTestRecord() *tv.TvRecord {
	start := time.Now()
	end := start.Add(50 * time.Minute)
	return tv.NewTvRecord(
		"title", "category",
		start, end,
		"20", "hd", "me",
	)
}
Exemplo n.º 3
0
func init() {
	recordFormValidator.Field("start_at").Func(util.ValidateDateTimeString)
	recordFormValidator.Field("end_at").Func(util.ValidateDateTimeString)

	app.Api.Get("/records/",
		func(res *wcg.Response, req *wcg.Request) {
			ctx := gae.NewContext(req)
			d := NewRecordCacheDriver(app.Key, ctx, req.Logger)
			if list, err := d.GetRecords(req.Query("force") == "1"); err != nil {
				app.Api.InternalError(res, req, err)
			} else {
				res.WriteJson(list)
			}
		},
	)
	app.Api.Post("/records/", lib.Family.Required(
		func(res *wcg.Response, req *wcg.Request) {
			if err := recordFormValidator.Eval(req.HttpRequest().PostForm); err != nil {
				app.Api.BadRequest(res, req, err)
				return
			}

			ctx := gae.NewContext(req)
			d := NewRecordCacheDriver(app.Key, ctx, req.Logger)
			start, _ := util.ParseDateTime(req.Form("start_at"))
			end, _ := util.ParseDateTime(req.Form("end_at"))
			rec := tv.NewTvRecord(
				req.Form("title"), req.Form("category"),
				start, end,
				req.Form("cid"), req.Form("sid"),
				req.User.Id(),
			)

			if err := d.Save(rec); err != nil {
				app.Api.InternalError(res, req, err)
			} else {
				app.Api.Created(res, req, fmt.Sprintf("/records/%s.json", rec.Key()))
			}
		},
	))

	app.Api.Delete("/records/:key.json", lib.Family.Required(
		func(res *wcg.Response, req *wcg.Request) {
			d := NewRecordCacheDriver(app.Key, gae.NewContext(req), req.Logger)
			if err := d.Delete(req.Param("key")); err != nil {
				app.Api.InternalError(res, req, err)
				return
			} else {
				app.Api.Ok(res, req)
			}
		},
	))
}