예제 #1
0
파일: migrate_test.go 프로젝트: tsuru/tsuru
func (s *S) checkEvtMatch(evt *event.Event, c *check.C) {
	rawEvt := bson.M{
		"_id":        evt.UniqueID,
		"uniqueid":   evt.UniqueID,
		"starttime":  evt.StartTime,
		"endtime":    evt.EndTime,
		"target":     evt.Target,
		"kind":       evt.Kind,
		"owner":      evt.Owner,
		"error":      evt.Error,
		"log":        evt.Log,
		"cancelable": evt.Cancelable,
		"running":    evt.Running,
	}
	conn, err := db.Conn()
	c.Assert(err, check.IsNil)
	defer conn.Close()
	err = conn.Events().Insert(rawEvt)
	c.Assert(err, check.IsNil)
	err = MigrateRCEvents()
	c.Assert(err, check.IsNil)
	evts, err := event.All()
	c.Assert(err, check.IsNil)
	c.Assert(evts, check.HasLen, 1)
	evt.ID = evts[0].ID
	c.Assert(&evts[0], check.DeepEquals, evt)

}
예제 #2
0
파일: checker.go 프로젝트: tsuru/tsuru
func (hasEventChecker) Check(params []interface{}, names []string) (bool, string) {
	var evt EventDesc
	switch params[0].(type) {
	case EventDesc:
		evt = params[0].(EventDesc)
	case *EventDesc:
		evt = *params[0].(*EventDesc)
	default:
		return false, "First parameter must be of type EventDesc or *EventDesc"
	}
	conn, err := db.Conn()
	if err != nil {
		return false, err.Error()
	}
	defer conn.Close()
	if evt.IsEmpty {
		var n int
		n, err = conn.Events().Find(nil).Count()
		if err != nil {
			return false, err.Error()
		}
		if n != 0 {
			return false, fmt.Sprintf("expected 0 events, got %d", n)
		}
		return true, ""
	}
	query := map[string]interface{}{
		"target":     evt.Target,
		"kind.name":  evt.Kind,
		"owner.name": evt.Owner,
		"running":    false,
	}
	queryPartCustom(query, "startcustomdata", evt.StartCustomData)
	queryPartCustom(query, "endcustomdata", evt.EndCustomData)
	queryPartCustom(query, "othercustomdata", evt.OtherCustomData)
	if evt.LogMatches != "" {
		query["log"] = bson.M{"$regex": evt.LogMatches}
	}
	if evt.ErrorMatches != "" {
		query["error"] = bson.M{"$regex": evt.ErrorMatches}
	} else {
		query["error"] = ""
	}
	n, err := conn.Events().Find(query).Count()
	if err != nil {
		return false, err.Error()
	}
	if n == 0 {
		all, _ := event.All()
		msg := fmt.Sprintf("Event not found. Existing events in DB: %s", debugEvts(all))
		return false, msg
	}
	if n > 1 {
		return false, "Multiple events match query"
	}
	return true, ""
}