github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/worker/metrics/collect/export_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package collect 5 6 import ( 7 "github.com/juju/juju/worker/metrics/spool" 8 "github.com/juju/juju/worker/uniter/runner" 9 ) 10 11 var ( 12 // NewCollect allows patching the function that creates the metric collection 13 // entity. 14 NewCollect = newCollect 15 16 // NewRecorder allows patching the function that creates the metric recorder. 17 NewRecorder = &newRecorder 18 19 // NewHookContext returns a new hook context used to collect metrics. 20 // It is exported here for calling from tests, but not patching. 21 NewHookContext = newHookContext 22 23 // ReadCharm reads the charm directory and returns the charm url and 24 // metrics declared by the charm. 25 ReadCharm = &readCharm 26 27 // NewSocketListener creates a new socket listener with the provided 28 // socket path and connection handler. 29 NewSocketListener = &newSocketListener 30 ) 31 32 // Ensure hookContext is a runner.Context. 33 var _ runner.Context = (*hookContext)(nil) 34 35 type handlerSetterStopper interface { 36 SetHandler(spool.ConnectionHandler) 37 Stop() error 38 } 39 40 func NewSocketListenerFnc(listener handlerSetterStopper) func(string, spool.ConnectionHandler) (stopper, error) { 41 return func(_ string, handler spool.ConnectionHandler) (stopper, error) { 42 listener.SetHandler(handler) 43 return listener, nil 44 } 45 }