summaryrefslogtreecommitdiff
path: root/client/task_inspect_test.go
diff options
context:
space:
mode:
authorMichael Crosby <crosbymichael@gmail.com>2016-09-06 11:46:37 -0700
committerMichael Crosby <crosbymichael@gmail.com>2016-09-07 11:05:58 -0700
commit7c36a1af031b510cd990cf488ee5998a3efb450f (patch)
tree477f7c37b71fbc6dc641d7b294b68e17d6c869ec /client/task_inspect_test.go
parent91e197d614547f0202e6ae9b8a24d88ee131d950 (diff)
downloaddocker-7c36a1af031b510cd990cf488ee5998a3efb450f.tar.gz
Move engine-api client package
This moves the engine-api client package to `/docker/docker/client`. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
Diffstat (limited to 'client/task_inspect_test.go')
-rw-r--r--client/task_inspect_test.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/client/task_inspect_test.go b/client/task_inspect_test.go
new file mode 100644
index 0000000000..2c73b37642
--- /dev/null
+++ b/client/task_inspect_test.go
@@ -0,0 +1,54 @@
+package client
+
+import (
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+ "net/http"
+ "strings"
+ "testing"
+
+ "github.com/docker/docker/api/types/swarm"
+ "golang.org/x/net/context"
+)
+
+func TestTaskInspectError(t *testing.T) {
+ client := &Client{
+ transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")),
+ }
+
+ _, _, err := client.TaskInspectWithRaw(context.Background(), "nothing")
+ if err == nil || err.Error() != "Error response from daemon: Server error" {
+ t.Fatalf("expected a Server Error, got %v", err)
+ }
+}
+
+func TestTaskInspect(t *testing.T) {
+ expectedURL := "/tasks/task_id"
+ client := &Client{
+ transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
+ 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)
+ }
+}