Exemple #1
0
// RunServer starts a server up.
func RunServer(v *config.Verbosity, laddr string) error {
	gf := func() Injector {
		g := graph.BuildGraph(&bytes.Buffer{}, os.Stdout, os.Stdout)
		g.Add(v)
		return g
	}
	s := New(laddr, gf)
	return s.ListenAndServe()
}
Exemple #2
0
// BuildCLIGraph builds the CLI DI graph.
func BuildCLIGraph(cli *CLI, root *Sous, in io.Reader, out, err io.Writer) *graph.SousGraph {
	g := graph.BuildGraph(in, out, err)
	g.Add(cli)
	g.Add(root)
	g.Add(func(c *CLI) graph.Out {
		return graph.Out{Output: c.Out}
	})
	g.Add(func(c *CLI) graph.ErrOut {
		return graph.ErrOut{Output: c.Err}
	})
	cli.SousGraph = g //Ugh, weird state.

	return g
}
Exemple #3
0
func testInject(thing interface{}) error {
	gf := func() Injector {
		g := graph.BuildGraph(&bytes.Buffer{}, os.Stdout, os.Stdout)
		g.Add(&config.Verbosity{})
		return g
	}
	mh := &MetaHandler{graphFac: gf}
	w := httptest.NewRecorder()
	r, err := http.NewRequest("GET", "/test", nil)
	if err != nil {
		panic(err)
	}
	p := httprouter.Params{}

	return mh.ExchangeGraph(w, r, p).Inject(thing)
}
Exemple #4
0
func TestOverallRouter(t *testing.T) {
	assert := assert.New(t)

	gf := func() Injector {
		g := graph.BuildGraph(&bytes.Buffer{}, os.Stdout, os.Stdout)
		g.Add(&config.Verbosity{})
		return g
	}
	ts := httptest.NewServer(SousRouteMap.BuildRouter(gf))
	defer ts.Close()

	res, err := http.Get(ts.URL + "/gdm")
	assert.NoError(err)
	gdm, err := ioutil.ReadAll(res.Body)
	res.Body.Close()
	assert.NoError(err)
	assert.Regexp(`"Deployments"`, string(gdm))
	assert.NotEqual(res.Header.Get("Etag"), "")
}