4f0d95fa | package client // import "github.com/docker/docker/client" |
7c36a1af | import ( "bytes" |
7d62e40f | "context" |
7c36a1af | "encoding/json" "fmt" "io/ioutil" "net/http" "strings" "testing" "github.com/docker/docker/api/types/swarm" |
161e0a90 | "github.com/docker/docker/errdefs" |
3e6bbefd | "github.com/pkg/errors" |
7c36a1af | ) func TestTaskInspectError(t *testing.T) { client := &Client{ |
9a072adf | client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
7c36a1af | } _, _, err := client.TaskInspectWithRaw(context.Background(), "nothing") |
161e0a90 | if !errdefs.IsSystem(err) { |
de10c7d0 | t.Fatalf("expected a Server Error, got %[1]T: %[1]v", err) |
161e0a90 | } |
7c36a1af | } |
3e6bbefd | func TestTaskInspectWithEmptyID(t *testing.T) { client := &Client{ client: newMockClient(func(req *http.Request) (*http.Response, error) { return nil, errors.New("should not make request") }), } _, _, err := client.TaskInspectWithRaw(context.Background(), "") if !IsErrNotFound(err) { t.Fatalf("Expected NotFoundError, got %v", err) } } |
7c36a1af | func TestTaskInspect(t *testing.T) { expectedURL := "/tasks/task_id" client := &Client{ |
9a072adf | client: newMockClient(func(req *http.Request) (*http.Response, error) { |
7c36a1af | if !strings.HasPrefix(req.URL.Path, expectedURL) { return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) } content, err := json.Marshal(swarm.Task{ ID: "task_id", }) if err != nil { return nil, err } return &http.Response{ StatusCode: http.StatusOK, Body: ioutil.NopCloser(bytes.NewReader(content)), }, nil }), } taskInspect, _, err := client.TaskInspectWithRaw(context.Background(), "task_id") if err != nil { t.Fatal(err) } if taskInspect.ID != "task_id" { t.Fatalf("expected `task_id`, got %s", taskInspect.ID) } } |