Files
weave-scope/app/origin_host_test.go
Peter Bourgon c8fbea0f15 Move fixture to its own package
We want to be able to import test from packages like probe/endpoint, in
order to use utility functions like poll. But that causes an import
cycle with the current layout. We got around this using dot-imports so
far, but it's ugly and unnecessary: fixture can be its own package.
2015-10-27 10:36:53 +00:00

34 lines
771 B
Go

package main
import (
"encoding/json"
"fmt"
"net/http/httptest"
"testing"
"github.com/weaveworks/scope/test/fixture"
)
func TestAPIOriginHost(t *testing.T) {
ts := httptest.NewServer(Router(StaticReport{}))
defer ts.Close()
is404(t, ts, "/api/origin/foobar")
is404(t, ts, "/api/origin/host/foobar")
{
// Origin
body := getRawJSON(t, ts, fmt.Sprintf("/api/origin/host/%s", fixture.ServerHostNodeID))
var o OriginHost
if err := json.Unmarshal(body, &o); err != nil {
t.Fatalf("JSON parse error: %s", err)
}
if want, have := "Linux", o.OS; want != have {
t.Errorf("Origin error. Want %v, have %v", want, have)
}
if want, have := "0.01 0.01 0.01", o.Load; want != have {
t.Errorf("Origin error. Want %v, have %v", want, have)
}
}
}