func (s *dataCleansingSuite) TestUnescapeKey_UnescapesDollarSigns(c *gc.C) { before := map[string]interface{}{ "\uff04" + "a": "c", } after := utils.UnescapeKeys(before) c.Check(after, gc.DeepEquals, map[string]interface{}{ "$a": "c", }) }
func (s *dataCleansingSuite) TestUnescapeKey_UnescapesPeriods(c *gc.C) { before := map[string]interface{}{ "a" + "\uff0e" + "b": "c", } after := utils.UnescapeKeys(before) c.Check(after, gc.DeepEquals, map[string]interface{}{ "a.b": "c", }) }
func (s *dataCleansingSuite) TestUnescapeKeys_RecursivelyUnescapes(c *gc.C) { before := map[string]interface{}{ "\uff04" + "a": "c", "b": map[string]interface{}{ "\uff04" + "foo" + "\uff0e" + "bar": "baz", }, } after := utils.UnescapeKeys(before) c.Check(after, gc.DeepEquals, map[string]interface{}{ "$a": "c", "b": map[string]interface{}{ "$foo.bar": "baz", }, }) }
func statusHistory(args *statusHistoryArgs) ([]status.StatusInfo, error) { filter := args.filter if err := args.filter.Validate(); err != nil { return nil, errors.Annotate(err, "validating arguments") } statusHistory, closer := args.st.getCollection(statusesHistoryC) defer closer() var ( docs []historicalStatusDoc query mongo.Query ) baseQuery := bson.M{"globalkey": args.globalKey} if filter.Delta != nil { delta := *filter.Delta // TODO(perrito666) 2016-05-02 lp:1558657 updated := time.Now().Add(-delta) baseQuery = bson.M{"updated": bson.M{"$gt": updated.UnixNano()}, "globalkey": args.globalKey} } if filter.Date != nil { baseQuery = bson.M{"updated": bson.M{"$gt": filter.Date.UnixNano()}, "globalkey": args.globalKey} } query = statusHistory.Find(baseQuery).Sort("-updated") if filter.Size > 0 { query = query.Limit(filter.Size) } err := query.All(&docs) if err == mgo.ErrNotFound { return []status.StatusInfo{}, errors.NotFoundf("status history") } else if err != nil { return []status.StatusInfo{}, errors.Annotatef(err, "cannot get status history") } results := make([]status.StatusInfo, len(docs)) for i, doc := range docs { results[i] = status.StatusInfo{ Status: doc.Status, Message: doc.StatusInfo, Data: utils.UnescapeKeys(doc.StatusData), Since: unixNanoToTime(doc.Updated), } } return results, nil }
// getStatus retrieves the status document associated with the given // globalKey and converts it to a StatusInfo. If the status document // is not found, a NotFoundError referencing badge will be returned. func getStatus(st *State, globalKey, badge string) (_ status.StatusInfo, err error) { defer errors.DeferredAnnotatef(&err, "cannot get status") statuses, closer := st.getCollection(statusesC) defer closer() var doc statusDoc err = statuses.FindId(globalKey).One(&doc) if err == mgo.ErrNotFound { return status.StatusInfo{}, errors.NotFoundf(badge) } else if err != nil { return status.StatusInfo{}, errors.Trace(err) } return status.StatusInfo{ Status: doc.Status, Message: doc.StatusInfo, Data: utils.UnescapeKeys(doc.StatusData), Since: unixNanoToTime(doc.Updated), }, nil }