Beispiel #1
0
func NewCacheAssertions(t assert.TestingT) *CacheAssertions {
	backend := memory.New()
	return &CacheAssertions{
		assert.New(t),
		backend,
		cache.New(backend),
	}
}
Beispiel #2
0
func main() {
	var err error

	cborRPCBind := flag.String("cborrpc", ":5932",
		"[ip]:port for CBOR-RPC interface")
	httpBind := flag.String("http", ":5980",
		"[ip]:port for HTTP REST interface")
	backend := backend.Backend{Implementation: "memory", Address: ""}
	flag.Var(&backend, "backend", "impl[:address] of the storage backend")
	config := flag.String("config", "", "global configuration YAML file")
	logRequests := flag.Bool("log-requests", false, "log all requests")
	flag.Parse()

	var gConfig map[string]interface{}
	if *config != "" {
		gConfig, err = loadConfigYaml(*config)
		if err != nil {
			logrus.WithFields(logrus.Fields{
				"err": err,
			}).Fatal("Could not load YAML configuration")
			return
		}
	}

	coordinate, err := backend.Coordinate()
	if err != nil {
		logrus.WithFields(logrus.Fields{
			"err": err,
		}).Fatal("Could not create Coordinate backend")
		return
	}
	coordinate = cache.New(coordinate)

	var reqLogger *logrus.Logger
	if *logRequests {
		stdlog := logrus.StandardLogger()
		reqLogger = &logrus.Logger{
			Out:       stdlog.Out,
			Formatter: stdlog.Formatter,
			Hooks:     stdlog.Hooks,
			Level:     logrus.DebugLevel,
		}
	}

	go ServeCBORRPC(coordinate, gConfig, "tcp", *cborRPCBind, reqLogger)
	go ServeHTTP(coordinate, *httpBind)
	select {}
}
func init() {
	backend := memory.NewWithClock(coordinatetest.Clock)
	backend = cache.New(backend)
	coordinatetest.Coordinate = backend
}