Exemplo n.º 1
0
func (s *S) TestWriteError(c *check.C) {
	s.T.WriteError(errors.New("my error", http.StatusInternalServerError))
	c.Assert(s.T.statusCode, check.Equals, http.StatusInternalServerError)
	c.Assert(s.Writer.Code, check.Equals, http.StatusInternalServerError)

	json, err := simplejson.NewFromReader(s.Writer.Body)
	c.Assert(err, check.IsNil)

	msg := json.Get("errors").GetIndex(0).Get("_all").GetIndex(0).MustString()
	c.Assert(msg, check.Equals, "my error")
}
Exemplo n.º 2
0
Arquivo: mongo.go Projeto: ricobl/beat
import (
	_ "github.com/backstage/beat/config"
	"github.com/backstage/beat/db"
	"github.com/backstage/beat/errors"
	"github.com/backstage/beat/schemas"
	simplejson "github.com/bitly/go-simplejson"
	"github.com/spf13/viper"
	"gopkg.in/mgo.v2"
	"gopkg.in/mgo.v2/bson"
)

func init() {
	viper.SetDefault("mongo.uri", "localhost:27017/backstage_beat_local")
}

var ItemSchemaNotFound = errors.New("item-schema not found", 404)

type MongoDB struct {
	dialInfo *mgo.DialInfo
	session  *mgo.Session
}

func New() (*MongoDB, error) {
	d := &MongoDB{}

	var err error
	d.dialInfo, err = mgo.ParseURL(viper.GetString("mongo.uri"))
	if err != nil {
		return nil, err
	}
Exemplo n.º 3
0
package db

import (
	"github.com/backstage/beat/errors"
	"github.com/backstage/beat/schemas"
)

var ItemSchemaNotFound = errors.New("item-schema not found", 404)
var CollectionSchemaNotFound = errors.New("collection-schema not found", 404)

type Database interface {
	CreateItemSchema(*schemas.ItemSchema) errors.Error
	FindItemSchema(*Filter) (*ItemSchemasReply, errors.Error)
	FindOneItemSchema(*Filter) (*schemas.ItemSchema, errors.Error)
	FindItemSchemaByCollectionName(string) (*schemas.ItemSchema, errors.Error)
	DeleteItemSchemaByCollectionName(string) errors.Error
}

type ItemSchemasReply struct {
	Items []*schemas.ItemSchema `json:"items"`
}