コード例 #1
0
func SendGetBuilder(cfg *config.Config, id string) *httptest.ResponseRecorder {
	var (
		buildbot = &MockBuildbotApi{url: cfg.BuildBotUrl}
		router   = GetNewTestRouter(cfg, buildbot)
		handler  = NewBuildersHandler(cfg, buildbot, cc.NewFileCache(), logging.MustGetLogger("test"))
	)

	router.Get("/builder/:id", handler.GetBuilder)

	res := httptest.NewRecorder()
	req, _ := http.NewRequest("GET", "/builder/"+id, nil)

	router.ServeHTTP(res, req)
	return res
}
コード例 #2
0
ファイル: main.go プロジェクト: ghophp/buildbot-dashboard
func main() {
	logging.SetFormatter(format)

	cfg, err := config.NewConfig(&config.FlagLoader{})
	if err != nil {
		panic(err)
	}

	var (
		cache    = cc.NewFileCache()
		buildbot = bb.NewBuildbotApi(cfg.BuildBotUrl, pool.NewRequestPool(), log)

		indexHandler    = handler.NewIndexHandler()
		buildersHandler = handler.NewBuildersHandler(cfg, buildbot, cache, log)
	)

	router := martini.Classic()
	router.Use(staticbin.Static("static/assets", Asset))
	router.Use(render.RendererBin(Asset, AssetNames(), render.Options{
		Directory:  "static/templates",
		Layout:     "layout",
		Extensions: []string{".tmpl", ".html"},
		Charset:    "UTF-8",
		IndentJSON: true,
		Funcs: []template.FuncMap{
			{
				"refreshSec": func() string {
					return strconv.Itoa(cfg.RefreshSec)
				},
				"buildbotUrl": func() string {
					return buildbot.GetUrl()
				},
				"hashedUrl": func() string {
					return cfg.HashedUrl
				},
			},
		},
	}))

	router.Get("/", indexHandler.ServeHTTP)
	router.Get("/builders", buildersHandler.GetBuilders)
	router.Get("/builder/:id", buildersHandler.GetBuilder)

	router.Run()
}