示例#1
0
func TestInfo(t *testing.T) {
	body := `{
     "Containers":11,
     "Images":16,
     "Debug":0,
     "NFd":11,
     "NGoroutines":21,
     "MemoryLimit":1,
     "SwapLimit":0
}`
	fakeRT := FakeRoundTripper{message: body, status: http.StatusOK}
	client := newTestClient(&fakeRT)
	expected := engine.Env{}
	expected.SetInt("Containers", 11)
	expected.SetInt("Images", 16)
	expected.SetBool("Debug", false)
	expected.SetInt("NFd", 11)
	expected.SetInt("NGoroutines", 21)
	expected.SetBool("MemoryLimit", true)
	expected.SetBool("SwapLimit", false)
	info, err := client.Info()
	if err != nil {
		t.Fatal(err)
	}
	infoSlice := []string(*info)
	expectedSlice := []string(expected)
	sort.Strings(infoSlice)
	sort.Strings(expectedSlice)
	if !reflect.DeepEqual(expectedSlice, infoSlice) {
		t.Errorf("Info(): Wrong result.\nWant %#v.\nGot %#v.", expected, *info)
	}
	req := fakeRT.requests[0]
	if req.Method != "GET" {
		t.Errorf("Info(): Wrong HTTP method. Want GET. Got %s.", req.Method)
	}
	u, _ := url.Parse(client.getURL("/info"))
	if req.URL.Path != u.Path {
		t.Errorf("Info(): Wrong request path. Want %q. Got %q.", u.Path, req.URL.Path)
	}
}