api_report_test.go 848 B

1234567891011121314151617181920212223242526272829303132333435
  1. package app_test
  2. import (
  3. "net/http/httptest"
  4. "testing"
  5. "github.com/gorilla/mux"
  6. "github.com/ugorji/go/codec"
  7. "github.com/weaveworks/scope/app"
  8. "github.com/weaveworks/scope/report"
  9. "github.com/weaveworks/scope/test/fixture"
  10. )
  11. func topologyServer() *httptest.Server {
  12. router := mux.NewRouter().SkipClean(true)
  13. app.RegisterTopologyRoutes(router, app.StaticCollector(fixture.Report), map[string]bool{"foo_capability": true})
  14. return httptest.NewServer(router)
  15. }
  16. func TestAPIReport(t *testing.T) {
  17. ts := topologyServer()
  18. defer ts.Close()
  19. is404(t, ts, "/api/report/foobar")
  20. var body = getRawJSON(t, ts, "/api/report")
  21. // fmt.Printf("Body: %v\n", string(body))
  22. var r report.Report
  23. decoder := codec.NewDecoderBytes(body, &codec.JsonHandle{})
  24. if err := decoder.Decode(&r); err != nil {
  25. t.Fatalf("JSON parse error: %s", err)
  26. }
  27. }