From 57230a7212f820b98f9c34cc8c750b3a0b9dbb43 Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Mon, 8 May 2017 09:33:45 -0700 Subject: [PATCH] rm client and vendor it instead Signed-off-by: Tibor Vass --- README.md | 1 - cli/command/cli.go | 2 +- cli/command/container/create.go | 2 +- cli/command/container/exec.go | 2 +- cli/command/container/stats_helpers.go | 2 +- cli/command/container/tty.go | 2 +- cli/command/container/utils.go | 2 +- cli/command/idresolver/client_test.go | 2 +- cli/command/idresolver/idresolver.go | 2 +- cli/command/image/client_test.go | 2 +- cli/command/node/client_test.go | 2 +- cli/command/node/cmd.go | 2 +- cli/command/secret/client_test.go | 2 +- cli/command/service/inspect.go | 2 +- cli/command/service/logs.go | 2 +- cli/command/service/opts.go | 2 +- cli/command/service/parse.go | 2 +- cli/command/service/progress/progress.go | 2 +- cli/command/service/update.go | 2 +- cli/command/stack/client_test.go | 2 +- cli/command/stack/common.go | 2 +- cli/command/stack/deploy_composefile.go | 4 +- cli/command/stack/list.go | 2 +- cli/command/swarm/client_test.go | 2 +- cli/command/system/inspect.go | 2 +- cli/command/volume/client_test.go | 2 +- cli/compose/convert/service.go | 2 +- cli/internal/test/cli.go | 2 +- client/checkpoint_create_test.go | 73 ----- client/checkpoint_delete_test.go | 54 ---- client/checkpoint_list_test.go | 68 ----- client/client_mock_test.go | 53 ---- client/client_test.go | 284 ------------------ client/container_commit_test.go | 96 ------ client/container_copy_test.go | 244 --------------- client/container_create_test.go | 118 -------- client/container_diff_test.go | 61 ---- client/container_exec_test.go | 157 ---------- client/container_export_test.go | 50 --- client/container_inspect_test.go | 125 -------- client/container_kill_test.go | 46 --- client/container_list_test.go | 96 ------ client/container_logs_test.go | 133 -------- client/container_pause_test.go | 41 --- client/container_prune_test.go | 124 -------- client/container_remove_test.go | 59 ---- client/container_rename_test.go | 46 --- client/container_resize_test.go | 82 ----- client/container_restart_test.go | 48 --- client/container_start_test.go | 58 ---- client/container_stats_test.go | 70 ----- client/container_stop_test.go | 48 --- client/container_top_test.go | 74 ----- client/container_unpause_test.go | 41 --- client/container_update_test.go | 58 ---- client/container_wait_test.go | 70 ----- client/events_test.go | 165 ---------- client/image_build_test.go | 233 -------------- client/image_create_test.go | 76 ----- client/image_history_test.go | 60 ---- client/image_import_test.go | 81 ----- client/image_inspect_test.go | 71 ----- client/image_list_test.go | 159 ---------- client/image_load_test.go | 95 ------ client/image_prune_test.go | 119 -------- client/image_pull_test.go | 199 ------------ client/image_push_test.go | 180 ----------- client/image_remove_test.go | 95 ------ client/image_save_test.go | 58 ---- client/image_search_test.go | 166 ---------- client/image_tag_test.go | 143 --------- client/info_test.go | 76 ----- client/network_connect_test.go | 111 ------- client/network_create_test.go | 72 ----- client/network_disconnect_test.go | 64 ---- client/network_inspect_test.go | 96 ------ client/network_list_test.go | 108 ------- client/network_prune_test.go | 112 ------- client/network_remove_test.go | 47 --- client/node_inspect_test.go | 65 ---- client/node_list_test.go | 94 ------ client/node_remove_test.go | 69 ----- client/node_update_test.go | 49 --- client/plugin_disable_test.go | 48 --- client/plugin_enable_test.go | 48 --- client/plugin_inspect_test.go | 54 ---- client/plugin_list_test.go | 107 ------- client/plugin_push_test.go | 51 ---- client/plugin_remove_test.go | 49 --- client/plugin_set_test.go | 47 --- client/request_test.go | 92 ------ client/secret_create_test.go | 57 ---- client/secret_inspect_test.go | 65 ---- client/secret_list_test.go | 94 ------ client/secret_remove_test.go | 47 --- client/secret_update_test.go | 49 --- client/service_create_test.go | 57 ---- client/service_inspect_test.go | 66 ---- client/service_list_test.go | 94 ------ client/service_logs_test.go | 133 -------- client/service_remove_test.go | 47 --- client/service_update_test.go | 77 ----- client/swarm_init_test.go | 54 ---- client/swarm_inspect_test.go | 56 ---- client/swarm_join_test.go | 51 ---- client/swarm_leave_test.go | 66 ---- client/swarm_update_test.go | 49 --- client/task_inspect_test.go | 54 ---- client/task_list_test.go | 94 ------ client/testdata/ca.pem | 18 -- client/testdata/cert.pem | 18 -- client/testdata/key.pem | 27 -- client/volume_create_test.go | 75 ----- client/volume_inspect_test.go | 76 ----- client/volume_list_test.go | 98 ------ client/volume_remove_test.go | 47 --- cmd/docker/docker.go | 2 +- .../docker/docker/client}/README.md | 4 +- .../docker/client}/checkpoint_create.go | 0 .../docker/client}/checkpoint_delete.go | 0 .../docker/docker/client}/checkpoint_list.go | 0 .../docker/docker/client}/client.go | 2 +- .../docker/docker/client}/client_unix.go | 0 .../docker/docker/client}/client_windows.go | 0 .../docker/docker/client}/container_attach.go | 0 .../docker/docker/client}/container_commit.go | 0 .../docker/docker/client}/container_copy.go | 0 .../docker/docker/client}/container_create.go | 0 .../docker/docker/client}/container_diff.go | 0 .../docker/docker/client}/container_exec.go | 0 .../docker/docker/client}/container_export.go | 0 .../docker/client}/container_inspect.go | 0 .../docker/docker/client}/container_kill.go | 0 .../docker/docker/client}/container_list.go | 0 .../docker/docker/client}/container_logs.go | 0 .../docker/docker/client}/container_pause.go | 0 .../docker/docker/client}/container_prune.go | 0 .../docker/docker/client}/container_remove.go | 0 .../docker/docker/client}/container_rename.go | 0 .../docker/docker/client}/container_resize.go | 0 .../docker/client}/container_restart.go | 0 .../docker/docker/client}/container_start.go | 0 .../docker/docker/client}/container_stats.go | 0 .../docker/docker/client}/container_stop.go | 0 .../docker/docker/client}/container_top.go | 0 .../docker/client}/container_unpause.go | 0 .../docker/docker/client}/container_update.go | 0 .../docker/docker/client}/container_wait.go | 0 .../docker/docker/client}/disk_usage.go | 0 .../docker/docker/client}/errors.go | 0 .../docker/docker/client}/events.go | 0 .../docker/docker/client}/hijack.go | 0 .../docker/docker/client}/image_build.go | 0 .../docker/docker/client}/image_create.go | 0 .../docker/docker/client}/image_history.go | 0 .../docker/docker/client}/image_import.go | 0 .../docker/docker/client}/image_inspect.go | 0 .../docker/docker/client}/image_list.go | 0 .../docker/docker/client}/image_load.go | 0 .../docker/docker/client}/image_prune.go | 0 .../docker/docker/client}/image_pull.go | 0 .../docker/docker/client}/image_push.go | 0 .../docker/docker/client}/image_remove.go | 0 .../docker/docker/client}/image_save.go | 0 .../docker/docker/client}/image_search.go | 0 .../docker/docker/client}/image_tag.go | 0 .../github.com/docker/docker/client}/info.go | 0 .../docker/docker/client}/interface.go | 0 .../docker/client}/interface_experimental.go | 0 .../docker/docker/client}/interface_stable.go | 0 .../github.com/docker/docker/client}/login.go | 0 .../docker/docker/client}/network_connect.go | 0 .../docker/docker/client}/network_create.go | 0 .../docker/client}/network_disconnect.go | 0 .../docker/docker/client}/network_inspect.go | 0 .../docker/docker/client}/network_list.go | 0 .../docker/docker/client}/network_prune.go | 0 .../docker/docker/client}/network_remove.go | 0 .../docker/docker/client}/node_inspect.go | 0 .../docker/docker/client}/node_list.go | 0 .../docker/docker/client}/node_remove.go | 0 .../docker/docker/client}/node_update.go | 0 .../github.com/docker/docker/client}/ping.go | 0 .../docker/docker/client}/plugin_create.go | 0 .../docker/docker/client}/plugin_disable.go | 0 .../docker/docker/client}/plugin_enable.go | 0 .../docker/docker/client}/plugin_inspect.go | 0 .../docker/docker/client}/plugin_install.go | 0 .../docker/docker/client}/plugin_list.go | 0 .../docker/docker/client}/plugin_push.go | 0 .../docker/docker/client}/plugin_remove.go | 0 .../docker/docker/client}/plugin_set.go | 0 .../docker/docker/client}/plugin_upgrade.go | 0 .../docker/docker/client}/request.go | 1 - .../docker/docker/client}/secret_create.go | 0 .../docker/docker/client}/secret_inspect.go | 0 .../docker/docker/client}/secret_list.go | 0 .../docker/docker/client}/secret_remove.go | 0 .../docker/docker/client}/secret_update.go | 0 .../docker/docker/client}/service_create.go | 0 .../docker/docker/client}/service_inspect.go | 0 .../docker/docker/client}/service_list.go | 0 .../docker/docker/client}/service_logs.go | 0 .../docker/docker/client}/service_remove.go | 0 .../docker/docker/client}/service_update.go | 0 .../docker/client}/swarm_get_unlock_key.go | 0 .../docker/docker/client}/swarm_init.go | 0 .../docker/docker/client}/swarm_inspect.go | 0 .../docker/docker/client}/swarm_join.go | 0 .../docker/docker/client}/swarm_leave.go | 0 .../docker/docker/client}/swarm_unlock.go | 0 .../docker/docker/client}/swarm_update.go | 0 .../docker/docker/client}/task_inspect.go | 0 .../docker/docker/client}/task_list.go | 0 .../docker/docker/client}/task_logs.go | 0 .../docker/docker/client}/transport.go | 8 + .../github.com/docker/docker/client}/utils.go | 3 +- .../docker/docker/client}/version.go | 0 .../docker/docker/client}/volume_create.go | 0 .../docker/docker/client}/volume_inspect.go | 0 .../docker/docker/client}/volume_list.go | 0 .../docker/docker/client}/volume_prune.go | 0 .../docker/docker/client}/volume_remove.go | 0 223 files changed, 41 insertions(+), 7441 deletions(-) delete mode 100644 client/checkpoint_create_test.go delete mode 100644 client/checkpoint_delete_test.go delete mode 100644 client/checkpoint_list_test.go delete mode 100644 client/client_mock_test.go delete mode 100644 client/client_test.go delete mode 100644 client/container_commit_test.go delete mode 100644 client/container_copy_test.go delete mode 100644 client/container_create_test.go delete mode 100644 client/container_diff_test.go delete mode 100644 client/container_exec_test.go delete mode 100644 client/container_export_test.go delete mode 100644 client/container_inspect_test.go delete mode 100644 client/container_kill_test.go delete mode 100644 client/container_list_test.go delete mode 100644 client/container_logs_test.go delete mode 100644 client/container_pause_test.go delete mode 100644 client/container_prune_test.go delete mode 100644 client/container_remove_test.go delete mode 100644 client/container_rename_test.go delete mode 100644 client/container_resize_test.go delete mode 100644 client/container_restart_test.go delete mode 100644 client/container_start_test.go delete mode 100644 client/container_stats_test.go delete mode 100644 client/container_stop_test.go delete mode 100644 client/container_top_test.go delete mode 100644 client/container_unpause_test.go delete mode 100644 client/container_update_test.go delete mode 100644 client/container_wait_test.go delete mode 100644 client/events_test.go delete mode 100644 client/image_build_test.go delete mode 100644 client/image_create_test.go delete mode 100644 client/image_history_test.go delete mode 100644 client/image_import_test.go delete mode 100644 client/image_inspect_test.go delete mode 100644 client/image_list_test.go delete mode 100644 client/image_load_test.go delete mode 100644 client/image_prune_test.go delete mode 100644 client/image_pull_test.go delete mode 100644 client/image_push_test.go delete mode 100644 client/image_remove_test.go delete mode 100644 client/image_save_test.go delete mode 100644 client/image_search_test.go delete mode 100644 client/image_tag_test.go delete mode 100644 client/info_test.go delete mode 100644 client/network_connect_test.go delete mode 100644 client/network_create_test.go delete mode 100644 client/network_disconnect_test.go delete mode 100644 client/network_inspect_test.go delete mode 100644 client/network_list_test.go delete mode 100644 client/network_prune_test.go delete mode 100644 client/network_remove_test.go delete mode 100644 client/node_inspect_test.go delete mode 100644 client/node_list_test.go delete mode 100644 client/node_remove_test.go delete mode 100644 client/node_update_test.go delete mode 100644 client/plugin_disable_test.go delete mode 100644 client/plugin_enable_test.go delete mode 100644 client/plugin_inspect_test.go delete mode 100644 client/plugin_list_test.go delete mode 100644 client/plugin_push_test.go delete mode 100644 client/plugin_remove_test.go delete mode 100644 client/plugin_set_test.go delete mode 100644 client/request_test.go delete mode 100644 client/secret_create_test.go delete mode 100644 client/secret_inspect_test.go delete mode 100644 client/secret_list_test.go delete mode 100644 client/secret_remove_test.go delete mode 100644 client/secret_update_test.go delete mode 100644 client/service_create_test.go delete mode 100644 client/service_inspect_test.go delete mode 100644 client/service_list_test.go delete mode 100644 client/service_logs_test.go delete mode 100644 client/service_remove_test.go delete mode 100644 client/service_update_test.go delete mode 100644 client/swarm_init_test.go delete mode 100644 client/swarm_inspect_test.go delete mode 100644 client/swarm_join_test.go delete mode 100644 client/swarm_leave_test.go delete mode 100644 client/swarm_update_test.go delete mode 100644 client/task_inspect_test.go delete mode 100644 client/task_list_test.go delete mode 100644 client/testdata/ca.pem delete mode 100644 client/testdata/cert.pem delete mode 100644 client/testdata/key.pem delete mode 100644 client/volume_create_test.go delete mode 100644 client/volume_inspect_test.go delete mode 100644 client/volume_list_test.go delete mode 100644 client/volume_remove_test.go rename {client => vendor/github.com/docker/docker/client}/README.md (92%) rename {client => vendor/github.com/docker/docker/client}/checkpoint_create.go (100%) rename {client => vendor/github.com/docker/docker/client}/checkpoint_delete.go (100%) rename {client => vendor/github.com/docker/docker/client}/checkpoint_list.go (100%) rename {client => vendor/github.com/docker/docker/client}/client.go (99%) rename {client => vendor/github.com/docker/docker/client}/client_unix.go (100%) rename {client => vendor/github.com/docker/docker/client}/client_windows.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_attach.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_commit.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_copy.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_create.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_diff.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_exec.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_export.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_inspect.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_kill.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_list.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_logs.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_pause.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_prune.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_remove.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_rename.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_resize.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_restart.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_start.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_stats.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_stop.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_top.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_unpause.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_update.go (100%) rename {client => vendor/github.com/docker/docker/client}/container_wait.go (100%) rename {client => vendor/github.com/docker/docker/client}/disk_usage.go (100%) rename {client => vendor/github.com/docker/docker/client}/errors.go (100%) rename {client => vendor/github.com/docker/docker/client}/events.go (100%) rename {client => vendor/github.com/docker/docker/client}/hijack.go (100%) rename {client => vendor/github.com/docker/docker/client}/image_build.go (100%) rename {client => vendor/github.com/docker/docker/client}/image_create.go (100%) rename {client => vendor/github.com/docker/docker/client}/image_history.go (100%) rename {client => vendor/github.com/docker/docker/client}/image_import.go (100%) rename {client => vendor/github.com/docker/docker/client}/image_inspect.go (100%) rename {client => vendor/github.com/docker/docker/client}/image_list.go (100%) rename {client => vendor/github.com/docker/docker/client}/image_load.go (100%) rename {client => vendor/github.com/docker/docker/client}/image_prune.go (100%) rename {client => vendor/github.com/docker/docker/client}/image_pull.go (100%) rename {client => vendor/github.com/docker/docker/client}/image_push.go (100%) rename {client => vendor/github.com/docker/docker/client}/image_remove.go (100%) rename {client => vendor/github.com/docker/docker/client}/image_save.go (100%) rename {client => vendor/github.com/docker/docker/client}/image_search.go (100%) rename {client => vendor/github.com/docker/docker/client}/image_tag.go (100%) rename {client => vendor/github.com/docker/docker/client}/info.go (100%) rename {client => vendor/github.com/docker/docker/client}/interface.go (100%) rename {client => vendor/github.com/docker/docker/client}/interface_experimental.go (100%) rename {client => vendor/github.com/docker/docker/client}/interface_stable.go (100%) rename {client => vendor/github.com/docker/docker/client}/login.go (100%) rename {client => vendor/github.com/docker/docker/client}/network_connect.go (100%) rename {client => vendor/github.com/docker/docker/client}/network_create.go (100%) rename {client => vendor/github.com/docker/docker/client}/network_disconnect.go (100%) rename {client => vendor/github.com/docker/docker/client}/network_inspect.go (100%) rename {client => vendor/github.com/docker/docker/client}/network_list.go (100%) rename {client => vendor/github.com/docker/docker/client}/network_prune.go (100%) rename {client => vendor/github.com/docker/docker/client}/network_remove.go (100%) rename {client => vendor/github.com/docker/docker/client}/node_inspect.go (100%) rename {client => vendor/github.com/docker/docker/client}/node_list.go (100%) rename {client => vendor/github.com/docker/docker/client}/node_remove.go (100%) rename {client => vendor/github.com/docker/docker/client}/node_update.go (100%) rename {client => vendor/github.com/docker/docker/client}/ping.go (100%) rename {client => vendor/github.com/docker/docker/client}/plugin_create.go (100%) rename {client => vendor/github.com/docker/docker/client}/plugin_disable.go (100%) rename {client => vendor/github.com/docker/docker/client}/plugin_enable.go (100%) rename {client => vendor/github.com/docker/docker/client}/plugin_inspect.go (100%) rename {client => vendor/github.com/docker/docker/client}/plugin_install.go (100%) rename {client => vendor/github.com/docker/docker/client}/plugin_list.go (100%) rename {client => vendor/github.com/docker/docker/client}/plugin_push.go (100%) rename {client => vendor/github.com/docker/docker/client}/plugin_remove.go (100%) rename {client => vendor/github.com/docker/docker/client}/plugin_set.go (100%) rename {client => vendor/github.com/docker/docker/client}/plugin_upgrade.go (100%) rename {client => vendor/github.com/docker/docker/client}/request.go (99%) rename {client => vendor/github.com/docker/docker/client}/secret_create.go (100%) rename {client => vendor/github.com/docker/docker/client}/secret_inspect.go (100%) rename {client => vendor/github.com/docker/docker/client}/secret_list.go (100%) rename {client => vendor/github.com/docker/docker/client}/secret_remove.go (100%) rename {client => vendor/github.com/docker/docker/client}/secret_update.go (100%) rename {client => vendor/github.com/docker/docker/client}/service_create.go (100%) rename {client => vendor/github.com/docker/docker/client}/service_inspect.go (100%) rename {client => vendor/github.com/docker/docker/client}/service_list.go (100%) rename {client => vendor/github.com/docker/docker/client}/service_logs.go (100%) rename {client => vendor/github.com/docker/docker/client}/service_remove.go (100%) rename {client => vendor/github.com/docker/docker/client}/service_update.go (100%) rename {client => vendor/github.com/docker/docker/client}/swarm_get_unlock_key.go (100%) rename {client => vendor/github.com/docker/docker/client}/swarm_init.go (100%) rename {client => vendor/github.com/docker/docker/client}/swarm_inspect.go (100%) rename {client => vendor/github.com/docker/docker/client}/swarm_join.go (100%) rename {client => vendor/github.com/docker/docker/client}/swarm_leave.go (100%) rename {client => vendor/github.com/docker/docker/client}/swarm_unlock.go (100%) rename {client => vendor/github.com/docker/docker/client}/swarm_update.go (100%) rename {client => vendor/github.com/docker/docker/client}/task_inspect.go (100%) rename {client => vendor/github.com/docker/docker/client}/task_list.go (100%) rename {client => vendor/github.com/docker/docker/client}/task_logs.go (100%) rename {client => vendor/github.com/docker/docker/client}/transport.go (50%) rename {client => vendor/github.com/docker/docker/client}/utils.go (99%) rename {client => vendor/github.com/docker/docker/client}/version.go (100%) rename {client => vendor/github.com/docker/docker/client}/volume_create.go (100%) rename {client => vendor/github.com/docker/docker/client}/volume_inspect.go (100%) rename {client => vendor/github.com/docker/docker/client}/volume_list.go (100%) rename {client => vendor/github.com/docker/docker/client}/volume_prune.go (100%) rename {client => vendor/github.com/docker/docker/client}/volume_remove.go (100%) diff --git a/README.md b/README.md index dc41db3b40..66db952beb 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ Docker EE products. It's composed of 3 main folders * `/cli` - all the commands code. -* `/client` - the API client, used by `/cli`. * `/cmd/docker` - the entrypoint of the cli, aka the main. Development diff --git a/cli/command/cli.go b/cli/command/cli.go index 6cad5a10c7..3cb5b9a146 100644 --- a/cli/command/cli.go +++ b/cli/command/cli.go @@ -12,7 +12,7 @@ import ( "github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/cli/config/credentials" cliflags "github.com/docker/cli/cli/flags" - "github.com/docker/cli/client" + "github.com/docker/docker/client" "github.com/docker/docker/api" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/versions" diff --git a/cli/command/container/create.go b/cli/command/container/create.go index 7556ece98e..3f36bb8e57 100644 --- a/cli/command/container/create.go +++ b/cli/command/container/create.go @@ -8,7 +8,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/image" - apiclient "github.com/docker/cli/client" + apiclient "github.com/docker/docker/client" "github.com/docker/distribution/reference" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" diff --git a/cli/command/container/exec.go b/cli/command/container/exec.go index 964d5c5ba2..67bc71494d 100644 --- a/cli/command/container/exec.go +++ b/cli/command/container/exec.go @@ -7,7 +7,7 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" - apiclient "github.com/docker/cli/client" + apiclient "github.com/docker/docker/client" "github.com/docker/docker/api/types" options "github.com/docker/docker/opts" "github.com/docker/docker/pkg/promise" diff --git a/cli/command/container/stats_helpers.go b/cli/command/container/stats_helpers.go index 4df1624a73..f7808533ca 100644 --- a/cli/command/container/stats_helpers.go +++ b/cli/command/container/stats_helpers.go @@ -9,7 +9,7 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/cli/cli/command/formatter" - "github.com/docker/cli/client" + "github.com/docker/docker/client" "github.com/docker/docker/api/types" "github.com/pkg/errors" "golang.org/x/net/context" diff --git a/cli/command/container/tty.go b/cli/command/container/tty.go index dba519ef91..a1b068b26c 100644 --- a/cli/command/container/tty.go +++ b/cli/command/container/tty.go @@ -9,7 +9,7 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/cli/cli/command" - "github.com/docker/cli/client" + "github.com/docker/docker/client" "github.com/docker/docker/api/types" "github.com/docker/docker/pkg/signal" "golang.org/x/net/context" diff --git a/cli/command/container/utils.go b/cli/command/container/utils.go index e623af38c1..344ac40685 100644 --- a/cli/command/container/utils.go +++ b/cli/command/container/utils.go @@ -5,7 +5,7 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/cli/cli/command" - clientapi "github.com/docker/cli/client" + clientapi "github.com/docker/docker/client" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/events" "github.com/docker/docker/api/types/filters" diff --git a/cli/command/idresolver/client_test.go b/cli/command/idresolver/client_test.go index 7a13609421..8568f0e770 100644 --- a/cli/command/idresolver/client_test.go +++ b/cli/command/idresolver/client_test.go @@ -1,7 +1,7 @@ package idresolver import ( - "github.com/docker/cli/client" + "github.com/docker/docker/client" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "golang.org/x/net/context" diff --git a/cli/command/idresolver/idresolver.go b/cli/command/idresolver/idresolver.go index f79d8a11fc..746eb866de 100644 --- a/cli/command/idresolver/idresolver.go +++ b/cli/command/idresolver/idresolver.go @@ -3,7 +3,7 @@ package idresolver import ( "golang.org/x/net/context" - "github.com/docker/cli/client" + "github.com/docker/docker/client" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" diff --git a/cli/command/image/client_test.go b/cli/command/image/client_test.go index 949b09388b..10ceefd281 100644 --- a/cli/command/image/client_test.go +++ b/cli/command/image/client_test.go @@ -6,7 +6,7 @@ import ( "strings" "time" - "github.com/docker/cli/client" + "github.com/docker/docker/client" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/image" diff --git a/cli/command/node/client_test.go b/cli/command/node/client_test.go index a0c8e53743..df3a450da6 100644 --- a/cli/command/node/client_test.go +++ b/cli/command/node/client_test.go @@ -1,7 +1,7 @@ package node import ( - "github.com/docker/cli/client" + "github.com/docker/docker/client" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "golang.org/x/net/context" diff --git a/cli/command/node/cmd.go b/cli/command/node/cmd.go index 0462274a89..1ecfcc048f 100644 --- a/cli/command/node/cmd.go +++ b/cli/command/node/cmd.go @@ -5,7 +5,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" - apiclient "github.com/docker/cli/client" + apiclient "github.com/docker/docker/client" "github.com/docker/docker/api/types" "github.com/spf13/cobra" "golang.org/x/net/context" diff --git a/cli/command/secret/client_test.go b/cli/command/secret/client_test.go index 1620fada16..f498abe390 100644 --- a/cli/command/secret/client_test.go +++ b/cli/command/secret/client_test.go @@ -1,7 +1,7 @@ package secret import ( - "github.com/docker/cli/client" + "github.com/docker/docker/client" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "golang.org/x/net/context" diff --git a/cli/command/service/inspect.go b/cli/command/service/inspect.go index 34c623789c..1a1f6c3d2c 100644 --- a/cli/command/service/inspect.go +++ b/cli/command/service/inspect.go @@ -8,7 +8,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/formatter" - apiclient "github.com/docker/cli/client" + apiclient "github.com/docker/docker/client" "github.com/docker/docker/api/types" "github.com/pkg/errors" "github.com/spf13/cobra" diff --git a/cli/command/service/logs.go b/cli/command/service/logs.go index 5db7c42bc3..07758e645f 100644 --- a/cli/command/service/logs.go +++ b/cli/command/service/logs.go @@ -12,7 +12,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/idresolver" - "github.com/docker/cli/client" + "github.com/docker/docker/client" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/pkg/stdcopy" diff --git a/cli/command/service/opts.go b/cli/command/service/opts.go index d043b78cf8..747df23bff 100644 --- a/cli/command/service/opts.go +++ b/cli/command/service/opts.go @@ -7,7 +7,7 @@ import ( "strings" "time" - "github.com/docker/cli/client" + "github.com/docker/docker/client" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/opts" diff --git a/cli/command/service/parse.go b/cli/command/service/parse.go index d6f93b044e..b125f8ce78 100644 --- a/cli/command/service/parse.go +++ b/cli/command/service/parse.go @@ -1,7 +1,7 @@ package service import ( - "github.com/docker/cli/client" + "github.com/docker/docker/client" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" swarmtypes "github.com/docker/docker/api/types/swarm" diff --git a/cli/command/service/progress/progress.go b/cli/command/service/progress/progress.go index 266a949814..9a81aabfc3 100644 --- a/cli/command/service/progress/progress.go +++ b/cli/command/service/progress/progress.go @@ -8,7 +8,7 @@ import ( "os/signal" "time" - "github.com/docker/cli/client" + "github.com/docker/docker/client" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/swarm" diff --git a/cli/command/service/update.go b/cli/command/service/update.go index d960fab5ea..9185503d35 100644 --- a/cli/command/service/update.go +++ b/cli/command/service/update.go @@ -8,7 +8,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" - "github.com/docker/cli/client" + "github.com/docker/docker/client" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" mounttypes "github.com/docker/docker/api/types/mount" diff --git a/cli/command/stack/client_test.go b/cli/command/stack/client_test.go index 312e796b22..2a283dfe2f 100644 --- a/cli/command/stack/client_test.go +++ b/cli/command/stack/client_test.go @@ -4,7 +4,7 @@ import ( "strings" "github.com/docker/cli/cli/compose/convert" - "github.com/docker/cli/client" + "github.com/docker/docker/client" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/swarm" diff --git a/cli/command/stack/common.go b/cli/command/stack/common.go index 3e6b57bd8b..0c7f621d0a 100644 --- a/cli/command/stack/common.go +++ b/cli/command/stack/common.go @@ -4,7 +4,7 @@ import ( "golang.org/x/net/context" "github.com/docker/cli/cli/compose/convert" - "github.com/docker/cli/client" + "github.com/docker/docker/client" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/swarm" diff --git a/cli/command/stack/deploy_composefile.go b/cli/command/stack/deploy_composefile.go index e3f59de14c..56bb34872f 100644 --- a/cli/command/stack/deploy_composefile.go +++ b/cli/command/stack/deploy_composefile.go @@ -12,8 +12,8 @@ import ( "github.com/docker/cli/cli/compose/convert" "github.com/docker/cli/cli/compose/loader" composetypes "github.com/docker/cli/cli/compose/types" - apiclient "github.com/docker/cli/client" - dockerclient "github.com/docker/cli/client" + apiclient "github.com/docker/docker/client" + dockerclient "github.com/docker/docker/client" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" diff --git a/cli/command/stack/list.go b/cli/command/stack/list.go index c1402b3005..443fd13331 100644 --- a/cli/command/stack/list.go +++ b/cli/command/stack/list.go @@ -7,7 +7,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/cli/compose/convert" - "github.com/docker/cli/client" + "github.com/docker/docker/client" "github.com/docker/docker/api/types" "github.com/pkg/errors" "github.com/spf13/cobra" diff --git a/cli/command/swarm/client_test.go b/cli/command/swarm/client_test.go index c6552c8081..afb773444a 100644 --- a/cli/command/swarm/client_test.go +++ b/cli/command/swarm/client_test.go @@ -1,7 +1,7 @@ package swarm import ( - "github.com/docker/cli/client" + "github.com/docker/docker/client" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "golang.org/x/net/context" diff --git a/cli/command/system/inspect.go b/cli/command/system/inspect.go index ef5f7a8b05..9f9f69420e 100644 --- a/cli/command/system/inspect.go +++ b/cli/command/system/inspect.go @@ -7,7 +7,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/inspect" - apiclient "github.com/docker/cli/client" + apiclient "github.com/docker/docker/client" "github.com/docker/docker/api/types" "github.com/pkg/errors" "github.com/spf13/cobra" diff --git a/cli/command/volume/client_test.go b/cli/command/volume/client_test.go index 71500d1f03..52e82e598f 100644 --- a/cli/command/volume/client_test.go +++ b/cli/command/volume/client_test.go @@ -1,7 +1,7 @@ package volume import ( - "github.com/docker/cli/client" + "github.com/docker/docker/client" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" volumetypes "github.com/docker/docker/api/types/volume" diff --git a/cli/compose/convert/service.go b/cli/compose/convert/service.go index 932e7543a1..aff3fc21e7 100644 --- a/cli/compose/convert/service.go +++ b/cli/compose/convert/service.go @@ -9,7 +9,7 @@ import ( servicecli "github.com/docker/cli/cli/command/service" composetypes "github.com/docker/cli/cli/compose/types" - "github.com/docker/cli/client" + "github.com/docker/docker/client" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/versions" diff --git a/cli/internal/test/cli.go b/cli/internal/test/cli.go index 0a0eae3841..f0f75f7bd5 100644 --- a/cli/internal/test/cli.go +++ b/cli/internal/test/cli.go @@ -8,7 +8,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/cli/config/credentials" - "github.com/docker/cli/client" + "github.com/docker/docker/client" ) // FakeCli emulates the default DockerCli diff --git a/client/checkpoint_create_test.go b/client/checkpoint_create_test.go deleted file mode 100644 index 96e5187618..0000000000 --- a/client/checkpoint_create_test.go +++ /dev/null @@ -1,73 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestCheckpointCreateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - err := client.CheckpointCreate(context.Background(), "nothing", types.CheckpointCreateOptions{ - CheckpointID: "noting", - Exit: true, - }) - - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestCheckpointCreate(t *testing.T) { - expectedContainerID := "container_id" - expectedCheckpointID := "checkpoint_id" - expectedURL := "/containers/container_id/checkpoints" - - client := &Client{ - client: newMockClient(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) - } - - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - - createOptions := &types.CheckpointCreateOptions{} - if err := json.NewDecoder(req.Body).Decode(createOptions); err != nil { - return nil, err - } - - if createOptions.CheckpointID != expectedCheckpointID { - return nil, fmt.Errorf("expected CheckpointID to be 'checkpoint_id', got %v", createOptions.CheckpointID) - } - - if !createOptions.Exit { - return nil, fmt.Errorf("expected Exit to be true") - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.CheckpointCreate(context.Background(), expectedContainerID, types.CheckpointCreateOptions{ - CheckpointID: expectedCheckpointID, - Exit: true, - }) - - if err != nil { - t.Fatal(err) - } -} diff --git a/client/checkpoint_delete_test.go b/client/checkpoint_delete_test.go deleted file mode 100644 index a78b050487..0000000000 --- a/client/checkpoint_delete_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestCheckpointDeleteError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.CheckpointDelete(context.Background(), "container_id", types.CheckpointDeleteOptions{ - CheckpointID: "checkpoint_id", - }) - - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestCheckpointDelete(t *testing.T) { - expectedURL := "/containers/container_id/checkpoints/checkpoint_id" - - client := &Client{ - client: newMockClient(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) - } - if req.Method != "DELETE" { - return nil, fmt.Errorf("expected DELETE method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.CheckpointDelete(context.Background(), "container_id", types.CheckpointDeleteOptions{ - CheckpointID: "checkpoint_id", - }) - - if err != nil { - t.Fatal(err) - } -} diff --git a/client/checkpoint_list_test.go b/client/checkpoint_list_test.go deleted file mode 100644 index 388465715b..0000000000 --- a/client/checkpoint_list_test.go +++ /dev/null @@ -1,68 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestCheckpointListError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.CheckpointList(context.Background(), "container_id", types.CheckpointListOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestCheckpointList(t *testing.T) { - expectedURL := "/containers/container_id/checkpoints" - - client := &Client{ - client: newMockClient(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([]types.Checkpoint{ - { - Name: "checkpoint", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - checkpoints, err := client.CheckpointList(context.Background(), "container_id", types.CheckpointListOptions{}) - if err != nil { - t.Fatal(err) - } - if len(checkpoints) != 1 { - t.Fatalf("expected 1 checkpoint, got %v", checkpoints) - } -} - -func TestCheckpointListContainerNotFound(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusNotFound, "Server error")), - } - - _, err := client.CheckpointList(context.Background(), "unknown", types.CheckpointListOptions{}) - if err == nil || !IsErrContainerNotFound(err) { - t.Fatalf("expected a containerNotFound error, got %v", err) - } -} diff --git a/client/client_mock_test.go b/client/client_mock_test.go deleted file mode 100644 index e75c3ecbfc..0000000000 --- a/client/client_mock_test.go +++ /dev/null @@ -1,53 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "io/ioutil" - "net/http" - - "github.com/docker/docker/api/types" -) - -// transportFunc allows us to inject a mock transport for testing. We define it -// here so we can detect the tlsconfig and return nil for only this type. -type transportFunc func(*http.Request) (*http.Response, error) - -func (tf transportFunc) RoundTrip(req *http.Request) (*http.Response, error) { - return tf(req) -} - -func newMockClient(doer func(*http.Request) (*http.Response, error)) *http.Client { - return &http.Client{ - Transport: transportFunc(doer), - } -} - -func errorMock(statusCode int, message string) func(req *http.Request) (*http.Response, error) { - return func(req *http.Request) (*http.Response, error) { - header := http.Header{} - header.Set("Content-Type", "application/json") - - body, err := json.Marshal(&types.ErrorResponse{ - Message: message, - }) - if err != nil { - return nil, err - } - - return &http.Response{ - StatusCode: statusCode, - Body: ioutil.NopCloser(bytes.NewReader(body)), - Header: header, - }, nil - } -} - -func plainTextErrorMock(statusCode int, message string) func(req *http.Request) (*http.Response, error) { - return func(req *http.Request) (*http.Response, error) { - return &http.Response{ - StatusCode: statusCode, - Body: ioutil.NopCloser(bytes.NewReader([]byte(message))), - }, nil - } -} diff --git a/client/client_test.go b/client/client_test.go deleted file mode 100644 index 0816d8a9bf..0000000000 --- a/client/client_test.go +++ /dev/null @@ -1,284 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "io/ioutil" - "net/http" - "net/url" - "os" - "runtime" - "strings" - "testing" - - "github.com/docker/docker/api" - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestNewEnvClient(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("skipping unix only test for windows") - } - cases := []struct { - envs map[string]string - expectedError string - expectedVersion string - }{ - { - envs: map[string]string{}, - expectedVersion: api.DefaultVersion, - }, - { - envs: map[string]string{ - "DOCKER_CERT_PATH": "invalid/path", - }, - expectedError: "Could not load X509 key pair: open invalid/path/cert.pem: no such file or directory", - }, - { - envs: map[string]string{ - "DOCKER_CERT_PATH": "testdata/", - }, - expectedVersion: api.DefaultVersion, - }, - { - envs: map[string]string{ - "DOCKER_CERT_PATH": "testdata/", - "DOCKER_TLS_VERIFY": "1", - }, - expectedVersion: api.DefaultVersion, - }, - { - envs: map[string]string{ - "DOCKER_CERT_PATH": "testdata/", - "DOCKER_HOST": "https://notaunixsocket", - }, - expectedVersion: api.DefaultVersion, - }, - { - envs: map[string]string{ - "DOCKER_HOST": "host", - }, - expectedError: "unable to parse docker host `host`", - }, - { - envs: map[string]string{ - "DOCKER_HOST": "invalid://url", - }, - expectedVersion: api.DefaultVersion, - }, - { - envs: map[string]string{ - "DOCKER_API_VERSION": "anything", - }, - expectedVersion: "anything", - }, - { - envs: map[string]string{ - "DOCKER_API_VERSION": "1.22", - }, - expectedVersion: "1.22", - }, - } - for _, c := range cases { - recoverEnvs := setupEnvs(t, c.envs) - apiclient, err := NewEnvClient() - if c.expectedError != "" { - if err == nil { - t.Errorf("expected an error for %v", c) - } else if err.Error() != c.expectedError { - t.Errorf("expected an error %s, got %s, for %v", c.expectedError, err.Error(), c) - } - } else { - if err != nil { - t.Error(err) - } - version := apiclient.ClientVersion() - if version != c.expectedVersion { - t.Errorf("expected %s, got %s, for %v", c.expectedVersion, version, c) - } - } - - if c.envs["DOCKER_TLS_VERIFY"] != "" { - // pedantic checking that this is handled correctly - tr := apiclient.client.Transport.(*http.Transport) - if tr.TLSClientConfig == nil { - t.Error("no TLS config found when DOCKER_TLS_VERIFY enabled") - } - - if tr.TLSClientConfig.InsecureSkipVerify { - t.Error("TLS verification should be enabled") - } - } - - recoverEnvs(t) - } -} - -func setupEnvs(t *testing.T, envs map[string]string) func(*testing.T) { - oldEnvs := map[string]string{} - for key, value := range envs { - oldEnv := os.Getenv(key) - oldEnvs[key] = oldEnv - err := os.Setenv(key, value) - if err != nil { - t.Error(err) - } - } - return func(t *testing.T) { - for key, value := range oldEnvs { - err := os.Setenv(key, value) - if err != nil { - t.Error(err) - } - } - } -} - -func TestGetAPIPath(t *testing.T) { - cases := []struct { - v string - p string - q url.Values - e string - }{ - {"", "/containers/json", nil, "/containers/json"}, - {"", "/containers/json", url.Values{}, "/containers/json"}, - {"", "/containers/json", url.Values{"s": []string{"c"}}, "/containers/json?s=c"}, - {"1.22", "/containers/json", nil, "/v1.22/containers/json"}, - {"1.22", "/containers/json", url.Values{}, "/v1.22/containers/json"}, - {"1.22", "/containers/json", url.Values{"s": []string{"c"}}, "/v1.22/containers/json?s=c"}, - {"v1.22", "/containers/json", nil, "/v1.22/containers/json"}, - {"v1.22", "/containers/json", url.Values{}, "/v1.22/containers/json"}, - {"v1.22", "/containers/json", url.Values{"s": []string{"c"}}, "/v1.22/containers/json?s=c"}, - {"v1.22", "/networks/kiwl$%^", nil, "/v1.22/networks/kiwl$%25%5E"}, - } - - for _, cs := range cases { - c, err := NewClient("unix:///var/run/docker.sock", cs.v, nil, nil) - if err != nil { - t.Fatal(err) - } - g := c.getAPIPath(cs.p, cs.q) - if g != cs.e { - t.Fatalf("Expected %s, got %s", cs.e, g) - } - - err = c.Close() - if nil != err { - t.Fatalf("close client failed, error message: %s", err) - } - } -} - -func TestParseHost(t *testing.T) { - cases := []struct { - host string - proto string - addr string - base string - err bool - }{ - {"", "", "", "", true}, - {"foobar", "", "", "", true}, - {"foo://bar", "foo", "bar", "", false}, - {"tcp://localhost:2476", "tcp", "localhost:2476", "", false}, - {"tcp://localhost:2476/path", "tcp", "localhost:2476", "/path", false}, - } - - for _, cs := range cases { - p, a, b, e := ParseHost(cs.host) - if cs.err && e == nil { - t.Fatalf("expected error, got nil") - } - if !cs.err && e != nil { - t.Fatal(e) - } - if cs.proto != p { - t.Fatalf("expected proto %s, got %s", cs.proto, p) - } - if cs.addr != a { - t.Fatalf("expected addr %s, got %s", cs.addr, a) - } - if cs.base != b { - t.Fatalf("expected base %s, got %s", cs.base, b) - } - } -} - -func TestUpdateClientVersion(t *testing.T) { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - splitQuery := strings.Split(req.URL.Path, "/") - queryVersion := splitQuery[1] - b, err := json.Marshal(types.Version{ - APIVersion: queryVersion, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - cases := []struct { - v string - }{ - {"1.20"}, - {"v1.21"}, - {"1.22"}, - {"v1.22"}, - } - - for _, cs := range cases { - client.UpdateClientVersion(cs.v) - r, err := client.ServerVersion(context.Background()) - if err != nil { - t.Fatal(err) - } - if strings.TrimPrefix(r.APIVersion, "v") != strings.TrimPrefix(cs.v, "v") { - t.Fatalf("Expected %s, got %s", cs.v, r.APIVersion) - } - } -} - -func TestNewEnvClientSetsDefaultVersion(t *testing.T) { - // Unset environment variables - envVarKeys := []string{ - "DOCKER_HOST", - "DOCKER_API_VERSION", - "DOCKER_TLS_VERIFY", - "DOCKER_CERT_PATH", - } - envVarValues := make(map[string]string) - for _, key := range envVarKeys { - envVarValues[key] = os.Getenv(key) - os.Setenv(key, "") - } - - client, err := NewEnvClient() - if err != nil { - t.Fatal(err) - } - if client.version != api.DefaultVersion { - t.Fatalf("Expected %s, got %s", api.DefaultVersion, client.version) - } - - expected := "1.22" - os.Setenv("DOCKER_API_VERSION", expected) - client, err = NewEnvClient() - if err != nil { - t.Fatal(err) - } - if client.version != expected { - t.Fatalf("Expected %s, got %s", expected, client.version) - } - - // Restore environment variables - for _, key := range envVarKeys { - os.Setenv(key, envVarValues[key]) - } -} diff --git a/client/container_commit_test.go b/client/container_commit_test.go deleted file mode 100644 index 6947ed3861..0000000000 --- a/client/container_commit_test.go +++ /dev/null @@ -1,96 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestContainerCommitError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerCommit(context.Background(), "nothing", types.ContainerCommitOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerCommit(t *testing.T) { - expectedURL := "/commit" - expectedContainerID := "container_id" - specifiedReference := "repository_name:tag" - expectedRepositoryName := "repository_name" - expectedTag := "tag" - expectedComment := "comment" - expectedAuthor := "author" - expectedChanges := []string{"change1", "change2"} - - client := &Client{ - client: newMockClient(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) - } - query := req.URL.Query() - containerID := query.Get("container") - if containerID != expectedContainerID { - return nil, fmt.Errorf("container id not set in URL query properly. Expected '%s', got %s", expectedContainerID, containerID) - } - repo := query.Get("repo") - if repo != expectedRepositoryName { - return nil, fmt.Errorf("container repo not set in URL query properly. Expected '%s', got %s", expectedRepositoryName, repo) - } - tag := query.Get("tag") - if tag != expectedTag { - return nil, fmt.Errorf("container tag not set in URL query properly. Expected '%s', got %s'", expectedTag, tag) - } - comment := query.Get("comment") - if comment != expectedComment { - return nil, fmt.Errorf("container comment not set in URL query properly. Expected '%s', got %s'", expectedComment, comment) - } - author := query.Get("author") - if author != expectedAuthor { - return nil, fmt.Errorf("container author not set in URL query properly. Expected '%s', got %s'", expectedAuthor, author) - } - pause := query.Get("pause") - if pause != "0" { - return nil, fmt.Errorf("container pause not set in URL query properly. Expected 'true', got %v'", pause) - } - changes := query["changes"] - if len(changes) != len(expectedChanges) { - return nil, fmt.Errorf("expected container changes size to be '%d', got %d", len(expectedChanges), len(changes)) - } - b, err := json.Marshal(types.IDResponse{ - ID: "new_container_id", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - r, err := client.ContainerCommit(context.Background(), expectedContainerID, types.ContainerCommitOptions{ - Reference: specifiedReference, - Comment: expectedComment, - Author: expectedAuthor, - Changes: expectedChanges, - Pause: false, - }) - if err != nil { - t.Fatal(err) - } - if r.ID != "new_container_id" { - t.Fatalf("expected `new_container_id`, got %s", r.ID) - } -} diff --git a/client/container_copy_test.go b/client/container_copy_test.go deleted file mode 100644 index c84f82e9fb..0000000000 --- a/client/container_copy_test.go +++ /dev/null @@ -1,244 +0,0 @@ -package client - -import ( - "bytes" - "encoding/base64" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" -) - -func TestContainerStatPathError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerStatPath(context.Background(), "container_id", "path") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server error, got %v", err) - } -} - -func TestContainerStatPathNoHeaderError(t *testing.T) { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - _, err := client.ContainerStatPath(context.Background(), "container_id", "path/to/file") - if err == nil { - t.Fatalf("expected an error, got nothing") - } -} - -func TestContainerStatPath(t *testing.T) { - expectedURL := "/containers/container_id/archive" - expectedPath := "path/to/file" - client := &Client{ - client: newMockClient(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) - } - if req.Method != "HEAD" { - return nil, fmt.Errorf("expected HEAD method, got %s", req.Method) - } - query := req.URL.Query() - path := query.Get("path") - if path != expectedPath { - return nil, fmt.Errorf("path not set in URL query properly") - } - content, err := json.Marshal(types.ContainerPathStat{ - Name: "name", - Mode: 0700, - }) - if err != nil { - return nil, err - } - base64PathStat := base64.StdEncoding.EncodeToString(content) - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - Header: http.Header{ - "X-Docker-Container-Path-Stat": []string{base64PathStat}, - }, - }, nil - }), - } - stat, err := client.ContainerStatPath(context.Background(), "container_id", expectedPath) - if err != nil { - t.Fatal(err) - } - if stat.Name != "name" { - t.Fatalf("expected container path stat name to be 'name', got '%s'", stat.Name) - } - if stat.Mode != 0700 { - t.Fatalf("expected container path stat mode to be 0700, got '%v'", stat.Mode) - } -} - -func TestCopyToContainerError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - err := client.CopyToContainer(context.Background(), "container_id", "path/to/file", bytes.NewReader([]byte("")), types.CopyToContainerOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server error, got %v", err) - } -} - -func TestCopyToContainerNotStatusOKError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusNoContent, "No content")), - } - err := client.CopyToContainer(context.Background(), "container_id", "path/to/file", bytes.NewReader([]byte("")), types.CopyToContainerOptions{}) - if err == nil || err.Error() != "unexpected status code from daemon: 204" { - t.Fatalf("expected an unexpected status code error, got %v", err) - } -} - -func TestCopyToContainer(t *testing.T) { - expectedURL := "/containers/container_id/archive" - expectedPath := "path/to/file" - client := &Client{ - client: newMockClient(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) - } - if req.Method != "PUT" { - return nil, fmt.Errorf("expected PUT method, got %s", req.Method) - } - query := req.URL.Query() - path := query.Get("path") - if path != expectedPath { - return nil, fmt.Errorf("path not set in URL query properly, expected '%s', got %s", expectedPath, path) - } - noOverwriteDirNonDir := query.Get("noOverwriteDirNonDir") - if noOverwriteDirNonDir != "true" { - return nil, fmt.Errorf("noOverwriteDirNonDir not set in URL query properly, expected true, got %s", noOverwriteDirNonDir) - } - - content, err := ioutil.ReadAll(req.Body) - if err != nil { - return nil, err - } - if err := req.Body.Close(); err != nil { - return nil, err - } - if string(content) != "content" { - return nil, fmt.Errorf("expected content to be 'content', got %s", string(content)) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - err := client.CopyToContainer(context.Background(), "container_id", expectedPath, bytes.NewReader([]byte("content")), types.CopyToContainerOptions{ - AllowOverwriteDirWithFile: false, - }) - if err != nil { - t.Fatal(err) - } -} - -func TestCopyFromContainerError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, _, err := client.CopyFromContainer(context.Background(), "container_id", "path/to/file") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server error, got %v", err) - } -} - -func TestCopyFromContainerNotStatusOKError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusNoContent, "No content")), - } - _, _, err := client.CopyFromContainer(context.Background(), "container_id", "path/to/file") - if err == nil || err.Error() != "unexpected status code from daemon: 204" { - t.Fatalf("expected an unexpected status code error, got %v", err) - } -} - -func TestCopyFromContainerNoHeaderError(t *testing.T) { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - _, _, err := client.CopyFromContainer(context.Background(), "container_id", "path/to/file") - if err == nil { - t.Fatalf("expected an error, got nothing") - } -} - -func TestCopyFromContainer(t *testing.T) { - expectedURL := "/containers/container_id/archive" - expectedPath := "path/to/file" - client := &Client{ - client: newMockClient(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) - } - if req.Method != "GET" { - return nil, fmt.Errorf("expected GET method, got %s", req.Method) - } - query := req.URL.Query() - path := query.Get("path") - if path != expectedPath { - return nil, fmt.Errorf("path not set in URL query properly, expected '%s', got %s", expectedPath, path) - } - - headercontent, err := json.Marshal(types.ContainerPathStat{ - Name: "name", - Mode: 0700, - }) - if err != nil { - return nil, err - } - base64PathStat := base64.StdEncoding.EncodeToString(headercontent) - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("content"))), - Header: http.Header{ - "X-Docker-Container-Path-Stat": []string{base64PathStat}, - }, - }, nil - }), - } - r, stat, err := client.CopyFromContainer(context.Background(), "container_id", expectedPath) - if err != nil { - t.Fatal(err) - } - if stat.Name != "name" { - t.Fatalf("expected container path stat name to be 'name', got '%s'", stat.Name) - } - if stat.Mode != 0700 { - t.Fatalf("expected container path stat mode to be 0700, got '%v'", stat.Mode) - } - content, err := ioutil.ReadAll(r) - if err != nil { - t.Fatal(err) - } - if err := r.Close(); err != nil { - t.Fatal(err) - } - if string(content) != "content" { - t.Fatalf("expected content to be 'content', got %s", string(content)) - } -} diff --git a/client/container_create_test.go b/client/container_create_test.go deleted file mode 100644 index 3ab608c21e..0000000000 --- a/client/container_create_test.go +++ /dev/null @@ -1,118 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types/container" - "golang.org/x/net/context" -) - -func TestContainerCreateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerCreate(context.Background(), nil, nil, nil, "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error while testing StatusInternalServerError, got %v", err) - } - - // 404 doesn't automatically means an unknown image - client = &Client{ - client: newMockClient(errorMock(http.StatusNotFound, "Server error")), - } - _, err = client.ContainerCreate(context.Background(), nil, nil, nil, "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error while testing StatusNotFound, got %v", err) - } -} - -func TestContainerCreateImageNotFound(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusNotFound, "No such image")), - } - _, err := client.ContainerCreate(context.Background(), &container.Config{Image: "unknown_image"}, nil, nil, "unknown") - if err == nil || !IsErrImageNotFound(err) { - t.Fatalf("expected an imageNotFound error, got %v", err) - } -} - -func TestContainerCreateWithName(t *testing.T) { - expectedURL := "/containers/create" - client := &Client{ - client: newMockClient(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) - } - name := req.URL.Query().Get("name") - if name != "container_name" { - return nil, fmt.Errorf("container name not set in URL query properly. Expected `container_name`, got %s", name) - } - b, err := json.Marshal(container.ContainerCreateCreatedBody{ - ID: "container_id", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - r, err := client.ContainerCreate(context.Background(), nil, nil, nil, "container_name") - if err != nil { - t.Fatal(err) - } - if r.ID != "container_id" { - t.Fatalf("expected `container_id`, got %s", r.ID) - } -} - -// TestContainerCreateAutoRemove validates that a client using API 1.24 always disables AutoRemove. When using API 1.25 -// or up, AutoRemove should not be disabled. -func TestContainerCreateAutoRemove(t *testing.T) { - autoRemoveValidator := func(expectedValue bool) func(req *http.Request) (*http.Response, error) { - return func(req *http.Request) (*http.Response, error) { - var config configWrapper - - if err := json.NewDecoder(req.Body).Decode(&config); err != nil { - return nil, err - } - if config.HostConfig.AutoRemove != expectedValue { - return nil, fmt.Errorf("expected AutoRemove to be %v, got %v", expectedValue, config.HostConfig.AutoRemove) - } - b, err := json.Marshal(container.ContainerCreateCreatedBody{ - ID: "container_id", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - } - } - - client := &Client{ - client: newMockClient(autoRemoveValidator(false)), - version: "1.24", - } - if _, err := client.ContainerCreate(context.Background(), nil, &container.HostConfig{AutoRemove: true}, nil, ""); err != nil { - t.Fatal(err) - } - client = &Client{ - client: newMockClient(autoRemoveValidator(true)), - version: "1.25", - } - if _, err := client.ContainerCreate(context.Background(), nil, &container.HostConfig{AutoRemove: true}, nil, ""); err != nil { - t.Fatal(err) - } -} diff --git a/client/container_diff_test.go b/client/container_diff_test.go deleted file mode 100644 index 57dd73e66d..0000000000 --- a/client/container_diff_test.go +++ /dev/null @@ -1,61 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types/container" - "golang.org/x/net/context" -) - -func TestContainerDiffError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerDiff(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } - -} - -func TestContainerDiff(t *testing.T) { - expectedURL := "/containers/container_id/changes" - client := &Client{ - client: newMockClient(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) - } - b, err := json.Marshal([]container.ContainerChangeResponseItem{ - { - Kind: 0, - Path: "/path/1", - }, - { - Kind: 1, - Path: "/path/2", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - changes, err := client.ContainerDiff(context.Background(), "container_id") - if err != nil { - t.Fatal(err) - } - if len(changes) != 2 { - t.Fatalf("expected an array of 2 changes, got %v", changes) - } -} diff --git a/client/container_exec_test.go b/client/container_exec_test.go deleted file mode 100644 index 0e296a50ad..0000000000 --- a/client/container_exec_test.go +++ /dev/null @@ -1,157 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" -) - -func TestContainerExecCreateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerExecCreate(context.Background(), "container_id", types.ExecConfig{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerExecCreate(t *testing.T) { - expectedURL := "/containers/container_id/exec" - client := &Client{ - client: newMockClient(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) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - // FIXME validate the content is the given ExecConfig ? - if err := req.ParseForm(); err != nil { - return nil, err - } - execConfig := &types.ExecConfig{} - if err := json.NewDecoder(req.Body).Decode(execConfig); err != nil { - return nil, err - } - if execConfig.User != "user" { - return nil, fmt.Errorf("expected an execConfig with User == 'user', got %v", execConfig) - } - b, err := json.Marshal(types.IDResponse{ - ID: "exec_id", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - r, err := client.ContainerExecCreate(context.Background(), "container_id", types.ExecConfig{ - User: "user", - }) - if err != nil { - t.Fatal(err) - } - if r.ID != "exec_id" { - t.Fatalf("expected `exec_id`, got %s", r.ID) - } -} - -func TestContainerExecStartError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - err := client.ContainerExecStart(context.Background(), "nothing", types.ExecStartCheck{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerExecStart(t *testing.T) { - expectedURL := "/exec/exec_id/start" - client := &Client{ - client: newMockClient(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) - } - if err := req.ParseForm(); err != nil { - return nil, err - } - execStartCheck := &types.ExecStartCheck{} - if err := json.NewDecoder(req.Body).Decode(execStartCheck); err != nil { - return nil, err - } - if execStartCheck.Tty || !execStartCheck.Detach { - return nil, fmt.Errorf("expected execStartCheck{Detach:true,Tty:false}, got %v", execStartCheck) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.ContainerExecStart(context.Background(), "exec_id", types.ExecStartCheck{ - Detach: true, - Tty: false, - }) - if err != nil { - t.Fatal(err) - } -} - -func TestContainerExecInspectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerExecInspect(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerExecInspect(t *testing.T) { - expectedURL := "/exec/exec_id/json" - client := &Client{ - client: newMockClient(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) - } - b, err := json.Marshal(types.ContainerExecInspect{ - ExecID: "exec_id", - ContainerID: "container_id", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - inspect, err := client.ContainerExecInspect(context.Background(), "exec_id") - if err != nil { - t.Fatal(err) - } - if inspect.ExecID != "exec_id" { - t.Fatalf("expected ExecID to be `exec_id`, got %s", inspect.ExecID) - } - if inspect.ContainerID != "container_id" { - t.Fatalf("expected ContainerID `container_id`, got %s", inspect.ContainerID) - } -} diff --git a/client/container_export_test.go b/client/container_export_test.go deleted file mode 100644 index 5849fe9252..0000000000 --- a/client/container_export_test.go +++ /dev/null @@ -1,50 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestContainerExportError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerExport(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerExport(t *testing.T) { - expectedURL := "/containers/container_id/export" - client := &Client{ - client: newMockClient(func(r *http.Request) (*http.Response, error) { - if !strings.HasPrefix(r.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("response"))), - }, nil - }), - } - body, err := client.ContainerExport(context.Background(), "container_id") - if err != nil { - t.Fatal(err) - } - defer body.Close() - content, err := ioutil.ReadAll(body) - if err != nil { - t.Fatal(err) - } - if string(content) != "response" { - t.Fatalf("expected response to contain 'response', got %s", string(content)) - } -} diff --git a/client/container_inspect_test.go b/client/container_inspect_test.go deleted file mode 100644 index 98f83bd8db..0000000000 --- a/client/container_inspect_test.go +++ /dev/null @@ -1,125 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestContainerInspectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.ContainerInspect(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerInspectContainerNotFound(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusNotFound, "Server error")), - } - - _, err := client.ContainerInspect(context.Background(), "unknown") - if err == nil || !IsErrContainerNotFound(err) { - t.Fatalf("expected a containerNotFound error, got %v", err) - } -} - -func TestContainerInspect(t *testing.T) { - expectedURL := "/containers/container_id/json" - client := &Client{ - client: newMockClient(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(types.ContainerJSON{ - ContainerJSONBase: &types.ContainerJSONBase{ - ID: "container_id", - Image: "image", - Name: "name", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - r, err := client.ContainerInspect(context.Background(), "container_id") - if err != nil { - t.Fatal(err) - } - if r.ID != "container_id" { - t.Fatalf("expected `container_id`, got %s", r.ID) - } - if r.Image != "image" { - t.Fatalf("expected `image`, got %s", r.Image) - } - if r.Name != "name" { - t.Fatalf("expected `name`, got %s", r.Name) - } -} - -func TestContainerInspectNode(t *testing.T) { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - content, err := json.Marshal(types.ContainerJSON{ - ContainerJSONBase: &types.ContainerJSONBase{ - ID: "container_id", - Image: "image", - Name: "name", - Node: &types.ContainerNode{ - ID: "container_node_id", - Addr: "container_node", - Labels: map[string]string{"foo": "bar"}, - }, - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - r, err := client.ContainerInspect(context.Background(), "container_id") - if err != nil { - t.Fatal(err) - } - if r.ID != "container_id" { - t.Fatalf("expected `container_id`, got %s", r.ID) - } - if r.Image != "image" { - t.Fatalf("expected `image`, got %s", r.Image) - } - if r.Name != "name" { - t.Fatalf("expected `name`, got %s", r.Name) - } - if r.Node.ID != "container_node_id" { - t.Fatalf("expected `container_node_id`, got %s", r.Node.ID) - } - if r.Node.Addr != "container_node" { - t.Fatalf("expected `container_node`, got %s", r.Node.Addr) - } - foo, ok := r.Node.Labels["foo"] - if foo != "bar" || !ok { - t.Fatalf("expected `bar` for label `foo`") - } -} diff --git a/client/container_kill_test.go b/client/container_kill_test.go deleted file mode 100644 index 9477b0abd2..0000000000 --- a/client/container_kill_test.go +++ /dev/null @@ -1,46 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestContainerKillError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - err := client.ContainerKill(context.Background(), "nothing", "SIGKILL") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerKill(t *testing.T) { - expectedURL := "/containers/container_id/kill" - client := &Client{ - client: newMockClient(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) - } - signal := req.URL.Query().Get("signal") - if signal != "SIGKILL" { - return nil, fmt.Errorf("signal not set in URL query properly. Expected 'SIGKILL', got %s", signal) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.ContainerKill(context.Background(), "container_id", "SIGKILL") - if err != nil { - t.Fatal(err) - } -} diff --git a/client/container_list_test.go b/client/container_list_test.go deleted file mode 100644 index e41c6874b5..0000000000 --- a/client/container_list_test.go +++ /dev/null @@ -1,96 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "golang.org/x/net/context" -) - -func TestContainerListError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerList(context.Background(), types.ContainerListOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerList(t *testing.T) { - expectedURL := "/containers/json" - expectedFilters := `{"before":{"container":true},"label":{"label1":true,"label2":true}}` - client := &Client{ - client: newMockClient(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) - } - query := req.URL.Query() - all := query.Get("all") - if all != "1" { - return nil, fmt.Errorf("all not set in URL query properly. Expected '1', got %s", all) - } - limit := query.Get("limit") - if limit != "0" { - return nil, fmt.Errorf("limit should have not be present in query. Expected '0', got %s", limit) - } - since := query.Get("since") - if since != "container" { - return nil, fmt.Errorf("since not set in URL query properly. Expected 'container', got %s", since) - } - before := query.Get("before") - if before != "" { - return nil, fmt.Errorf("before should have not be present in query, go %s", before) - } - size := query.Get("size") - if size != "1" { - return nil, fmt.Errorf("size not set in URL query properly. Expected '1', got %s", size) - } - filters := query.Get("filters") - if filters != expectedFilters { - return nil, fmt.Errorf("expected filters incoherent '%v' with actual filters %v", expectedFilters, filters) - } - - b, err := json.Marshal([]types.Container{ - { - ID: "container_id1", - }, - { - ID: "container_id2", - }, - }) - if err != nil { - return nil, err - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - filters := filters.NewArgs() - filters.Add("label", "label1") - filters.Add("label", "label2") - filters.Add("before", "container") - containers, err := client.ContainerList(context.Background(), types.ContainerListOptions{ - Size: true, - All: true, - Since: "container", - Filters: filters, - }) - if err != nil { - t.Fatal(err) - } - if len(containers) != 2 { - t.Fatalf("expected 2 containers, got %v", containers) - } -} diff --git a/client/container_logs_test.go b/client/container_logs_test.go deleted file mode 100644 index 99e31842c9..0000000000 --- a/client/container_logs_test.go +++ /dev/null @@ -1,133 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io" - "io/ioutil" - "log" - "net/http" - "os" - "strings" - "testing" - "time" - - "github.com/docker/docker/api/types" - - "golang.org/x/net/context" -) - -func TestContainerLogsError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerLogs(context.Background(), "container_id", types.ContainerLogsOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } - _, err = client.ContainerLogs(context.Background(), "container_id", types.ContainerLogsOptions{ - Since: "2006-01-02TZ", - }) - if err == nil || !strings.Contains(err.Error(), `parsing time "2006-01-02TZ"`) { - t.Fatalf("expected a 'parsing time' error, got %v", err) - } -} - -func TestContainerLogs(t *testing.T) { - expectedURL := "/containers/container_id/logs" - cases := []struct { - options types.ContainerLogsOptions - expectedQueryParams map[string]string - }{ - { - expectedQueryParams: map[string]string{ - "tail": "", - }, - }, - { - options: types.ContainerLogsOptions{ - Tail: "any", - }, - expectedQueryParams: map[string]string{ - "tail": "any", - }, - }, - { - options: types.ContainerLogsOptions{ - ShowStdout: true, - ShowStderr: true, - Timestamps: true, - Details: true, - Follow: true, - }, - expectedQueryParams: map[string]string{ - "tail": "", - "stdout": "1", - "stderr": "1", - "timestamps": "1", - "details": "1", - "follow": "1", - }, - }, - { - options: types.ContainerLogsOptions{ - // An complete invalid date, timestamp or go duration will be - // passed as is - Since: "invalid but valid", - }, - expectedQueryParams: map[string]string{ - "tail": "", - "since": "invalid but valid", - }, - }, - } - for _, logCase := range cases { - client := &Client{ - client: newMockClient(func(r *http.Request) (*http.Response, error) { - if !strings.HasPrefix(r.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL) - } - // Check query parameters - query := r.URL.Query() - for key, expected := range logCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("response"))), - }, nil - }), - } - body, err := client.ContainerLogs(context.Background(), "container_id", logCase.options) - if err != nil { - t.Fatal(err) - } - defer body.Close() - content, err := ioutil.ReadAll(body) - if err != nil { - t.Fatal(err) - } - if string(content) != "response" { - t.Fatalf("expected response to contain 'response', got %s", string(content)) - } - } -} - -func ExampleClient_ContainerLogs_withTimeout() { - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - - client, _ := NewEnvClient() - reader, err := client.ContainerLogs(ctx, "container_id", types.ContainerLogsOptions{}) - if err != nil { - log.Fatal(err) - } - - _, err = io.Copy(os.Stdout, reader) - if err != nil && err != io.EOF { - log.Fatal(err) - } -} diff --git a/client/container_pause_test.go b/client/container_pause_test.go deleted file mode 100644 index 0ee2f05d7e..0000000000 --- a/client/container_pause_test.go +++ /dev/null @@ -1,41 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestContainerPauseError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - err := client.ContainerPause(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerPause(t *testing.T) { - expectedURL := "/containers/container_id/pause" - client := &Client{ - client: newMockClient(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) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - err := client.ContainerPause(context.Background(), "container_id") - if err != nil { - t.Fatal(err) - } -} diff --git a/client/container_prune_test.go b/client/container_prune_test.go deleted file mode 100644 index 8a1c63897b..0000000000 --- a/client/container_prune_test.go +++ /dev/null @@ -1,124 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/stretchr/testify/assert" - "golang.org/x/net/context" -) - -func TestContainersPruneError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - version: "1.25", - } - - filters := filters.NewArgs() - - _, err := client.ContainersPrune(context.Background(), filters) - assert.EqualError(t, err, "Error response from daemon: Server error") -} - -func TestContainersPrune(t *testing.T) { - expectedURL := "/v1.25/containers/prune" - - danglingFilters := filters.NewArgs() - danglingFilters.Add("dangling", "true") - - noDanglingFilters := filters.NewArgs() - noDanglingFilters.Add("dangling", "false") - - danglingUntilFilters := filters.NewArgs() - danglingUntilFilters.Add("dangling", "true") - danglingUntilFilters.Add("until", "2016-12-15T14:00") - - labelFilters := filters.NewArgs() - labelFilters.Add("dangling", "true") - labelFilters.Add("label", "label1=foo") - labelFilters.Add("label", "label2!=bar") - - listCases := []struct { - filters filters.Args - expectedQueryParams map[string]string - }{ - { - filters: filters.Args{}, - expectedQueryParams: map[string]string{ - "until": "", - "filter": "", - "filters": "", - }, - }, - { - filters: danglingFilters, - expectedQueryParams: map[string]string{ - "until": "", - "filter": "", - "filters": `{"dangling":{"true":true}}`, - }, - }, - { - filters: danglingUntilFilters, - expectedQueryParams: map[string]string{ - "until": "", - "filter": "", - "filters": `{"dangling":{"true":true},"until":{"2016-12-15T14:00":true}}`, - }, - }, - { - filters: noDanglingFilters, - expectedQueryParams: map[string]string{ - "until": "", - "filter": "", - "filters": `{"dangling":{"false":true}}`, - }, - }, - { - filters: labelFilters, - expectedQueryParams: map[string]string{ - "until": "", - "filter": "", - "filters": `{"dangling":{"true":true},"label":{"label1=foo":true,"label2!=bar":true}}`, - }, - }, - } - for _, listCase := range listCases { - client := &Client{ - client: newMockClient(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) - } - query := req.URL.Query() - for key, expected := range listCase.expectedQueryParams { - actual := query.Get(key) - assert.Equal(t, expected, actual) - } - content, err := json.Marshal(types.ContainersPruneReport{ - ContainersDeleted: []string{"container_id1", "container_id2"}, - SpaceReclaimed: 9999, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - version: "1.25", - } - - report, err := client.ContainersPrune(context.Background(), listCase.filters) - assert.NoError(t, err) - assert.Len(t, report.ContainersDeleted, 2) - assert.Equal(t, uint64(9999), report.SpaceReclaimed) - } -} diff --git a/client/container_remove_test.go b/client/container_remove_test.go deleted file mode 100644 index 798c08b333..0000000000 --- a/client/container_remove_test.go +++ /dev/null @@ -1,59 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestContainerRemoveError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - err := client.ContainerRemove(context.Background(), "container_id", types.ContainerRemoveOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerRemove(t *testing.T) { - expectedURL := "/containers/container_id" - client := &Client{ - client: newMockClient(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) - } - query := req.URL.Query() - volume := query.Get("v") - if volume != "1" { - return nil, fmt.Errorf("v (volume) not set in URL query properly. Expected '1', got %s", volume) - } - force := query.Get("force") - if force != "1" { - return nil, fmt.Errorf("force not set in URL query properly. Expected '1', got %s", force) - } - link := query.Get("link") - if link != "" { - return nil, fmt.Errorf("link should have not be present in query, go %s", link) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.ContainerRemove(context.Background(), "container_id", types.ContainerRemoveOptions{ - RemoveVolumes: true, - Force: true, - }) - if err != nil { - t.Fatal(err) - } -} diff --git a/client/container_rename_test.go b/client/container_rename_test.go deleted file mode 100644 index 732ebff5f7..0000000000 --- a/client/container_rename_test.go +++ /dev/null @@ -1,46 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestContainerRenameError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - err := client.ContainerRename(context.Background(), "nothing", "newNothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerRename(t *testing.T) { - expectedURL := "/containers/container_id/rename" - client := &Client{ - client: newMockClient(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) - } - name := req.URL.Query().Get("name") - if name != "newName" { - return nil, fmt.Errorf("name not set in URL query properly. Expected 'newName', got %s", name) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.ContainerRename(context.Background(), "container_id", "newName") - if err != nil { - t.Fatal(err) - } -} diff --git a/client/container_resize_test.go b/client/container_resize_test.go deleted file mode 100644 index 5b2efecdce..0000000000 --- a/client/container_resize_test.go +++ /dev/null @@ -1,82 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestContainerResizeError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - err := client.ContainerResize(context.Background(), "container_id", types.ResizeOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerExecResizeError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - err := client.ContainerExecResize(context.Background(), "exec_id", types.ResizeOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerResize(t *testing.T) { - client := &Client{ - client: newMockClient(resizeTransport("/containers/container_id/resize")), - } - - err := client.ContainerResize(context.Background(), "container_id", types.ResizeOptions{ - Height: 500, - Width: 600, - }) - if err != nil { - t.Fatal(err) - } -} - -func TestContainerExecResize(t *testing.T) { - client := &Client{ - client: newMockClient(resizeTransport("/exec/exec_id/resize")), - } - - err := client.ContainerExecResize(context.Background(), "exec_id", types.ResizeOptions{ - Height: 500, - Width: 600, - }) - if err != nil { - t.Fatal(err) - } -} - -func resizeTransport(expectedURL string) func(req *http.Request) (*http.Response, error) { - return 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) - } - query := req.URL.Query() - h := query.Get("h") - if h != "500" { - return nil, fmt.Errorf("h not set in URL query properly. Expected '500', got %s", h) - } - w := query.Get("w") - if w != "600" { - return nil, fmt.Errorf("w not set in URL query properly. Expected '600', got %s", w) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - } -} diff --git a/client/container_restart_test.go b/client/container_restart_test.go deleted file mode 100644 index 8c3cfd6a6f..0000000000 --- a/client/container_restart_test.go +++ /dev/null @@ -1,48 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - "time" - - "golang.org/x/net/context" -) - -func TestContainerRestartError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - timeout := 0 * time.Second - err := client.ContainerRestart(context.Background(), "nothing", &timeout) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerRestart(t *testing.T) { - expectedURL := "/containers/container_id/restart" - client := &Client{ - client: newMockClient(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) - } - t := req.URL.Query().Get("t") - if t != "100" { - return nil, fmt.Errorf("t (timeout) not set in URL query properly. Expected '100', got %s", t) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - timeout := 100 * time.Second - err := client.ContainerRestart(context.Background(), "container_id", &timeout) - if err != nil { - t.Fatal(err) - } -} diff --git a/client/container_start_test.go b/client/container_start_test.go deleted file mode 100644 index 5826fa8bc7..0000000000 --- a/client/container_start_test.go +++ /dev/null @@ -1,58 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" -) - -func TestContainerStartError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - err := client.ContainerStart(context.Background(), "nothing", types.ContainerStartOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerStart(t *testing.T) { - expectedURL := "/containers/container_id/start" - client := &Client{ - client: newMockClient(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) - } - // we're not expecting any payload, but if one is supplied, check it is valid. - if req.Header.Get("Content-Type") == "application/json" { - var startConfig interface{} - if err := json.NewDecoder(req.Body).Decode(&startConfig); err != nil { - return nil, fmt.Errorf("Unable to parse json: %s", err) - } - } - - checkpoint := req.URL.Query().Get("checkpoint") - if checkpoint != "checkpoint_id" { - return nil, fmt.Errorf("checkpoint not set in URL query properly. Expected 'checkpoint_id', got %s", checkpoint) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.ContainerStart(context.Background(), "container_id", types.ContainerStartOptions{CheckpointID: "checkpoint_id"}) - if err != nil { - t.Fatal(err) - } -} diff --git a/client/container_stats_test.go b/client/container_stats_test.go deleted file mode 100644 index 7414f135c3..0000000000 --- a/client/container_stats_test.go +++ /dev/null @@ -1,70 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestContainerStatsError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerStats(context.Background(), "nothing", false) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerStats(t *testing.T) { - expectedURL := "/containers/container_id/stats" - cases := []struct { - stream bool - expectedStream string - }{ - { - expectedStream: "0", - }, - { - stream: true, - expectedStream: "1", - }, - } - for _, c := range cases { - client := &Client{ - client: newMockClient(func(r *http.Request) (*http.Response, error) { - if !strings.HasPrefix(r.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL) - } - - query := r.URL.Query() - stream := query.Get("stream") - if stream != c.expectedStream { - return nil, fmt.Errorf("stream not set in URL query properly. Expected '%s', got %s", c.expectedStream, stream) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("response"))), - }, nil - }), - } - resp, err := client.ContainerStats(context.Background(), "container_id", c.stream) - if err != nil { - t.Fatal(err) - } - defer resp.Body.Close() - content, err := ioutil.ReadAll(resp.Body) - if err != nil { - t.Fatal(err) - } - if string(content) != "response" { - t.Fatalf("expected response to contain 'response', got %s", string(content)) - } - } -} diff --git a/client/container_stop_test.go b/client/container_stop_test.go deleted file mode 100644 index c32cd691c4..0000000000 --- a/client/container_stop_test.go +++ /dev/null @@ -1,48 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - "time" - - "golang.org/x/net/context" -) - -func TestContainerStopError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - timeout := 0 * time.Second - err := client.ContainerStop(context.Background(), "nothing", &timeout) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerStop(t *testing.T) { - expectedURL := "/containers/container_id/stop" - client := &Client{ - client: newMockClient(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) - } - t := req.URL.Query().Get("t") - if t != "100" { - return nil, fmt.Errorf("t (timeout) not set in URL query properly. Expected '100', got %s", t) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - timeout := 100 * time.Second - err := client.ContainerStop(context.Background(), "container_id", &timeout) - if err != nil { - t.Fatal(err) - } -} diff --git a/client/container_top_test.go b/client/container_top_test.go deleted file mode 100644 index 68ccef505d..0000000000 --- a/client/container_top_test.go +++ /dev/null @@ -1,74 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "reflect" - "strings" - "testing" - - "github.com/docker/docker/api/types/container" - "golang.org/x/net/context" -) - -func TestContainerTopError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerTop(context.Background(), "nothing", []string{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerTop(t *testing.T) { - expectedURL := "/containers/container_id/top" - expectedProcesses := [][]string{ - {"p1", "p2"}, - {"p3"}, - } - expectedTitles := []string{"title1", "title2"} - - client := &Client{ - client: newMockClient(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) - } - query := req.URL.Query() - args := query.Get("ps_args") - if args != "arg1 arg2" { - return nil, fmt.Errorf("args not set in URL query properly. Expected 'arg1 arg2', got %v", args) - } - - b, err := json.Marshal(container.ContainerTopOKBody{ - Processes: [][]string{ - {"p1", "p2"}, - {"p3"}, - }, - Titles: []string{"title1", "title2"}, - }) - if err != nil { - return nil, err - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - processList, err := client.ContainerTop(context.Background(), "container_id", []string{"arg1", "arg2"}) - if err != nil { - t.Fatal(err) - } - if !reflect.DeepEqual(expectedProcesses, processList.Processes) { - t.Fatalf("Processes: expected %v, got %v", expectedProcesses, processList.Processes) - } - if !reflect.DeepEqual(expectedTitles, processList.Titles) { - t.Fatalf("Titles: expected %v, got %v", expectedTitles, processList.Titles) - } -} diff --git a/client/container_unpause_test.go b/client/container_unpause_test.go deleted file mode 100644 index 2c42727191..0000000000 --- a/client/container_unpause_test.go +++ /dev/null @@ -1,41 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestContainerUnpauseError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - err := client.ContainerUnpause(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerUnpause(t *testing.T) { - expectedURL := "/containers/container_id/unpause" - client := &Client{ - client: newMockClient(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) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - err := client.ContainerUnpause(context.Background(), "container_id") - if err != nil { - t.Fatal(err) - } -} diff --git a/client/container_update_test.go b/client/container_update_test.go deleted file mode 100644 index 715bb7ca23..0000000000 --- a/client/container_update_test.go +++ /dev/null @@ -1,58 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types/container" - "golang.org/x/net/context" -) - -func TestContainerUpdateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerUpdate(context.Background(), "nothing", container.UpdateConfig{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerUpdate(t *testing.T) { - expectedURL := "/containers/container_id/update" - - client := &Client{ - client: newMockClient(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) - } - - b, err := json.Marshal(container.ContainerUpdateOKBody{}) - if err != nil { - return nil, err - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - _, err := client.ContainerUpdate(context.Background(), "container_id", container.UpdateConfig{ - Resources: container.Resources{ - CPUPeriod: 1, - }, - RestartPolicy: container.RestartPolicy{ - Name: "always", - }, - }) - if err != nil { - t.Fatal(err) - } -} diff --git a/client/container_wait_test.go b/client/container_wait_test.go deleted file mode 100644 index 9300bc0a54..0000000000 --- a/client/container_wait_test.go +++ /dev/null @@ -1,70 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "log" - "net/http" - "strings" - "testing" - "time" - - "github.com/docker/docker/api/types/container" - - "golang.org/x/net/context" -) - -func TestContainerWaitError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - code, err := client.ContainerWait(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } - if code != -1 { - t.Fatalf("expected a status code equal to '-1', got %d", code) - } -} - -func TestContainerWait(t *testing.T) { - expectedURL := "/containers/container_id/wait" - client := &Client{ - client: newMockClient(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) - } - b, err := json.Marshal(container.ContainerWaitOKBody{ - StatusCode: 15, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - code, err := client.ContainerWait(context.Background(), "container_id") - if err != nil { - t.Fatal(err) - } - if code != 15 { - t.Fatalf("expected a status code equal to '15', got %d", code) - } -} - -func ExampleClient_ContainerWait_withTimeout() { - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - - client, _ := NewEnvClient() - _, err := client.ContainerWait(ctx, "container_id") - if err != nil { - log.Fatal(err) - } -} diff --git a/client/events_test.go b/client/events_test.go deleted file mode 100644 index ba82d2f542..0000000000 --- a/client/events_test.go +++ /dev/null @@ -1,165 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/events" - "github.com/docker/docker/api/types/filters" -) - -func TestEventsErrorInOptions(t *testing.T) { - errorCases := []struct { - options types.EventsOptions - expectedError string - }{ - { - options: types.EventsOptions{ - Since: "2006-01-02TZ", - }, - expectedError: `parsing time "2006-01-02TZ"`, - }, - { - options: types.EventsOptions{ - Until: "2006-01-02TZ", - }, - expectedError: `parsing time "2006-01-02TZ"`, - }, - } - for _, e := range errorCases { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, errs := client.Events(context.Background(), e.options) - err := <-errs - if err == nil || !strings.Contains(err.Error(), e.expectedError) { - t.Fatalf("expected an error %q, got %v", e.expectedError, err) - } - } -} - -func TestEventsErrorFromServer(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, errs := client.Events(context.Background(), types.EventsOptions{}) - err := <-errs - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestEvents(t *testing.T) { - - expectedURL := "/events" - - filters := filters.NewArgs() - filters.Add("type", events.ContainerEventType) - expectedFiltersJSON := fmt.Sprintf(`{"type":{"%s":true}}`, events.ContainerEventType) - - eventsCases := []struct { - options types.EventsOptions - events []events.Message - expectedEvents map[string]bool - expectedQueryParams map[string]string - }{ - { - options: types.EventsOptions{ - Filters: filters, - }, - expectedQueryParams: map[string]string{ - "filters": expectedFiltersJSON, - }, - events: []events.Message{}, - expectedEvents: make(map[string]bool), - }, - { - options: types.EventsOptions{ - Filters: filters, - }, - expectedQueryParams: map[string]string{ - "filters": expectedFiltersJSON, - }, - events: []events.Message{ - { - Type: "container", - ID: "1", - Action: "create", - }, - { - Type: "container", - ID: "2", - Action: "die", - }, - { - Type: "container", - ID: "3", - Action: "create", - }, - }, - expectedEvents: map[string]bool{ - "1": true, - "2": true, - "3": true, - }, - }, - } - - for _, eventsCase := range eventsCases { - client := &Client{ - client: newMockClient(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) - } - query := req.URL.Query() - - for key, expected := range eventsCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - - buffer := new(bytes.Buffer) - - for _, e := range eventsCase.events { - b, _ := json.Marshal(e) - buffer.Write(b) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(buffer), - }, nil - }), - } - - messages, errs := client.Events(context.Background(), eventsCase.options) - - loop: - for { - select { - case err := <-errs: - if err != nil && err != io.EOF { - t.Fatal(err) - } - - break loop - case e := <-messages: - _, ok := eventsCase.expectedEvents[e.ID] - if !ok { - t.Fatalf("event received not expected with action %s & id %s", e.Action, e.ID) - } - } - } - } -} diff --git a/client/image_build_test.go b/client/image_build_test.go deleted file mode 100644 index 1e18b7bda8..0000000000 --- a/client/image_build_test.go +++ /dev/null @@ -1,233 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "reflect" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/container" - "github.com/docker/go-units" -) - -func TestImageBuildError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ImageBuild(context.Background(), nil, types.ImageBuildOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestImageBuild(t *testing.T) { - v1 := "value1" - v2 := "value2" - emptyRegistryConfig := "bnVsbA==" - buildCases := []struct { - buildOptions types.ImageBuildOptions - expectedQueryParams map[string]string - expectedTags []string - expectedRegistryConfig string - }{ - { - buildOptions: types.ImageBuildOptions{ - SuppressOutput: true, - NoCache: true, - Remove: true, - ForceRemove: true, - PullParent: true, - }, - expectedQueryParams: map[string]string{ - "q": "1", - "nocache": "1", - "rm": "1", - "forcerm": "1", - "pull": "1", - }, - expectedTags: []string{}, - expectedRegistryConfig: emptyRegistryConfig, - }, - { - buildOptions: types.ImageBuildOptions{ - SuppressOutput: false, - NoCache: false, - Remove: false, - ForceRemove: false, - PullParent: false, - }, - expectedQueryParams: map[string]string{ - "q": "", - "nocache": "", - "rm": "0", - "forcerm": "", - "pull": "", - }, - expectedTags: []string{}, - expectedRegistryConfig: emptyRegistryConfig, - }, - { - buildOptions: types.ImageBuildOptions{ - RemoteContext: "remoteContext", - Isolation: container.Isolation("isolation"), - CPUSetCPUs: "2", - CPUSetMems: "12", - CPUShares: 20, - CPUQuota: 10, - CPUPeriod: 30, - Memory: 256, - MemorySwap: 512, - ShmSize: 10, - CgroupParent: "cgroup_parent", - Dockerfile: "Dockerfile", - }, - expectedQueryParams: map[string]string{ - "remote": "remoteContext", - "isolation": "isolation", - "cpusetcpus": "2", - "cpusetmems": "12", - "cpushares": "20", - "cpuquota": "10", - "cpuperiod": "30", - "memory": "256", - "memswap": "512", - "shmsize": "10", - "cgroupparent": "cgroup_parent", - "dockerfile": "Dockerfile", - "rm": "0", - }, - expectedTags: []string{}, - expectedRegistryConfig: emptyRegistryConfig, - }, - { - buildOptions: types.ImageBuildOptions{ - BuildArgs: map[string]*string{ - "ARG1": &v1, - "ARG2": &v2, - "ARG3": nil, - }, - }, - expectedQueryParams: map[string]string{ - "buildargs": `{"ARG1":"value1","ARG2":"value2","ARG3":null}`, - "rm": "0", - }, - expectedTags: []string{}, - expectedRegistryConfig: emptyRegistryConfig, - }, - { - buildOptions: types.ImageBuildOptions{ - Ulimits: []*units.Ulimit{ - { - Name: "nproc", - Hard: 65557, - Soft: 65557, - }, - { - Name: "nofile", - Hard: 20000, - Soft: 40000, - }, - }, - }, - expectedQueryParams: map[string]string{ - "ulimits": `[{"Name":"nproc","Hard":65557,"Soft":65557},{"Name":"nofile","Hard":20000,"Soft":40000}]`, - "rm": "0", - }, - expectedTags: []string{}, - expectedRegistryConfig: emptyRegistryConfig, - }, - { - buildOptions: types.ImageBuildOptions{ - AuthConfigs: map[string]types.AuthConfig{ - "https://index.docker.io/v1/": { - Auth: "dG90bwo=", - }, - }, - }, - expectedQueryParams: map[string]string{ - "rm": "0", - }, - expectedTags: []string{}, - expectedRegistryConfig: "eyJodHRwczovL2luZGV4LmRvY2tlci5pby92MS8iOnsiYXV0aCI6ImRHOTBid289In19", - }, - } - for _, buildCase := range buildCases { - expectedURL := "/build" - client := &Client{ - client: newMockClient(func(r *http.Request) (*http.Response, error) { - if !strings.HasPrefix(r.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL) - } - // Check request headers - registryConfig := r.Header.Get("X-Registry-Config") - if registryConfig != buildCase.expectedRegistryConfig { - return nil, fmt.Errorf("X-Registry-Config header not properly set in the request. Expected '%s', got %s", buildCase.expectedRegistryConfig, registryConfig) - } - contentType := r.Header.Get("Content-Type") - if contentType != "application/x-tar" { - return nil, fmt.Errorf("Content-type header not properly set in the request. Expected 'application/x-tar', got %s", contentType) - } - - // Check query parameters - query := r.URL.Query() - for key, expected := range buildCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - - // Check tags - if len(buildCase.expectedTags) > 0 { - tags := query["t"] - if !reflect.DeepEqual(tags, buildCase.expectedTags) { - return nil, fmt.Errorf("t (tags) not set in URL query properly. Expected '%s', got %s", buildCase.expectedTags, tags) - } - } - - headers := http.Header{} - headers.Add("Server", "Docker/v1.23 (MyOS)") - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("body"))), - Header: headers, - }, nil - }), - } - buildResponse, err := client.ImageBuild(context.Background(), nil, buildCase.buildOptions) - if err != nil { - t.Fatal(err) - } - if buildResponse.OSType != "MyOS" { - t.Fatalf("expected OSType to be 'MyOS', got %s", buildResponse.OSType) - } - response, err := ioutil.ReadAll(buildResponse.Body) - if err != nil { - t.Fatal(err) - } - buildResponse.Body.Close() - if string(response) != "body" { - t.Fatalf("expected Body to contain 'body' string, got %s", response) - } - } -} - -func TestGetDockerOS(t *testing.T) { - cases := map[string]string{ - "Docker/v1.22 (linux)": "linux", - "Docker/v1.22 (windows)": "windows", - "Foo/v1.22 (bar)": "", - } - for header, os := range cases { - g := getDockerOS(header) - if g != os { - t.Fatalf("Expected %s, got %s", os, g) - } - } -} diff --git a/client/image_create_test.go b/client/image_create_test.go deleted file mode 100644 index 5c2edd2ad5..0000000000 --- a/client/image_create_test.go +++ /dev/null @@ -1,76 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" -) - -func TestImageCreateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ImageCreate(context.Background(), "reference", types.ImageCreateOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server error, got %v", err) - } -} - -func TestImageCreate(t *testing.T) { - expectedURL := "/images/create" - expectedImage := "test:5000/my_image" - expectedTag := "sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - expectedReference := fmt.Sprintf("%s@%s", expectedImage, expectedTag) - expectedRegistryAuth := "eyJodHRwczovL2luZGV4LmRvY2tlci5pby92MS8iOnsiYXV0aCI6ImRHOTBid289IiwiZW1haWwiOiJqb2huQGRvZS5jb20ifX0=" - client := &Client{ - client: newMockClient(func(r *http.Request) (*http.Response, error) { - if !strings.HasPrefix(r.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL) - } - registryAuth := r.Header.Get("X-Registry-Auth") - if registryAuth != expectedRegistryAuth { - return nil, fmt.Errorf("X-Registry-Auth header not properly set in the request. Expected '%s', got %s", expectedRegistryAuth, registryAuth) - } - - query := r.URL.Query() - fromImage := query.Get("fromImage") - if fromImage != expectedImage { - return nil, fmt.Errorf("fromImage not set in URL query properly. Expected '%s', got %s", expectedImage, fromImage) - } - - tag := query.Get("tag") - if tag != expectedTag { - return nil, fmt.Errorf("tag not set in URL query properly. Expected '%s', got %s", expectedTag, tag) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("body"))), - }, nil - }), - } - - createResponse, err := client.ImageCreate(context.Background(), expectedReference, types.ImageCreateOptions{ - RegistryAuth: expectedRegistryAuth, - }) - if err != nil { - t.Fatal(err) - } - response, err := ioutil.ReadAll(createResponse) - if err != nil { - t.Fatal(err) - } - if err = createResponse.Close(); err != nil { - t.Fatal(err) - } - if string(response) != "body" { - t.Fatalf("expected Body to contain 'body' string, got %s", response) - } -} diff --git a/client/image_history_test.go b/client/image_history_test.go deleted file mode 100644 index 101bffd0c3..0000000000 --- a/client/image_history_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types/image" - "golang.org/x/net/context" -) - -func TestImageHistoryError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ImageHistory(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server error, got %v", err) - } -} - -func TestImageHistory(t *testing.T) { - expectedURL := "/images/image_id/history" - client := &Client{ - client: newMockClient(func(r *http.Request) (*http.Response, error) { - if !strings.HasPrefix(r.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL) - } - b, err := json.Marshal([]image.HistoryResponseItem{ - { - ID: "image_id1", - Tags: []string{"tag1", "tag2"}, - }, - { - ID: "image_id2", - Tags: []string{"tag1", "tag2"}, - }, - }) - if err != nil { - return nil, err - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - imageHistories, err := client.ImageHistory(context.Background(), "image_id") - if err != nil { - t.Fatal(err) - } - if len(imageHistories) != 2 { - t.Fatalf("expected 2 containers, got %v", imageHistories) - } -} diff --git a/client/image_import_test.go b/client/image_import_test.go deleted file mode 100644 index 370ad5fbed..0000000000 --- a/client/image_import_test.go +++ /dev/null @@ -1,81 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "reflect" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestImageImportError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ImageImport(context.Background(), types.ImageImportSource{}, "image:tag", types.ImageImportOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server error, got %v", err) - } -} - -func TestImageImport(t *testing.T) { - expectedURL := "/images/create" - client := &Client{ - client: newMockClient(func(r *http.Request) (*http.Response, error) { - if !strings.HasPrefix(r.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL) - } - query := r.URL.Query() - fromSrc := query.Get("fromSrc") - if fromSrc != "image_source" { - return nil, fmt.Errorf("fromSrc not set in URL query properly. Expected 'image_source', got %s", fromSrc) - } - repo := query.Get("repo") - if repo != "repository_name:imported" { - return nil, fmt.Errorf("repo not set in URL query properly. Expected 'repository_name:imported', got %s", repo) - } - tag := query.Get("tag") - if tag != "imported" { - return nil, fmt.Errorf("tag not set in URL query properly. Expected 'imported', got %s", tag) - } - message := query.Get("message") - if message != "A message" { - return nil, fmt.Errorf("message not set in URL query properly. Expected 'A message', got %s", message) - } - changes := query["changes"] - expectedChanges := []string{"change1", "change2"} - if !reflect.DeepEqual(expectedChanges, changes) { - return nil, fmt.Errorf("changes not set in URL query properly. Expected %v, got %v", expectedChanges, changes) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("response"))), - }, nil - }), - } - importResponse, err := client.ImageImport(context.Background(), types.ImageImportSource{ - Source: strings.NewReader("source"), - SourceName: "image_source", - }, "repository_name:imported", types.ImageImportOptions{ - Tag: "imported", - Message: "A message", - Changes: []string{"change1", "change2"}, - }) - if err != nil { - t.Fatal(err) - } - response, err := ioutil.ReadAll(importResponse) - if err != nil { - t.Fatal(err) - } - importResponse.Close() - if string(response) != "response" { - t.Fatalf("expected response to contain 'response', got %s", string(response)) - } -} diff --git a/client/image_inspect_test.go b/client/image_inspect_test.go deleted file mode 100644 index 74a4e49805..0000000000 --- a/client/image_inspect_test.go +++ /dev/null @@ -1,71 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "reflect" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestImageInspectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, _, err := client.ImageInspectWithRaw(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestImageInspectImageNotFound(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusNotFound, "Server error")), - } - - _, _, err := client.ImageInspectWithRaw(context.Background(), "unknown") - if err == nil || !IsErrImageNotFound(err) { - t.Fatalf("expected an imageNotFound error, got %v", err) - } -} - -func TestImageInspect(t *testing.T) { - expectedURL := "/images/image_id/json" - expectedTags := []string{"tag1", "tag2"} - client := &Client{ - client: newMockClient(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(types.ImageInspect{ - ID: "image_id", - RepoTags: expectedTags, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - imageInspect, _, err := client.ImageInspectWithRaw(context.Background(), "image_id") - if err != nil { - t.Fatal(err) - } - if imageInspect.ID != "image_id" { - t.Fatalf("expected `image_id`, got %s", imageInspect.ID) - } - if !reflect.DeepEqual(imageInspect.RepoTags, expectedTags) { - t.Fatalf("expected `%v`, got %v", expectedTags, imageInspect.RepoTags) - } -} diff --git a/client/image_list_test.go b/client/image_list_test.go deleted file mode 100644 index 7c4a46414d..0000000000 --- a/client/image_list_test.go +++ /dev/null @@ -1,159 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "golang.org/x/net/context" -) - -func TestImageListError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.ImageList(context.Background(), types.ImageListOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestImageList(t *testing.T) { - expectedURL := "/images/json" - - noDanglingfilters := filters.NewArgs() - noDanglingfilters.Add("dangling", "false") - - filters := filters.NewArgs() - filters.Add("label", "label1") - filters.Add("label", "label2") - filters.Add("dangling", "true") - - listCases := []struct { - options types.ImageListOptions - expectedQueryParams map[string]string - }{ - { - options: types.ImageListOptions{}, - expectedQueryParams: map[string]string{ - "all": "", - "filter": "", - "filters": "", - }, - }, - { - options: types.ImageListOptions{ - Filters: filters, - }, - expectedQueryParams: map[string]string{ - "all": "", - "filter": "", - "filters": `{"dangling":{"true":true},"label":{"label1":true,"label2":true}}`, - }, - }, - { - options: types.ImageListOptions{ - Filters: noDanglingfilters, - }, - expectedQueryParams: map[string]string{ - "all": "", - "filter": "", - "filters": `{"dangling":{"false":true}}`, - }, - }, - } - for _, listCase := range listCases { - client := &Client{ - client: newMockClient(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) - } - query := req.URL.Query() - for key, expected := range listCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - content, err := json.Marshal([]types.ImageSummary{ - { - ID: "image_id2", - }, - { - ID: "image_id2", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - images, err := client.ImageList(context.Background(), listCase.options) - if err != nil { - t.Fatal(err) - } - if len(images) != 2 { - t.Fatalf("expected 2 images, got %v", images) - } - } -} - -func TestImageListApiBefore125(t *testing.T) { - expectedFilter := "image:tag" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - query := req.URL.Query() - actualFilter := query.Get("filter") - if actualFilter != expectedFilter { - return nil, fmt.Errorf("filter not set in URL query properly. Expected '%s', got %s", expectedFilter, actualFilter) - } - actualFilters := query.Get("filters") - if actualFilters != "" { - return nil, fmt.Errorf("filters should have not been present, were with value: %s", actualFilters) - } - content, err := json.Marshal([]types.ImageSummary{ - { - ID: "image_id2", - }, - { - ID: "image_id2", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - version: "1.24", - } - - filters := filters.NewArgs() - filters.Add("reference", "image:tag") - - options := types.ImageListOptions{ - Filters: filters, - } - - images, err := client.ImageList(context.Background(), options) - if err != nil { - t.Fatal(err) - } - if len(images) != 2 { - t.Fatalf("expected 2 images, got %v", images) - } -} diff --git a/client/image_load_test.go b/client/image_load_test.go deleted file mode 100644 index 68dc14ff22..0000000000 --- a/client/image_load_test.go +++ /dev/null @@ -1,95 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestImageLoadError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.ImageLoad(context.Background(), nil, true) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestImageLoad(t *testing.T) { - expectedURL := "/images/load" - expectedInput := "inputBody" - expectedOutput := "outputBody" - loadCases := []struct { - quiet bool - responseContentType string - expectedResponseJSON bool - expectedQueryParams map[string]string - }{ - { - quiet: false, - responseContentType: "text/plain", - expectedResponseJSON: false, - expectedQueryParams: map[string]string{ - "quiet": "0", - }, - }, - { - quiet: true, - responseContentType: "application/json", - expectedResponseJSON: true, - expectedQueryParams: map[string]string{ - "quiet": "1", - }, - }, - } - for _, loadCase := range loadCases { - client := &Client{ - client: newMockClient(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) - } - contentType := req.Header.Get("Content-Type") - if contentType != "application/x-tar" { - return nil, fmt.Errorf("content-type not set in URL headers properly. Expected 'application/x-tar', got %s", contentType) - } - query := req.URL.Query() - for key, expected := range loadCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - headers := http.Header{} - headers.Add("Content-Type", loadCase.responseContentType) - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(expectedOutput))), - Header: headers, - }, nil - }), - } - - input := bytes.NewReader([]byte(expectedInput)) - imageLoadResponse, err := client.ImageLoad(context.Background(), input, loadCase.quiet) - if err != nil { - t.Fatal(err) - } - if imageLoadResponse.JSON != loadCase.expectedResponseJSON { - t.Fatalf("expected a JSON response, was not.") - } - body, err := ioutil.ReadAll(imageLoadResponse.Body) - if err != nil { - t.Fatal(err) - } - if string(body) != expectedOutput { - t.Fatalf("expected %s, got %s", expectedOutput, string(body)) - } - } -} diff --git a/client/image_prune_test.go b/client/image_prune_test.go deleted file mode 100644 index 453f84adee..0000000000 --- a/client/image_prune_test.go +++ /dev/null @@ -1,119 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/stretchr/testify/assert" - "golang.org/x/net/context" -) - -func TestImagesPruneError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - version: "1.25", - } - - filters := filters.NewArgs() - - _, err := client.ImagesPrune(context.Background(), filters) - assert.EqualError(t, err, "Error response from daemon: Server error") -} - -func TestImagesPrune(t *testing.T) { - expectedURL := "/v1.25/images/prune" - - danglingFilters := filters.NewArgs() - danglingFilters.Add("dangling", "true") - - noDanglingFilters := filters.NewArgs() - noDanglingFilters.Add("dangling", "false") - - labelFilters := filters.NewArgs() - labelFilters.Add("dangling", "true") - labelFilters.Add("label", "label1=foo") - labelFilters.Add("label", "label2!=bar") - - listCases := []struct { - filters filters.Args - expectedQueryParams map[string]string - }{ - { - filters: filters.Args{}, - expectedQueryParams: map[string]string{ - "until": "", - "filter": "", - "filters": "", - }, - }, - { - filters: danglingFilters, - expectedQueryParams: map[string]string{ - "until": "", - "filter": "", - "filters": `{"dangling":{"true":true}}`, - }, - }, - { - filters: noDanglingFilters, - expectedQueryParams: map[string]string{ - "until": "", - "filter": "", - "filters": `{"dangling":{"false":true}}`, - }, - }, - { - filters: labelFilters, - expectedQueryParams: map[string]string{ - "until": "", - "filter": "", - "filters": `{"dangling":{"true":true},"label":{"label1=foo":true,"label2!=bar":true}}`, - }, - }, - } - for _, listCase := range listCases { - client := &Client{ - client: newMockClient(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) - } - query := req.URL.Query() - for key, expected := range listCase.expectedQueryParams { - actual := query.Get(key) - assert.Equal(t, expected, actual) - } - content, err := json.Marshal(types.ImagesPruneReport{ - ImagesDeleted: []types.ImageDeleteResponseItem{ - { - Deleted: "image_id1", - }, - { - Deleted: "image_id2", - }, - }, - SpaceReclaimed: 9999, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - version: "1.25", - } - - report, err := client.ImagesPrune(context.Background(), listCase.filters) - assert.NoError(t, err) - assert.Len(t, report.ImagesDeleted, 2) - assert.Equal(t, uint64(9999), report.SpaceReclaimed) - } -} diff --git a/client/image_pull_test.go b/client/image_pull_test.go deleted file mode 100644 index ab49d2d349..0000000000 --- a/client/image_pull_test.go +++ /dev/null @@ -1,199 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" -) - -func TestImagePullReferenceParseError(t *testing.T) { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - return nil, nil - }), - } - // An empty reference is an invalid reference - _, err := client.ImagePull(context.Background(), "", types.ImagePullOptions{}) - if err == nil || !strings.Contains(err.Error(), "invalid reference format") { - t.Fatalf("expected an error, got %v", err) - } -} - -func TestImagePullAnyError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ImagePull(context.Background(), "myimage", types.ImagePullOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestImagePullStatusUnauthorizedError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), - } - _, err := client.ImagePull(context.Background(), "myimage", types.ImagePullOptions{}) - if err == nil || err.Error() != "Error response from daemon: Unauthorized error" { - t.Fatalf("expected an Unauthorized Error, got %v", err) - } -} - -func TestImagePullWithUnauthorizedErrorAndPrivilegeFuncError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), - } - privilegeFunc := func() (string, error) { - return "", fmt.Errorf("Error requesting privilege") - } - _, err := client.ImagePull(context.Background(), "myimage", types.ImagePullOptions{ - PrivilegeFunc: privilegeFunc, - }) - if err == nil || err.Error() != "Error requesting privilege" { - t.Fatalf("expected an error requesting privilege, got %v", err) - } -} - -func TestImagePullWithUnauthorizedErrorAndAnotherUnauthorizedError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), - } - privilegeFunc := func() (string, error) { - return "a-auth-header", nil - } - _, err := client.ImagePull(context.Background(), "myimage", types.ImagePullOptions{ - PrivilegeFunc: privilegeFunc, - }) - if err == nil || err.Error() != "Error response from daemon: Unauthorized error" { - t.Fatalf("expected an Unauthorized Error, got %v", err) - } -} - -func TestImagePullWithPrivilegedFuncNoError(t *testing.T) { - expectedURL := "/images/create" - client := &Client{ - client: newMockClient(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) - } - auth := req.Header.Get("X-Registry-Auth") - if auth == "NotValid" { - return &http.Response{ - StatusCode: http.StatusUnauthorized, - Body: ioutil.NopCloser(bytes.NewReader([]byte("Invalid credentials"))), - }, nil - } - if auth != "IAmValid" { - return nil, fmt.Errorf("Invalid auth header : expected %s, got %s", "IAmValid", auth) - } - query := req.URL.Query() - fromImage := query.Get("fromImage") - if fromImage != "myimage" { - return nil, fmt.Errorf("fromimage not set in URL query properly. Expected '%s', got %s", "myimage", fromImage) - } - tag := query.Get("tag") - if tag != "latest" { - return nil, fmt.Errorf("tag not set in URL query properly. Expected '%s', got %s", "latest", tag) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("hello world"))), - }, nil - }), - } - privilegeFunc := func() (string, error) { - return "IAmValid", nil - } - resp, err := client.ImagePull(context.Background(), "myimage", types.ImagePullOptions{ - RegistryAuth: "NotValid", - PrivilegeFunc: privilegeFunc, - }) - if err != nil { - t.Fatal(err) - } - body, err := ioutil.ReadAll(resp) - if err != nil { - t.Fatal(err) - } - if string(body) != "hello world" { - t.Fatalf("expected 'hello world', got %s", string(body)) - } -} - -func TestImagePullWithoutErrors(t *testing.T) { - expectedURL := "/images/create" - expectedOutput := "hello world" - pullCases := []struct { - all bool - reference string - expectedImage string - expectedTag string - }{ - { - all: false, - reference: "myimage", - expectedImage: "myimage", - expectedTag: "latest", - }, - { - all: false, - reference: "myimage:tag", - expectedImage: "myimage", - expectedTag: "tag", - }, - { - all: true, - reference: "myimage", - expectedImage: "myimage", - expectedTag: "", - }, - { - all: true, - reference: "myimage:anything", - expectedImage: "myimage", - expectedTag: "", - }, - } - for _, pullCase := range pullCases { - client := &Client{ - client: newMockClient(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) - } - query := req.URL.Query() - fromImage := query.Get("fromImage") - if fromImage != pullCase.expectedImage { - return nil, fmt.Errorf("fromimage not set in URL query properly. Expected '%s', got %s", pullCase.expectedImage, fromImage) - } - tag := query.Get("tag") - if tag != pullCase.expectedTag { - return nil, fmt.Errorf("tag not set in URL query properly. Expected '%s', got %s", pullCase.expectedTag, tag) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(expectedOutput))), - }, nil - }), - } - resp, err := client.ImagePull(context.Background(), pullCase.reference, types.ImagePullOptions{ - All: pullCase.all, - }) - if err != nil { - t.Fatal(err) - } - body, err := ioutil.ReadAll(resp) - if err != nil { - t.Fatal(err) - } - if string(body) != expectedOutput { - t.Fatalf("expected '%s', got %s", expectedOutput, string(body)) - } - } -} diff --git a/client/image_push_test.go b/client/image_push_test.go deleted file mode 100644 index f93debf5bb..0000000000 --- a/client/image_push_test.go +++ /dev/null @@ -1,180 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" -) - -func TestImagePushReferenceError(t *testing.T) { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - return nil, nil - }), - } - // An empty reference is an invalid reference - _, err := client.ImagePush(context.Background(), "", types.ImagePushOptions{}) - if err == nil || !strings.Contains(err.Error(), "invalid reference format") { - t.Fatalf("expected an error, got %v", err) - } - // An canonical reference cannot be pushed - _, err = client.ImagePush(context.Background(), "repo@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", types.ImagePushOptions{}) - if err == nil || err.Error() != "cannot push a digest reference" { - t.Fatalf("expected an error, got %v", err) - } -} - -func TestImagePushAnyError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ImagePush(context.Background(), "myimage", types.ImagePushOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestImagePushStatusUnauthorizedError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), - } - _, err := client.ImagePush(context.Background(), "myimage", types.ImagePushOptions{}) - if err == nil || err.Error() != "Error response from daemon: Unauthorized error" { - t.Fatalf("expected an Unauthorized Error, got %v", err) - } -} - -func TestImagePushWithUnauthorizedErrorAndPrivilegeFuncError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), - } - privilegeFunc := func() (string, error) { - return "", fmt.Errorf("Error requesting privilege") - } - _, err := client.ImagePush(context.Background(), "myimage", types.ImagePushOptions{ - PrivilegeFunc: privilegeFunc, - }) - if err == nil || err.Error() != "Error requesting privilege" { - t.Fatalf("expected an error requesting privilege, got %v", err) - } -} - -func TestImagePushWithUnauthorizedErrorAndAnotherUnauthorizedError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), - } - privilegeFunc := func() (string, error) { - return "a-auth-header", nil - } - _, err := client.ImagePush(context.Background(), "myimage", types.ImagePushOptions{ - PrivilegeFunc: privilegeFunc, - }) - if err == nil || err.Error() != "Error response from daemon: Unauthorized error" { - t.Fatalf("expected an Unauthorized Error, got %v", err) - } -} - -func TestImagePushWithPrivilegedFuncNoError(t *testing.T) { - expectedURL := "/images/myimage/push" - client := &Client{ - client: newMockClient(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) - } - auth := req.Header.Get("X-Registry-Auth") - if auth == "NotValid" { - return &http.Response{ - StatusCode: http.StatusUnauthorized, - Body: ioutil.NopCloser(bytes.NewReader([]byte("Invalid credentials"))), - }, nil - } - if auth != "IAmValid" { - return nil, fmt.Errorf("Invalid auth header : expected %s, got %s", "IAmValid", auth) - } - query := req.URL.Query() - tag := query.Get("tag") - if tag != "tag" { - return nil, fmt.Errorf("tag not set in URL query properly. Expected '%s', got %s", "tag", tag) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("hello world"))), - }, nil - }), - } - privilegeFunc := func() (string, error) { - return "IAmValid", nil - } - resp, err := client.ImagePush(context.Background(), "myimage:tag", types.ImagePushOptions{ - RegistryAuth: "NotValid", - PrivilegeFunc: privilegeFunc, - }) - if err != nil { - t.Fatal(err) - } - body, err := ioutil.ReadAll(resp) - if err != nil { - t.Fatal(err) - } - if string(body) != "hello world" { - t.Fatalf("expected 'hello world', got %s", string(body)) - } -} - -func TestImagePushWithoutErrors(t *testing.T) { - expectedOutput := "hello world" - expectedURLFormat := "/images/%s/push" - pullCases := []struct { - reference string - expectedImage string - expectedTag string - }{ - { - reference: "myimage", - expectedImage: "myimage", - expectedTag: "", - }, - { - reference: "myimage:tag", - expectedImage: "myimage", - expectedTag: "tag", - }, - } - for _, pullCase := range pullCases { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - expectedURL := fmt.Sprintf(expectedURLFormat, pullCase.expectedImage) - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - query := req.URL.Query() - tag := query.Get("tag") - if tag != pullCase.expectedTag { - return nil, fmt.Errorf("tag not set in URL query properly. Expected '%s', got %s", pullCase.expectedTag, tag) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(expectedOutput))), - }, nil - }), - } - resp, err := client.ImagePush(context.Background(), pullCase.reference, types.ImagePushOptions{}) - if err != nil { - t.Fatal(err) - } - body, err := ioutil.ReadAll(resp) - if err != nil { - t.Fatal(err) - } - if string(body) != expectedOutput { - t.Fatalf("expected '%s', got %s", expectedOutput, string(body)) - } - } -} diff --git a/client/image_remove_test.go b/client/image_remove_test.go deleted file mode 100644 index 9856311305..0000000000 --- a/client/image_remove_test.go +++ /dev/null @@ -1,95 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestImageRemoveError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.ImageRemove(context.Background(), "image_id", types.ImageRemoveOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestImageRemove(t *testing.T) { - expectedURL := "/images/image_id" - removeCases := []struct { - force bool - pruneChildren bool - expectedQueryParams map[string]string - }{ - { - force: false, - pruneChildren: false, - expectedQueryParams: map[string]string{ - "force": "", - "noprune": "1", - }, - }, { - force: true, - pruneChildren: true, - expectedQueryParams: map[string]string{ - "force": "1", - "noprune": "", - }, - }, - } - for _, removeCase := range removeCases { - client := &Client{ - client: newMockClient(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) - } - if req.Method != "DELETE" { - return nil, fmt.Errorf("expected DELETE method, got %s", req.Method) - } - query := req.URL.Query() - for key, expected := range removeCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - b, err := json.Marshal([]types.ImageDeleteResponseItem{ - { - Untagged: "image_id1", - }, - { - Deleted: "image_id", - }, - }) - if err != nil { - return nil, err - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - imageDeletes, err := client.ImageRemove(context.Background(), "image_id", types.ImageRemoveOptions{ - Force: removeCase.force, - PruneChildren: removeCase.pruneChildren, - }) - if err != nil { - t.Fatal(err) - } - if len(imageDeletes) != 2 { - t.Fatalf("expected 2 deleted images, got %v", imageDeletes) - } - } -} diff --git a/client/image_save_test.go b/client/image_save_test.go deleted file mode 100644 index 8f0cf88640..0000000000 --- a/client/image_save_test.go +++ /dev/null @@ -1,58 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "reflect" - "testing" - - "golang.org/x/net/context" - - "strings" -) - -func TestImageSaveError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ImageSave(context.Background(), []string{"nothing"}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server error, got %v", err) - } -} - -func TestImageSave(t *testing.T) { - expectedURL := "/images/get" - client := &Client{ - client: newMockClient(func(r *http.Request) (*http.Response, error) { - if !strings.HasPrefix(r.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL) - } - query := r.URL.Query() - names := query["names"] - expectedNames := []string{"image_id1", "image_id2"} - if !reflect.DeepEqual(names, expectedNames) { - return nil, fmt.Errorf("names not set in URL query properly. Expected %v, got %v", names, expectedNames) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("response"))), - }, nil - }), - } - saveResponse, err := client.ImageSave(context.Background(), []string{"image_id1", "image_id2"}) - if err != nil { - t.Fatal(err) - } - response, err := ioutil.ReadAll(saveResponse) - if err != nil { - t.Fatal(err) - } - saveResponse.Close() - if string(response) != "response" { - t.Fatalf("expected response to contain 'response', got %s", string(response)) - } -} diff --git a/client/image_search_test.go b/client/image_search_test.go deleted file mode 100644 index a64e0c458b..0000000000 --- a/client/image_search_test.go +++ /dev/null @@ -1,166 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "encoding/json" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/registry" -) - -func TestImageSearchAnyError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestImageSearchStatusUnauthorizedError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), - } - _, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{}) - if err == nil || err.Error() != "Error response from daemon: Unauthorized error" { - t.Fatalf("expected an Unauthorized Error, got %v", err) - } -} - -func TestImageSearchWithUnauthorizedErrorAndPrivilegeFuncError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), - } - privilegeFunc := func() (string, error) { - return "", fmt.Errorf("Error requesting privilege") - } - _, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{ - PrivilegeFunc: privilegeFunc, - }) - if err == nil || err.Error() != "Error requesting privilege" { - t.Fatalf("expected an error requesting privilege, got %v", err) - } -} - -func TestImageSearchWithUnauthorizedErrorAndAnotherUnauthorizedError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), - } - privilegeFunc := func() (string, error) { - return "a-auth-header", nil - } - _, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{ - PrivilegeFunc: privilegeFunc, - }) - if err == nil || err.Error() != "Error response from daemon: Unauthorized error" { - t.Fatalf("expected an Unauthorized Error, got %v", err) - } -} - -func TestImageSearchWithPrivilegedFuncNoError(t *testing.T) { - expectedURL := "/images/search" - client := &Client{ - client: newMockClient(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) - } - auth := req.Header.Get("X-Registry-Auth") - if auth == "NotValid" { - return &http.Response{ - StatusCode: http.StatusUnauthorized, - Body: ioutil.NopCloser(bytes.NewReader([]byte("Invalid credentials"))), - }, nil - } - if auth != "IAmValid" { - return nil, fmt.Errorf("Invalid auth header : expected 'IAmValid', got %s", auth) - } - query := req.URL.Query() - term := query.Get("term") - if term != "some-image" { - return nil, fmt.Errorf("term not set in URL query properly. Expected 'some-image', got %s", term) - } - content, err := json.Marshal([]registry.SearchResult{ - { - Name: "anything", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - privilegeFunc := func() (string, error) { - return "IAmValid", nil - } - results, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{ - RegistryAuth: "NotValid", - PrivilegeFunc: privilegeFunc, - }) - if err != nil { - t.Fatal(err) - } - if len(results) != 1 { - t.Fatalf("expected 1 result, got %v", results) - } -} - -func TestImageSearchWithoutErrors(t *testing.T) { - expectedURL := "/images/search" - filterArgs := filters.NewArgs() - filterArgs.Add("is-automated", "true") - filterArgs.Add("stars", "3") - - expectedFilters := `{"is-automated":{"true":true},"stars":{"3":true}}` - - client := &Client{ - client: newMockClient(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) - } - query := req.URL.Query() - term := query.Get("term") - if term != "some-image" { - return nil, fmt.Errorf("term not set in URL query properly. Expected 'some-image', got %s", term) - } - filters := query.Get("filters") - if filters != expectedFilters { - return nil, fmt.Errorf("filters not set in URL query properly. Expected '%s', got %s", expectedFilters, filters) - } - content, err := json.Marshal([]registry.SearchResult{ - { - Name: "anything", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - results, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{ - Filters: filterArgs, - }) - if err != nil { - t.Fatal(err) - } - if len(results) != 1 { - t.Fatalf("expected a result, got %v", results) - } -} diff --git a/client/image_tag_test.go b/client/image_tag_test.go deleted file mode 100644 index f7a0ee331c..0000000000 --- a/client/image_tag_test.go +++ /dev/null @@ -1,143 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestImageTagError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.ImageTag(context.Background(), "image_id", "repo:tag") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -// Note: this is not testing all the InvalidReference as it's the responsibility -// of distribution/reference package. -func TestImageTagInvalidReference(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.ImageTag(context.Background(), "image_id", "aa/asdf$$^/aa") - if err == nil || err.Error() != `Error parsing reference: "aa/asdf$$^/aa" is not a valid repository/tag: invalid reference format` { - t.Fatalf("expected ErrReferenceInvalidFormat, got %v", err) - } -} - -func TestImageTagInvalidSourceImageName(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.ImageTag(context.Background(), "invalid_source_image_name_", "repo:tag") - if err == nil || err.Error() != "Error parsing reference: \"invalid_source_image_name_\" is not a valid repository/tag: invalid reference format" { - t.Fatalf("expected Parsing Reference Error, got %v", err) - } -} - -func TestImageTagHexSource(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusOK, "OK")), - } - - err := client.ImageTag(context.Background(), "0d409d33b27e47423b049f7f863faa08655a8c901749c2b25b93ca67d01a470d", "repo:tag") - if err != nil { - t.Fatalf("got error: %v", err) - } -} - -func TestImageTag(t *testing.T) { - expectedURL := "/images/image_id/tag" - tagCases := []struct { - reference string - expectedQueryParams map[string]string - }{ - { - reference: "repository:tag1", - expectedQueryParams: map[string]string{ - "repo": "repository", - "tag": "tag1", - }, - }, { - reference: "another_repository:latest", - expectedQueryParams: map[string]string{ - "repo": "another_repository", - "tag": "latest", - }, - }, { - reference: "another_repository", - expectedQueryParams: map[string]string{ - "repo": "another_repository", - "tag": "latest", - }, - }, { - reference: "test/another_repository", - expectedQueryParams: map[string]string{ - "repo": "test/another_repository", - "tag": "latest", - }, - }, { - reference: "test/another_repository:tag1", - expectedQueryParams: map[string]string{ - "repo": "test/another_repository", - "tag": "tag1", - }, - }, { - reference: "test/test/another_repository:tag1", - expectedQueryParams: map[string]string{ - "repo": "test/test/another_repository", - "tag": "tag1", - }, - }, { - reference: "test:5000/test/another_repository:tag1", - expectedQueryParams: map[string]string{ - "repo": "test:5000/test/another_repository", - "tag": "tag1", - }, - }, { - reference: "test:5000/test/another_repository", - expectedQueryParams: map[string]string{ - "repo": "test:5000/test/another_repository", - "tag": "latest", - }, - }, - } - for _, tagCase := range tagCases { - client := &Client{ - client: newMockClient(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) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - query := req.URL.Query() - for key, expected := range tagCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - err := client.ImageTag(context.Background(), "image_id", tagCase.reference) - if err != nil { - t.Fatal(err) - } - } -} diff --git a/client/info_test.go b/client/info_test.go deleted file mode 100644 index 79f23c8af2..0000000000 --- a/client/info_test.go +++ /dev/null @@ -1,76 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestInfoServerError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.Info(context.Background()) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestInfoInvalidResponseJSONError(t *testing.T) { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("invalid json"))), - }, nil - }), - } - _, err := client.Info(context.Background()) - if err == nil || !strings.Contains(err.Error(), "invalid character") { - t.Fatalf("expected a 'invalid character' error, got %v", err) - } -} - -func TestInfo(t *testing.T) { - expectedURL := "/info" - client := &Client{ - client: newMockClient(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) - } - info := &types.Info{ - ID: "daemonID", - Containers: 3, - } - b, err := json.Marshal(info) - if err != nil { - return nil, err - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - info, err := client.Info(context.Background()) - if err != nil { - t.Fatal(err) - } - - if info.ID != "daemonID" { - t.Fatalf("expected daemonID, got %s", info.ID) - } - - if info.Containers != 3 { - t.Fatalf("expected 3 containers, got %d", info.Containers) - } -} diff --git a/client/network_connect_test.go b/client/network_connect_test.go deleted file mode 100644 index 91b1a76676..0000000000 --- a/client/network_connect_test.go +++ /dev/null @@ -1,111 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/network" -) - -func TestNetworkConnectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.NetworkConnect(context.Background(), "network_id", "container_id", nil) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestNetworkConnectEmptyNilEndpointSettings(t *testing.T) { - expectedURL := "/networks/network_id/connect" - - client := &Client{ - client: newMockClient(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) - } - - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - - var connect types.NetworkConnect - if err := json.NewDecoder(req.Body).Decode(&connect); err != nil { - return nil, err - } - - if connect.Container != "container_id" { - return nil, fmt.Errorf("expected 'container_id', got %s", connect.Container) - } - - if connect.EndpointConfig != nil { - return nil, fmt.Errorf("expected connect.EndpointConfig to be nil, got %v", connect.EndpointConfig) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.NetworkConnect(context.Background(), "network_id", "container_id", nil) - if err != nil { - t.Fatal(err) - } -} - -func TestNetworkConnect(t *testing.T) { - expectedURL := "/networks/network_id/connect" - - client := &Client{ - client: newMockClient(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) - } - - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - - var connect types.NetworkConnect - if err := json.NewDecoder(req.Body).Decode(&connect); err != nil { - return nil, err - } - - if connect.Container != "container_id" { - return nil, fmt.Errorf("expected 'container_id', got %s", connect.Container) - } - - if connect.EndpointConfig == nil { - return nil, fmt.Errorf("expected connect.EndpointConfig to be not nil, got %v", connect.EndpointConfig) - } - - if connect.EndpointConfig.NetworkID != "NetworkID" { - return nil, fmt.Errorf("expected 'NetworkID', got %s", connect.EndpointConfig.NetworkID) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.NetworkConnect(context.Background(), "network_id", "container_id", &network.EndpointSettings{ - NetworkID: "NetworkID", - }) - if err != nil { - t.Fatal(err) - } -} diff --git a/client/network_create_test.go b/client/network_create_test.go deleted file mode 100644 index 0e2457f89c..0000000000 --- a/client/network_create_test.go +++ /dev/null @@ -1,72 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestNetworkCreateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.NetworkCreate(context.Background(), "mynetwork", types.NetworkCreate{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestNetworkCreate(t *testing.T) { - expectedURL := "/networks/create" - - client := &Client{ - client: newMockClient(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) - } - - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - - content, err := json.Marshal(types.NetworkCreateResponse{ - ID: "network_id", - Warning: "warning", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - networkResponse, err := client.NetworkCreate(context.Background(), "mynetwork", types.NetworkCreate{ - CheckDuplicate: true, - Driver: "mydriver", - EnableIPv6: true, - Internal: true, - Options: map[string]string{ - "opt-key": "opt-value", - }, - }) - if err != nil { - t.Fatal(err) - } - if networkResponse.ID != "network_id" { - t.Fatalf("expected networkResponse.ID to be 'network_id', got %s", networkResponse.ID) - } - if networkResponse.Warning != "warning" { - t.Fatalf("expected networkResponse.Warning to be 'warning', got %s", networkResponse.Warning) - } -} diff --git a/client/network_disconnect_test.go b/client/network_disconnect_test.go deleted file mode 100644 index b54a2b1ccf..0000000000 --- a/client/network_disconnect_test.go +++ /dev/null @@ -1,64 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestNetworkDisconnectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.NetworkDisconnect(context.Background(), "network_id", "container_id", false) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestNetworkDisconnect(t *testing.T) { - expectedURL := "/networks/network_id/disconnect" - - client := &Client{ - client: newMockClient(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) - } - - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - - var disconnect types.NetworkDisconnect - if err := json.NewDecoder(req.Body).Decode(&disconnect); err != nil { - return nil, err - } - - if disconnect.Container != "container_id" { - return nil, fmt.Errorf("expected 'container_id', got %s", disconnect.Container) - } - - if !disconnect.Force { - return nil, fmt.Errorf("expected Force to be true, got %v", disconnect.Force) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.NetworkDisconnect(context.Background(), "network_id", "container_id", true) - if err != nil { - t.Fatal(err) - } -} diff --git a/client/network_inspect_test.go b/client/network_inspect_test.go deleted file mode 100644 index 1504289f5d..0000000000 --- a/client/network_inspect_test.go +++ /dev/null @@ -1,96 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/network" - "golang.org/x/net/context" -) - -func TestNetworkInspectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.NetworkInspect(context.Background(), "nothing", false) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestNetworkInspectContainerNotFound(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusNotFound, "Server error")), - } - - _, err := client.NetworkInspect(context.Background(), "unknown", false) - if err == nil || !IsErrNetworkNotFound(err) { - t.Fatalf("expected a networkNotFound error, got %v", err) - } -} - -func TestNetworkInspect(t *testing.T) { - expectedURL := "/networks/network_id" - client := &Client{ - client: newMockClient(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) - } - if req.Method != "GET" { - return nil, fmt.Errorf("expected GET method, got %s", req.Method) - } - - var ( - content []byte - err error - ) - if strings.HasPrefix(req.URL.RawQuery, "verbose=true") { - s := map[string]network.ServiceInfo{ - "web": {}, - } - content, err = json.Marshal(types.NetworkResource{ - Name: "mynetwork", - Services: s, - }) - } else { - content, err = json.Marshal(types.NetworkResource{ - Name: "mynetwork", - }) - } - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - r, err := client.NetworkInspect(context.Background(), "network_id", false) - if err != nil { - t.Fatal(err) - } - if r.Name != "mynetwork" { - t.Fatalf("expected `mynetwork`, got %s", r.Name) - } - - r, err = client.NetworkInspect(context.Background(), "network_id", true) - if err != nil { - t.Fatal(err) - } - if r.Name != "mynetwork" { - t.Fatalf("expected `mynetwork`, got %s", r.Name) - } - _, ok := r.Services["web"] - if !ok { - t.Fatalf("expected service `web` missing in the verbose output") - } -} diff --git a/client/network_list_test.go b/client/network_list_test.go deleted file mode 100644 index 4d443496ac..0000000000 --- a/client/network_list_test.go +++ /dev/null @@ -1,108 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "golang.org/x/net/context" -) - -func TestNetworkListError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.NetworkList(context.Background(), types.NetworkListOptions{ - Filters: filters.NewArgs(), - }) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestNetworkList(t *testing.T) { - expectedURL := "/networks" - - noDanglingFilters := filters.NewArgs() - noDanglingFilters.Add("dangling", "false") - - danglingFilters := filters.NewArgs() - danglingFilters.Add("dangling", "true") - - labelFilters := filters.NewArgs() - labelFilters.Add("label", "label1") - labelFilters.Add("label", "label2") - - listCases := []struct { - options types.NetworkListOptions - expectedFilters string - }{ - { - options: types.NetworkListOptions{ - Filters: filters.NewArgs(), - }, - expectedFilters: "", - }, { - options: types.NetworkListOptions{ - Filters: noDanglingFilters, - }, - expectedFilters: `{"dangling":{"false":true}}`, - }, { - options: types.NetworkListOptions{ - Filters: danglingFilters, - }, - expectedFilters: `{"dangling":{"true":true}}`, - }, { - options: types.NetworkListOptions{ - Filters: labelFilters, - }, - expectedFilters: `{"label":{"label1":true,"label2":true}}`, - }, - } - - for _, listCase := range listCases { - client := &Client{ - client: newMockClient(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) - } - if req.Method != "GET" { - return nil, fmt.Errorf("expected GET method, got %s", req.Method) - } - query := req.URL.Query() - actualFilters := query.Get("filters") - if actualFilters != listCase.expectedFilters { - return nil, fmt.Errorf("filters not set in URL query properly. Expected '%s', got %s", listCase.expectedFilters, actualFilters) - } - content, err := json.Marshal([]types.NetworkResource{ - { - Name: "network", - Driver: "bridge", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - networkResources, err := client.NetworkList(context.Background(), listCase.options) - if err != nil { - t.Fatal(err) - } - if len(networkResources) != 1 { - t.Fatalf("expected 1 network resource, got %v", networkResources) - } - } -} diff --git a/client/network_prune_test.go b/client/network_prune_test.go deleted file mode 100644 index 3e4f5d0415..0000000000 --- a/client/network_prune_test.go +++ /dev/null @@ -1,112 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/stretchr/testify/assert" - "golang.org/x/net/context" -) - -func TestNetworksPruneError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - version: "1.25", - } - - filters := filters.NewArgs() - - _, err := client.NetworksPrune(context.Background(), filters) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestNetworksPrune(t *testing.T) { - expectedURL := "/v1.25/networks/prune" - - danglingFilters := filters.NewArgs() - danglingFilters.Add("dangling", "true") - - noDanglingFilters := filters.NewArgs() - noDanglingFilters.Add("dangling", "false") - - labelFilters := filters.NewArgs() - labelFilters.Add("dangling", "true") - labelFilters.Add("label", "label1=foo") - labelFilters.Add("label", "label2!=bar") - - listCases := []struct { - filters filters.Args - expectedQueryParams map[string]string - }{ - { - filters: filters.Args{}, - expectedQueryParams: map[string]string{ - "until": "", - "filter": "", - "filters": "", - }, - }, - { - filters: danglingFilters, - expectedQueryParams: map[string]string{ - "until": "", - "filter": "", - "filters": `{"dangling":{"true":true}}`, - }, - }, - { - filters: noDanglingFilters, - expectedQueryParams: map[string]string{ - "until": "", - "filter": "", - "filters": `{"dangling":{"false":true}}`, - }, - }, - { - filters: labelFilters, - expectedQueryParams: map[string]string{ - "until": "", - "filter": "", - "filters": `{"dangling":{"true":true},"label":{"label1=foo":true,"label2!=bar":true}}`, - }, - }, - } - for _, listCase := range listCases { - client := &Client{ - client: newMockClient(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) - } - query := req.URL.Query() - for key, expected := range listCase.expectedQueryParams { - actual := query.Get(key) - assert.Equal(t, expected, actual) - } - content, err := json.Marshal(types.NetworksPruneReport{ - NetworksDeleted: []string{"network_id1", "network_id2"}, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - version: "1.25", - } - - report, err := client.NetworksPrune(context.Background(), listCase.filters) - assert.NoError(t, err) - assert.Len(t, report.NetworksDeleted, 2) - } -} diff --git a/client/network_remove_test.go b/client/network_remove_test.go deleted file mode 100644 index 2a7b9640c1..0000000000 --- a/client/network_remove_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestNetworkRemoveError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.NetworkRemove(context.Background(), "network_id") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestNetworkRemove(t *testing.T) { - expectedURL := "/networks/network_id" - - client := &Client{ - client: newMockClient(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) - } - if req.Method != "DELETE" { - return nil, fmt.Errorf("expected DELETE method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("body"))), - }, nil - }), - } - - err := client.NetworkRemove(context.Background(), "network_id") - if err != nil { - t.Fatal(err) - } -} diff --git a/client/node_inspect_test.go b/client/node_inspect_test.go deleted file mode 100644 index dca16a8cdc..0000000000 --- a/client/node_inspect_test.go +++ /dev/null @@ -1,65 +0,0 @@ -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 TestNodeInspectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, _, err := client.NodeInspectWithRaw(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestNodeInspectNodeNotFound(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusNotFound, "Server error")), - } - - _, _, err := client.NodeInspectWithRaw(context.Background(), "unknown") - if err == nil || !IsErrNodeNotFound(err) { - t.Fatalf("expected a nodeNotFoundError error, got %v", err) - } -} - -func TestNodeInspect(t *testing.T) { - expectedURL := "/nodes/node_id" - client := &Client{ - client: newMockClient(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.Node{ - ID: "node_id", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - nodeInspect, _, err := client.NodeInspectWithRaw(context.Background(), "node_id") - if err != nil { - t.Fatal(err) - } - if nodeInspect.ID != "node_id" { - t.Fatalf("expected `node_id`, got %s", nodeInspect.ID) - } -} diff --git a/client/node_list_test.go b/client/node_list_test.go deleted file mode 100644 index 0251b5cce4..0000000000 --- a/client/node_list_test.go +++ /dev/null @@ -1,94 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -func TestNodeListError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.NodeList(context.Background(), types.NodeListOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestNodeList(t *testing.T) { - expectedURL := "/nodes" - - filters := filters.NewArgs() - filters.Add("label", "label1") - filters.Add("label", "label2") - - listCases := []struct { - options types.NodeListOptions - expectedQueryParams map[string]string - }{ - { - options: types.NodeListOptions{}, - expectedQueryParams: map[string]string{ - "filters": "", - }, - }, - { - options: types.NodeListOptions{ - Filters: filters, - }, - expectedQueryParams: map[string]string{ - "filters": `{"label":{"label1":true,"label2":true}}`, - }, - }, - } - for _, listCase := range listCases { - client := &Client{ - client: newMockClient(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) - } - query := req.URL.Query() - for key, expected := range listCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - content, err := json.Marshal([]swarm.Node{ - { - ID: "node_id1", - }, - { - ID: "node_id2", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - nodes, err := client.NodeList(context.Background(), listCase.options) - if err != nil { - t.Fatal(err) - } - if len(nodes) != 2 { - t.Fatalf("expected 2 nodes, got %v", nodes) - } - } -} diff --git a/client/node_remove_test.go b/client/node_remove_test.go deleted file mode 100644 index f2f8adc4a3..0000000000 --- a/client/node_remove_test.go +++ /dev/null @@ -1,69 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - - "golang.org/x/net/context" -) - -func TestNodeRemoveError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.NodeRemove(context.Background(), "node_id", types.NodeRemoveOptions{Force: false}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestNodeRemove(t *testing.T) { - expectedURL := "/nodes/node_id" - - removeCases := []struct { - force bool - expectedForce string - }{ - { - expectedForce: "", - }, - { - force: true, - expectedForce: "1", - }, - } - - for _, removeCase := range removeCases { - client := &Client{ - client: newMockClient(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) - } - if req.Method != "DELETE" { - return nil, fmt.Errorf("expected DELETE method, got %s", req.Method) - } - force := req.URL.Query().Get("force") - if force != removeCase.expectedForce { - return nil, fmt.Errorf("force not set in URL query properly. expected '%s', got %s", removeCase.expectedForce, force) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("body"))), - }, nil - }), - } - - err := client.NodeRemove(context.Background(), "node_id", types.NodeRemoveOptions{Force: removeCase.force}) - if err != nil { - t.Fatal(err) - } - } -} diff --git a/client/node_update_test.go b/client/node_update_test.go deleted file mode 100644 index 613ff104eb..0000000000 --- a/client/node_update_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types/swarm" -) - -func TestNodeUpdateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.NodeUpdate(context.Background(), "node_id", swarm.Version{}, swarm.NodeSpec{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestNodeUpdate(t *testing.T) { - expectedURL := "/nodes/node_id/update" - - client := &Client{ - client: newMockClient(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) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("body"))), - }, nil - }), - } - - err := client.NodeUpdate(context.Background(), "node_id", swarm.Version{}, swarm.NodeSpec{}) - if err != nil { - t.Fatal(err) - } -} diff --git a/client/plugin_disable_test.go b/client/plugin_disable_test.go deleted file mode 100644 index a4de45be2d..0000000000 --- a/client/plugin_disable_test.go +++ /dev/null @@ -1,48 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestPluginDisableError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.PluginDisable(context.Background(), "plugin_name", types.PluginDisableOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestPluginDisable(t *testing.T) { - expectedURL := "/plugins/plugin_name/disable" - - client := &Client{ - client: newMockClient(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) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.PluginDisable(context.Background(), "plugin_name", types.PluginDisableOptions{}) - if err != nil { - t.Fatal(err) - } -} diff --git a/client/plugin_enable_test.go b/client/plugin_enable_test.go deleted file mode 100644 index b27681348f..0000000000 --- a/client/plugin_enable_test.go +++ /dev/null @@ -1,48 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestPluginEnableError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.PluginEnable(context.Background(), "plugin_name", types.PluginEnableOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestPluginEnable(t *testing.T) { - expectedURL := "/plugins/plugin_name/enable" - - client := &Client{ - client: newMockClient(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) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.PluginEnable(context.Background(), "plugin_name", types.PluginEnableOptions{}) - if err != nil { - t.Fatal(err) - } -} diff --git a/client/plugin_inspect_test.go b/client/plugin_inspect_test.go deleted file mode 100644 index fae407eb9b..0000000000 --- a/client/plugin_inspect_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestPluginInspectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, _, err := client.PluginInspectWithRaw(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestPluginInspect(t *testing.T) { - expectedURL := "/plugins/plugin_name" - client := &Client{ - client: newMockClient(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(types.Plugin{ - ID: "plugin_id", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - pluginInspect, _, err := client.PluginInspectWithRaw(context.Background(), "plugin_name") - if err != nil { - t.Fatal(err) - } - if pluginInspect.ID != "plugin_id" { - t.Fatalf("expected `plugin_id`, got %s", pluginInspect.ID) - } -} diff --git a/client/plugin_list_test.go b/client/plugin_list_test.go deleted file mode 100644 index 6887079b42..0000000000 --- a/client/plugin_list_test.go +++ /dev/null @@ -1,107 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "golang.org/x/net/context" -) - -func TestPluginListError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.PluginList(context.Background(), filters.NewArgs()) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestPluginList(t *testing.T) { - expectedURL := "/plugins" - - enabledFilters := filters.NewArgs() - enabledFilters.Add("enabled", "true") - - capabilityFilters := filters.NewArgs() - capabilityFilters.Add("capability", "volumedriver") - capabilityFilters.Add("capability", "authz") - - listCases := []struct { - filters filters.Args - expectedQueryParams map[string]string - }{ - { - filters: filters.NewArgs(), - expectedQueryParams: map[string]string{ - "all": "", - "filter": "", - "filters": "", - }, - }, - { - filters: enabledFilters, - expectedQueryParams: map[string]string{ - "all": "", - "filter": "", - "filters": `{"enabled":{"true":true}}`, - }, - }, - { - filters: capabilityFilters, - expectedQueryParams: map[string]string{ - "all": "", - "filter": "", - "filters": `{"capability":{"authz":true,"volumedriver":true}}`, - }, - }, - } - - for _, listCase := range listCases { - client := &Client{ - client: newMockClient(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) - } - query := req.URL.Query() - for key, expected := range listCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - content, err := json.Marshal([]*types.Plugin{ - { - ID: "plugin_id1", - }, - { - ID: "plugin_id2", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - plugins, err := client.PluginList(context.Background(), listCase.filters) - if err != nil { - t.Fatal(err) - } - if len(plugins) != 2 { - t.Fatalf("expected 2 plugins, got %v", plugins) - } - } -} diff --git a/client/plugin_push_test.go b/client/plugin_push_test.go deleted file mode 100644 index d9f70cdff8..0000000000 --- a/client/plugin_push_test.go +++ /dev/null @@ -1,51 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestPluginPushError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.PluginPush(context.Background(), "plugin_name", "") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestPluginPush(t *testing.T) { - expectedURL := "/plugins/plugin_name" - - client := &Client{ - client: newMockClient(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) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - auth := req.Header.Get("X-Registry-Auth") - if auth != "authtoken" { - return nil, fmt.Errorf("Invalid auth header : expected 'authtoken', got %s", auth) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - _, err := client.PluginPush(context.Background(), "plugin_name", "authtoken") - if err != nil { - t.Fatal(err) - } -} diff --git a/client/plugin_remove_test.go b/client/plugin_remove_test.go deleted file mode 100644 index b2d515793a..0000000000 --- a/client/plugin_remove_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - - "golang.org/x/net/context" -) - -func TestPluginRemoveError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.PluginRemove(context.Background(), "plugin_name", types.PluginRemoveOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestPluginRemove(t *testing.T) { - expectedURL := "/plugins/plugin_name" - - client := &Client{ - client: newMockClient(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) - } - if req.Method != "DELETE" { - return nil, fmt.Errorf("expected DELETE method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.PluginRemove(context.Background(), "plugin_name", types.PluginRemoveOptions{}) - if err != nil { - t.Fatal(err) - } -} diff --git a/client/plugin_set_test.go b/client/plugin_set_test.go deleted file mode 100644 index 2450254463..0000000000 --- a/client/plugin_set_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestPluginSetError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.PluginSet(context.Background(), "plugin_name", []string{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestPluginSet(t *testing.T) { - expectedURL := "/plugins/plugin_name/set" - - client := &Client{ - client: newMockClient(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) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.PluginSet(context.Background(), "plugin_name", []string{"arg1"}) - if err != nil { - t.Fatal(err) - } -} diff --git a/client/request_test.go b/client/request_test.go deleted file mode 100644 index 63908aec4b..0000000000 --- a/client/request_test.go +++ /dev/null @@ -1,92 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// TestSetHostHeader should set fake host for local communications, set real host -// for normal communications. -func TestSetHostHeader(t *testing.T) { - testURL := "/test" - testCases := []struct { - host string - expectedHost string - expectedURLHost string - }{ - { - "unix:///var/run/docker.sock", - "docker", - "/var/run/docker.sock", - }, - { - "npipe:////./pipe/docker_engine", - "docker", - "//./pipe/docker_engine", - }, - { - "tcp://0.0.0.0:4243", - "", - "0.0.0.0:4243", - }, - { - "tcp://localhost:4243", - "", - "localhost:4243", - }, - } - - for c, test := range testCases { - proto, addr, basePath, err := ParseHost(test.host) - if err != nil { - t.Fatal(err) - } - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, testURL) { - return nil, fmt.Errorf("Test Case #%d: Expected URL %q, got %q", c, testURL, req.URL) - } - if req.Host != test.expectedHost { - return nil, fmt.Errorf("Test Case #%d: Expected host %q, got %q", c, test.expectedHost, req.Host) - } - if req.URL.Host != test.expectedURLHost { - return nil, fmt.Errorf("Test Case #%d: Expected URL host %q, got %q", c, test.expectedURLHost, req.URL.Host) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(([]byte("")))), - }, nil - }), - - proto: proto, - addr: addr, - basePath: basePath, - } - - _, err = client.sendRequest(context.Background(), "GET", testURL, nil, nil, nil) - if err != nil { - t.Fatal(err) - } - } -} - -// TestPlainTextError tests the server returning an error in plain text for -// backwards compatibility with API versions <1.24. All other tests use -// errors returned as JSON -func TestPlainTextError(t *testing.T) { - client := &Client{ - client: newMockClient(plainTextErrorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerList(context.Background(), types.ContainerListOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} diff --git a/client/secret_create_test.go b/client/secret_create_test.go deleted file mode 100644 index cb378c77ff..0000000000 --- a/client/secret_create_test.go +++ /dev/null @@ -1,57 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -func TestSecretCreateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.SecretCreate(context.Background(), swarm.SecretSpec{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestSecretCreate(t *testing.T) { - expectedURL := "/secrets/create" - client := &Client{ - client: newMockClient(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) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - b, err := json.Marshal(types.SecretCreateResponse{ - ID: "test_secret", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusCreated, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - r, err := client.SecretCreate(context.Background(), swarm.SecretSpec{}) - if err != nil { - t.Fatal(err) - } - if r.ID != "test_secret" { - t.Fatalf("expected `test_secret`, got %s", r.ID) - } -} diff --git a/client/secret_inspect_test.go b/client/secret_inspect_test.go deleted file mode 100644 index 0142a3ca9f..0000000000 --- a/client/secret_inspect_test.go +++ /dev/null @@ -1,65 +0,0 @@ -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 TestSecretInspectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, _, err := client.SecretInspectWithRaw(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestSecretInspectSecretNotFound(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusNotFound, "Server error")), - } - - _, _, err := client.SecretInspectWithRaw(context.Background(), "unknown") - if err == nil || !IsErrSecretNotFound(err) { - t.Fatalf("expected a secretNotFoundError error, got %v", err) - } -} - -func TestSecretInspect(t *testing.T) { - expectedURL := "/secrets/secret_id" - client := &Client{ - client: newMockClient(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.Secret{ - ID: "secret_id", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - secretInspect, _, err := client.SecretInspectWithRaw(context.Background(), "secret_id") - if err != nil { - t.Fatal(err) - } - if secretInspect.ID != "secret_id" { - t.Fatalf("expected `secret_id`, got %s", secretInspect.ID) - } -} diff --git a/client/secret_list_test.go b/client/secret_list_test.go deleted file mode 100644 index 1ac11cddb3..0000000000 --- a/client/secret_list_test.go +++ /dev/null @@ -1,94 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -func TestSecretListError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.SecretList(context.Background(), types.SecretListOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestSecretList(t *testing.T) { - expectedURL := "/secrets" - - filters := filters.NewArgs() - filters.Add("label", "label1") - filters.Add("label", "label2") - - listCases := []struct { - options types.SecretListOptions - expectedQueryParams map[string]string - }{ - { - options: types.SecretListOptions{}, - expectedQueryParams: map[string]string{ - "filters": "", - }, - }, - { - options: types.SecretListOptions{ - Filters: filters, - }, - expectedQueryParams: map[string]string{ - "filters": `{"label":{"label1":true,"label2":true}}`, - }, - }, - } - for _, listCase := range listCases { - client := &Client{ - client: newMockClient(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) - } - query := req.URL.Query() - for key, expected := range listCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - content, err := json.Marshal([]swarm.Secret{ - { - ID: "secret_id1", - }, - { - ID: "secret_id2", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - secrets, err := client.SecretList(context.Background(), listCase.options) - if err != nil { - t.Fatal(err) - } - if len(secrets) != 2 { - t.Fatalf("expected 2 secrets, got %v", secrets) - } - } -} diff --git a/client/secret_remove_test.go b/client/secret_remove_test.go deleted file mode 100644 index f269f787d2..0000000000 --- a/client/secret_remove_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestSecretRemoveError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.SecretRemove(context.Background(), "secret_id") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestSecretRemove(t *testing.T) { - expectedURL := "/secrets/secret_id" - - client := &Client{ - client: newMockClient(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) - } - if req.Method != "DELETE" { - return nil, fmt.Errorf("expected DELETE method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("body"))), - }, nil - }), - } - - err := client.SecretRemove(context.Background(), "secret_id") - if err != nil { - t.Fatal(err) - } -} diff --git a/client/secret_update_test.go b/client/secret_update_test.go deleted file mode 100644 index c620985bd5..0000000000 --- a/client/secret_update_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types/swarm" -) - -func TestSecretUpdateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.SecretUpdate(context.Background(), "secret_id", swarm.Version{}, swarm.SecretSpec{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestSecretUpdate(t *testing.T) { - expectedURL := "/secrets/secret_id/update" - - client := &Client{ - client: newMockClient(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) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("body"))), - }, nil - }), - } - - err := client.SecretUpdate(context.Background(), "secret_id", swarm.Version{}, swarm.SecretSpec{}) - if err != nil { - t.Fatal(err) - } -} diff --git a/client/service_create_test.go b/client/service_create_test.go deleted file mode 100644 index 1e07382870..0000000000 --- a/client/service_create_test.go +++ /dev/null @@ -1,57 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -func TestServiceCreateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ServiceCreate(context.Background(), swarm.ServiceSpec{}, types.ServiceCreateOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestServiceCreate(t *testing.T) { - expectedURL := "/services/create" - client := &Client{ - client: newMockClient(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) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - b, err := json.Marshal(types.ServiceCreateResponse{ - ID: "service_id", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - r, err := client.ServiceCreate(context.Background(), swarm.ServiceSpec{}, types.ServiceCreateOptions{}) - if err != nil { - t.Fatal(err) - } - if r.ID != "service_id" { - t.Fatalf("expected `service_id`, got %s", r.ID) - } -} diff --git a/client/service_inspect_test.go b/client/service_inspect_test.go deleted file mode 100644 index d53f583e90..0000000000 --- a/client/service_inspect_test.go +++ /dev/null @@ -1,66 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -func TestServiceInspectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, _, err := client.ServiceInspectWithRaw(context.Background(), "nothing", types.ServiceInspectOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestServiceInspectServiceNotFound(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusNotFound, "Server error")), - } - - _, _, err := client.ServiceInspectWithRaw(context.Background(), "unknown", types.ServiceInspectOptions{}) - if err == nil || !IsErrServiceNotFound(err) { - t.Fatalf("expected a serviceNotFoundError error, got %v", err) - } -} - -func TestServiceInspect(t *testing.T) { - expectedURL := "/services/service_id" - client := &Client{ - client: newMockClient(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.Service{ - ID: "service_id", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - serviceInspect, _, err := client.ServiceInspectWithRaw(context.Background(), "service_id", types.ServiceInspectOptions{}) - if err != nil { - t.Fatal(err) - } - if serviceInspect.ID != "service_id" { - t.Fatalf("expected `service_id`, got %s", serviceInspect.ID) - } -} diff --git a/client/service_list_test.go b/client/service_list_test.go deleted file mode 100644 index 213981ef70..0000000000 --- a/client/service_list_test.go +++ /dev/null @@ -1,94 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -func TestServiceListError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.ServiceList(context.Background(), types.ServiceListOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestServiceList(t *testing.T) { - expectedURL := "/services" - - filters := filters.NewArgs() - filters.Add("label", "label1") - filters.Add("label", "label2") - - listCases := []struct { - options types.ServiceListOptions - expectedQueryParams map[string]string - }{ - { - options: types.ServiceListOptions{}, - expectedQueryParams: map[string]string{ - "filters": "", - }, - }, - { - options: types.ServiceListOptions{ - Filters: filters, - }, - expectedQueryParams: map[string]string{ - "filters": `{"label":{"label1":true,"label2":true}}`, - }, - }, - } - for _, listCase := range listCases { - client := &Client{ - client: newMockClient(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) - } - query := req.URL.Query() - for key, expected := range listCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - content, err := json.Marshal([]swarm.Service{ - { - ID: "service_id1", - }, - { - ID: "service_id2", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - services, err := client.ServiceList(context.Background(), listCase.options) - if err != nil { - t.Fatal(err) - } - if len(services) != 2 { - t.Fatalf("expected 2 services, got %v", services) - } - } -} diff --git a/client/service_logs_test.go b/client/service_logs_test.go deleted file mode 100644 index a6d002ba75..0000000000 --- a/client/service_logs_test.go +++ /dev/null @@ -1,133 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io" - "io/ioutil" - "log" - "net/http" - "os" - "strings" - "testing" - "time" - - "github.com/docker/docker/api/types" - - "golang.org/x/net/context" -) - -func TestServiceLogsError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ServiceLogs(context.Background(), "service_id", types.ContainerLogsOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } - _, err = client.ServiceLogs(context.Background(), "service_id", types.ContainerLogsOptions{ - Since: "2006-01-02TZ", - }) - if err == nil || !strings.Contains(err.Error(), `parsing time "2006-01-02TZ"`) { - t.Fatalf("expected a 'parsing time' error, got %v", err) - } -} - -func TestServiceLogs(t *testing.T) { - expectedURL := "/services/service_id/logs" - cases := []struct { - options types.ContainerLogsOptions - expectedQueryParams map[string]string - }{ - { - expectedQueryParams: map[string]string{ - "tail": "", - }, - }, - { - options: types.ContainerLogsOptions{ - Tail: "any", - }, - expectedQueryParams: map[string]string{ - "tail": "any", - }, - }, - { - options: types.ContainerLogsOptions{ - ShowStdout: true, - ShowStderr: true, - Timestamps: true, - Details: true, - Follow: true, - }, - expectedQueryParams: map[string]string{ - "tail": "", - "stdout": "1", - "stderr": "1", - "timestamps": "1", - "details": "1", - "follow": "1", - }, - }, - { - options: types.ContainerLogsOptions{ - // An complete invalid date, timestamp or go duration will be - // passed as is - Since: "invalid but valid", - }, - expectedQueryParams: map[string]string{ - "tail": "", - "since": "invalid but valid", - }, - }, - } - for _, logCase := range cases { - client := &Client{ - client: newMockClient(func(r *http.Request) (*http.Response, error) { - if !strings.HasPrefix(r.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL) - } - // Check query parameters - query := r.URL.Query() - for key, expected := range logCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("response"))), - }, nil - }), - } - body, err := client.ServiceLogs(context.Background(), "service_id", logCase.options) - if err != nil { - t.Fatal(err) - } - defer body.Close() - content, err := ioutil.ReadAll(body) - if err != nil { - t.Fatal(err) - } - if string(content) != "response" { - t.Fatalf("expected response to contain 'response', got %s", string(content)) - } - } -} - -func ExampleClient_ServiceLogs_withTimeout() { - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - - client, _ := NewEnvClient() - reader, err := client.ServiceLogs(ctx, "service_id", types.ContainerLogsOptions{}) - if err != nil { - log.Fatal(err) - } - - _, err = io.Copy(os.Stdout, reader) - if err != nil && err != io.EOF { - log.Fatal(err) - } -} diff --git a/client/service_remove_test.go b/client/service_remove_test.go deleted file mode 100644 index 8e2ac259c1..0000000000 --- a/client/service_remove_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestServiceRemoveError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.ServiceRemove(context.Background(), "service_id") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestServiceRemove(t *testing.T) { - expectedURL := "/services/service_id" - - client := &Client{ - client: newMockClient(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) - } - if req.Method != "DELETE" { - return nil, fmt.Errorf("expected DELETE method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("body"))), - }, nil - }), - } - - err := client.ServiceRemove(context.Background(), "service_id") - if err != nil { - t.Fatal(err) - } -} diff --git a/client/service_update_test.go b/client/service_update_test.go deleted file mode 100644 index 76bea176bf..0000000000 --- a/client/service_update_test.go +++ /dev/null @@ -1,77 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/swarm" -) - -func TestServiceUpdateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.ServiceUpdate(context.Background(), "service_id", swarm.Version{}, swarm.ServiceSpec{}, types.ServiceUpdateOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestServiceUpdate(t *testing.T) { - expectedURL := "/services/service_id/update" - - updateCases := []struct { - swarmVersion swarm.Version - expectedVersion string - }{ - { - expectedVersion: "0", - }, - { - swarmVersion: swarm.Version{ - Index: 0, - }, - expectedVersion: "0", - }, - { - swarmVersion: swarm.Version{ - Index: 10, - }, - expectedVersion: "10", - }, - } - - for _, updateCase := range updateCases { - client := &Client{ - client: newMockClient(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) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - version := req.URL.Query().Get("version") - if version != updateCase.expectedVersion { - return nil, fmt.Errorf("version not set in URL query properly, expected '%s', got %s", updateCase.expectedVersion, version) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("{}"))), - }, nil - }), - } - - _, err := client.ServiceUpdate(context.Background(), "service_id", updateCase.swarmVersion, swarm.ServiceSpec{}, types.ServiceUpdateOptions{}) - if err != nil { - t.Fatal(err) - } - } -} diff --git a/client/swarm_init_test.go b/client/swarm_init_test.go deleted file mode 100644 index 811155aff4..0000000000 --- a/client/swarm_init_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types/swarm" -) - -func TestSwarmInitError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.SwarmInit(context.Background(), swarm.InitRequest{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestSwarmInit(t *testing.T) { - expectedURL := "/swarm/init" - - client := &Client{ - client: newMockClient(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) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(`"body"`))), - }, nil - }), - } - - resp, err := client.SwarmInit(context.Background(), swarm.InitRequest{ - ListenAddr: "0.0.0.0:2377", - }) - if err != nil { - t.Fatal(err) - } - if resp != "body" { - t.Fatalf("Expected 'body', got %s", resp) - } -} diff --git a/client/swarm_inspect_test.go b/client/swarm_inspect_test.go deleted file mode 100644 index 6432d172b4..0000000000 --- a/client/swarm_inspect_test.go +++ /dev/null @@ -1,56 +0,0 @@ -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 TestSwarmInspectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.SwarmInspect(context.Background()) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestSwarmInspect(t *testing.T) { - expectedURL := "/swarm" - client := &Client{ - client: newMockClient(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.Swarm{ - ClusterInfo: swarm.ClusterInfo{ - ID: "swarm_id", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - swarmInspect, err := client.SwarmInspect(context.Background()) - if err != nil { - t.Fatal(err) - } - if swarmInspect.ID != "swarm_id" { - t.Fatalf("expected `swarm_id`, got %s", swarmInspect.ID) - } -} diff --git a/client/swarm_join_test.go b/client/swarm_join_test.go deleted file mode 100644 index 31ef2a76ee..0000000000 --- a/client/swarm_join_test.go +++ /dev/null @@ -1,51 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types/swarm" -) - -func TestSwarmJoinError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.SwarmJoin(context.Background(), swarm.JoinRequest{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestSwarmJoin(t *testing.T) { - expectedURL := "/swarm/join" - - client := &Client{ - client: newMockClient(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) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.SwarmJoin(context.Background(), swarm.JoinRequest{ - ListenAddr: "0.0.0.0:2377", - }) - if err != nil { - t.Fatal(err) - } -} diff --git a/client/swarm_leave_test.go b/client/swarm_leave_test.go deleted file mode 100644 index c96dac8120..0000000000 --- a/client/swarm_leave_test.go +++ /dev/null @@ -1,66 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestSwarmLeaveError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.SwarmLeave(context.Background(), false) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestSwarmLeave(t *testing.T) { - expectedURL := "/swarm/leave" - - leaveCases := []struct { - force bool - expectedForce string - }{ - { - expectedForce: "", - }, - { - force: true, - expectedForce: "1", - }, - } - - for _, leaveCase := range leaveCases { - client := &Client{ - client: newMockClient(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) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - force := req.URL.Query().Get("force") - if force != leaveCase.expectedForce { - return nil, fmt.Errorf("force not set in URL query properly. expected '%s', got %s", leaveCase.expectedForce, force) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.SwarmLeave(context.Background(), leaveCase.force) - if err != nil { - t.Fatal(err) - } - } -} diff --git a/client/swarm_update_test.go b/client/swarm_update_test.go deleted file mode 100644 index 3b23db078f..0000000000 --- a/client/swarm_update_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types/swarm" -) - -func TestSwarmUpdateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.SwarmUpdate(context.Background(), swarm.Version{}, swarm.Spec{}, swarm.UpdateFlags{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestSwarmUpdate(t *testing.T) { - expectedURL := "/swarm/update" - - client := &Client{ - client: newMockClient(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) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.SwarmUpdate(context.Background(), swarm.Version{}, swarm.Spec{}, swarm.UpdateFlags{}) - if err != nil { - t.Fatal(err) - } -} diff --git a/client/task_inspect_test.go b/client/task_inspect_test.go deleted file mode 100644 index 148cdad3a7..0000000000 --- a/client/task_inspect_test.go +++ /dev/null @@ -1,54 +0,0 @@ -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{ - client: newMockClient(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{ - client: newMockClient(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) - } -} diff --git a/client/task_list_test.go b/client/task_list_test.go deleted file mode 100644 index 2a9a4c4346..0000000000 --- a/client/task_list_test.go +++ /dev/null @@ -1,94 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -func TestTaskListError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.TaskList(context.Background(), types.TaskListOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestTaskList(t *testing.T) { - expectedURL := "/tasks" - - filters := filters.NewArgs() - filters.Add("label", "label1") - filters.Add("label", "label2") - - listCases := []struct { - options types.TaskListOptions - expectedQueryParams map[string]string - }{ - { - options: types.TaskListOptions{}, - expectedQueryParams: map[string]string{ - "filters": "", - }, - }, - { - options: types.TaskListOptions{ - Filters: filters, - }, - expectedQueryParams: map[string]string{ - "filters": `{"label":{"label1":true,"label2":true}}`, - }, - }, - } - for _, listCase := range listCases { - client := &Client{ - client: newMockClient(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) - } - query := req.URL.Query() - for key, expected := range listCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - content, err := json.Marshal([]swarm.Task{ - { - ID: "task_id1", - }, - { - ID: "task_id2", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - tasks, err := client.TaskList(context.Background(), listCase.options) - if err != nil { - t.Fatal(err) - } - if len(tasks) != 2 { - t.Fatalf("expected 2 tasks, got %v", tasks) - } - } -} diff --git a/client/testdata/ca.pem b/client/testdata/ca.pem deleted file mode 100644 index ad14d47065..0000000000 --- a/client/testdata/ca.pem +++ /dev/null @@ -1,18 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIC0jCCAbqgAwIBAgIRAILlP5WWLaHkQ/m2ASHP7SowDQYJKoZIhvcNAQELBQAw -EjEQMA4GA1UEChMHdmluY2VudDAeFw0xNjAzMjQxMDE5MDBaFw0xOTAzMDkxMDE5 -MDBaMBIxEDAOBgNVBAoTB3ZpbmNlbnQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw -ggEKAoIBAQD0yZPKAGncoaxaU/QW9tWEHbrvDoGVF/65L8Si/jBrlAgLjhmmV1di -vKG9QPzuU8snxHro3/uCwyA6kTqw0U8bGwHxJq2Bpa6JBYj8N2jMJ+M+sjXgSo2t -E0zIzjTW2Pir3C8qwfrVL6NFp9xClwMD23SFZ0UsEH36NkfyrKBVeM8IOjJd4Wjs -xIcuvF3BTVkji84IJBW2JIKf9ZrzJwUlSCPgptRp4Evdbyp5d+UPxtwxD7qjW4lM -yQQ8vfcC4lKkVx5s/RNJ4fzd5uEgLdEbZ20qt7Zt/bLcxFHpUhH2teA0QjmrOWFh -gbL83s95/+hbSVhsO4hoFW7vTeiCCY4xAgMBAAGjIzAhMA4GA1UdDwEB/wQEAwIC -rDAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQBY51RHajuDuhO2 -tcm26jeNROzfffnjhvbOVPjSEdo9vI3JpMU/RuQw+nbNcLwJrdjL6UH7tD/36Y+q -NXH+xSIjWFH0zXGxrIUsVrvt6f8CbOvw7vD+gygOG+849PDQMbL6czP8rvXY7vZV -9pdpQfrENk4b5kePRW/6HaGSTvtgN7XOrYD9fp3pm/G534T2e3IxgYMRNwdB9Ul9 -bLwMqQqf4eiqqMs6x4IVmZUkGVMKiFKcvkNg9a+Ozx5pMizHeAezWMcZ5V+QJZVT -8lElSCKZ2Yy2xkcl7aeQMLwcAeZwfTp+Yu9dVzlqXiiBTLd1+LtAQCuKHzmw4Q8k -EvD5m49l ------END CERTIFICATE----- diff --git a/client/testdata/cert.pem b/client/testdata/cert.pem deleted file mode 100644 index 9000ffb32b..0000000000 --- a/client/testdata/cert.pem +++ /dev/null @@ -1,18 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIC8DCCAdigAwIBAgIRAJAS1glgcke4q7eCaretwgUwDQYJKoZIhvcNAQELBQAw -EjEQMA4GA1UEChMHdmluY2VudDAeFw0xNjAzMjQxMDE5MDBaFw0xOTAzMDkxMDE5 -MDBaMB4xHDAaBgNVBAoME3ZpbmNlbnQuPGJvb3RzdHJhcD4wggEiMA0GCSqGSIb3 -DQEBAQUAA4IBDwAwggEKAoIBAQClpvG442dGEvrRgmCrqY4kBml1LVlw2Y7ZDn6B -TKa52+MuGDmfXbO1UhclNqTXjLgAwKjPz/OvnPRxNEUoQEDbBd+Xev7rxTY5TvYI -27YH3fMH2LL2j62jum649abfhZ6ekD5eD8tCn3mnrEOgqRIlK7efPIVixq/ZqU1H -7ez0ggB7dmWHlhnUaxyQOCSnAX/7nKYQXqZgVvGhDeR2jp7GcnhbK/qPrZ/mOm83 -2IjCeYN145opYlzTSp64GYIZz7uqMNcnDKK37ZbS8MYcTjrRaHEiqZVVdIC+ghbx -qYqzbZRVfgztI9jwmifn0mYrN4yt+nhNYwBcRJ4Pv3uLFbo7AgMBAAGjNTAzMA4G -A1UdDwEB/wQEAwIHgDATBgNVHSUEDDAKBggrBgEFBQcDAjAMBgNVHRMBAf8EAjAA -MA0GCSqGSIb3DQEBCwUAA4IBAQDg1r7nksjYgDFYEcBbrRrRHddIoK+RVmSBTTrq -8giC77m0srKdh9XTVWK1PUbGfODV1oD8m9QhPE8zPDyYQ8jeXNRSU5wXdkrTRmmY -w/T3SREqmE7CObMtusokHidjYFuqqCR07sJzqBKRlzr3o0EGe3tuEhUlF5ARY028 -eipaDcVlT5ChGcDa6LeJ4e05u4cVap0dd6Rp1w3Rx1AYAecdgtgBMnw1iWdl/nrC -sp26ZXNaAhFOUovlY9VY257AMd9hQV7WvAK4yNEHcckVu3uXTBmDgNSOPtl0QLsL -Kjlj75ksCx8nCln/hCut/0+kGTsGZqdV5c6ktgcGYRir/5Hs ------END CERTIFICATE----- diff --git a/client/testdata/key.pem b/client/testdata/key.pem deleted file mode 100644 index c0869dfc1a..0000000000 --- a/client/testdata/key.pem +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEowIBAAKCAQEApabxuONnRhL60YJgq6mOJAZpdS1ZcNmO2Q5+gUymudvjLhg5 -n12ztVIXJTak14y4AMCoz8/zr5z0cTRFKEBA2wXfl3r+68U2OU72CNu2B93zB9iy -9o+to7puuPWm34WenpA+Xg/LQp95p6xDoKkSJSu3nzyFYsav2alNR+3s9IIAe3Zl -h5YZ1GsckDgkpwF/+5ymEF6mYFbxoQ3kdo6exnJ4Wyv6j62f5jpvN9iIwnmDdeOa -KWJc00qeuBmCGc+7qjDXJwyit+2W0vDGHE460WhxIqmVVXSAvoIW8amKs22UVX4M -7SPY8Jon59JmKzeMrfp4TWMAXESeD797ixW6OwIDAQABAoIBAHfyAAleL8NfrtnR -S+pApbmUIvxD0AWUooispBE/zWG6xC72P5MTqDJctIGvpYCmVf3Fgvamns7EGYN2 -07Sngc6V3Ca1WqyhaffpIuGbJZ1gqr89u6gotRRexBmNVj13ZTlvPJmjWgxtqQsu -AvHsOkVL+HOGwRaaw24Z1umEcBVCepl7PGTqsLeJUtBUZBiqdJTu4JYLAB6BggBI -OxhHoTWvlNWwzezo2C/IXkXcXD/tp3i5vTn5rAXHSMQkdMAUh7/xJ73Fl36gxZhp -W7NoPKaS9qNh8jhs6p54S7tInb6+mrKtvRFKl5XAR3istXrXteT5UaukpuBbQ/5d -qf4BXuECgYEAzoOKxMee5tG/G9iC6ImNq5xGAZm0OnmteNgIEQj49If1Q68av525 -FioqdC9zV+blfHQqXEIUeum4JAou4xqmB8Lw2H0lYwOJ1IkpUy3QJjU1IrI+U5Qy -ryZuA9cxSTLf1AJFbROsoZDpjaBh0uUQkD/4PHpwXMgHu/3CaJ4nTEkCgYEAzVjE -VWgczWJGyRxmHSeR51ft1jrlChZHEd3HwgLfo854JIj+MGUH4KPLSMIkYNuyiwNQ -W7zdXCB47U8afSL/lPTv1M5+ZsWY6sZAT6gtp/IeU0Va943h9cj10fAOBJaz1H6M -jnZS4jjWhVInE7wpCDVCwDRoHHJ84kb6JeflamMCgYBDQDcKie9HP3q6uLE4xMKr -5gIuNz2n5UQGnGNUGNXp2/SVDArr55MEksqsd19aesi01KeOz74XoNDke6R1NJJo -6KTB+08XhWl3GwuoGL02FBGvsNf3I8W1oBAnlAZqzfRx+CNfuA55ttU318jDgvD3 -6L0QBNdef411PNf4dbhacQKBgAd/e0PHFm4lbYJAaDYeUMSKwGN3KQ/SOmwblgSu -iC36BwcGfYmU1tHMCUsx05Q50W4kA9Ylskt/4AqCPexdz8lHnE4/7/uesXO5I3YF -JQ2h2Jufx6+MXbjUyq0Mv+ZI/m3+5PD6vxIFk0ew9T5SO4lSMIrGHxsSzx6QCuhB -bG4TAoGBAJ5PWG7d2CyCjLtfF8J4NxykRvIQ8l/3kDvDdNrXiXbgonojo2lgRYaM -5LoK9ApN8KHdedpTRipBaDA22Sp5SjMcUE7A6q42PJCL9r+BRYF0foFQx/rqpCff -pVWKgwIPoKnfxDqN1RUgyFcx1jbA3XVJZCuT+wbMuDQ9nlvulD1W ------END RSA PRIVATE KEY----- diff --git a/client/volume_create_test.go b/client/volume_create_test.go deleted file mode 100644 index 9f1b2540b5..0000000000 --- a/client/volume_create_test.go +++ /dev/null @@ -1,75 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - volumetypes "github.com/docker/docker/api/types/volume" - "golang.org/x/net/context" -) - -func TestVolumeCreateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.VolumeCreate(context.Background(), volumetypes.VolumesCreateBody{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestVolumeCreate(t *testing.T) { - expectedURL := "/volumes/create" - - client := &Client{ - client: newMockClient(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) - } - - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - - content, err := json.Marshal(types.Volume{ - Name: "volume", - Driver: "local", - Mountpoint: "mountpoint", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - volume, err := client.VolumeCreate(context.Background(), volumetypes.VolumesCreateBody{ - Name: "myvolume", - Driver: "mydriver", - DriverOpts: map[string]string{ - "opt-key": "opt-value", - }, - }) - if err != nil { - t.Fatal(err) - } - if volume.Name != "volume" { - t.Fatalf("expected volume.Name to be 'volume', got %s", volume.Name) - } - if volume.Driver != "local" { - t.Fatalf("expected volume.Driver to be 'local', got %s", volume.Driver) - } - if volume.Mountpoint != "mountpoint" { - t.Fatalf("expected volume.Mountpoint to be 'mountpoint', got %s", volume.Mountpoint) - } -} diff --git a/client/volume_inspect_test.go b/client/volume_inspect_test.go deleted file mode 100644 index 0d1d118828..0000000000 --- a/client/volume_inspect_test.go +++ /dev/null @@ -1,76 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestVolumeInspectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.VolumeInspect(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestVolumeInspectNotFound(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusNotFound, "Server error")), - } - - _, err := client.VolumeInspect(context.Background(), "unknown") - if err == nil || !IsErrVolumeNotFound(err) { - t.Fatalf("expected a volumeNotFound error, got %v", err) - } -} - -func TestVolumeInspect(t *testing.T) { - expectedURL := "/volumes/volume_id" - client := &Client{ - client: newMockClient(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) - } - if req.Method != "GET" { - return nil, fmt.Errorf("expected GET method, got %s", req.Method) - } - content, err := json.Marshal(types.Volume{ - Name: "name", - Driver: "driver", - Mountpoint: "mountpoint", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - v, err := client.VolumeInspect(context.Background(), "volume_id") - if err != nil { - t.Fatal(err) - } - if v.Name != "name" { - t.Fatalf("expected `name`, got %s", v.Name) - } - if v.Driver != "driver" { - t.Fatalf("expected `driver`, got %s", v.Driver) - } - if v.Mountpoint != "mountpoint" { - t.Fatalf("expected `mountpoint`, got %s", v.Mountpoint) - } -} diff --git a/client/volume_list_test.go b/client/volume_list_test.go deleted file mode 100644 index f29639be23..0000000000 --- a/client/volume_list_test.go +++ /dev/null @@ -1,98 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - volumetypes "github.com/docker/docker/api/types/volume" - "golang.org/x/net/context" -) - -func TestVolumeListError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.VolumeList(context.Background(), filters.NewArgs()) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestVolumeList(t *testing.T) { - expectedURL := "/volumes" - - noDanglingFilters := filters.NewArgs() - noDanglingFilters.Add("dangling", "false") - - danglingFilters := filters.NewArgs() - danglingFilters.Add("dangling", "true") - - labelFilters := filters.NewArgs() - labelFilters.Add("label", "label1") - labelFilters.Add("label", "label2") - - listCases := []struct { - filters filters.Args - expectedFilters string - }{ - { - filters: filters.NewArgs(), - expectedFilters: "", - }, { - filters: noDanglingFilters, - expectedFilters: `{"dangling":{"false":true}}`, - }, { - filters: danglingFilters, - expectedFilters: `{"dangling":{"true":true}}`, - }, { - filters: labelFilters, - expectedFilters: `{"label":{"label1":true,"label2":true}}`, - }, - } - - for _, listCase := range listCases { - client := &Client{ - client: newMockClient(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) - } - query := req.URL.Query() - actualFilters := query.Get("filters") - if actualFilters != listCase.expectedFilters { - return nil, fmt.Errorf("filters not set in URL query properly. Expected '%s', got %s", listCase.expectedFilters, actualFilters) - } - content, err := json.Marshal(volumetypes.VolumesListOKBody{ - Volumes: []*types.Volume{ - { - Name: "volume", - Driver: "local", - }, - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - volumeResponse, err := client.VolumeList(context.Background(), listCase.filters) - if err != nil { - t.Fatal(err) - } - if len(volumeResponse.Volumes) != 1 { - t.Fatalf("expected 1 volume, got %v", volumeResponse.Volumes) - } - } -} diff --git a/client/volume_remove_test.go b/client/volume_remove_test.go deleted file mode 100644 index 1fe657349a..0000000000 --- a/client/volume_remove_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestVolumeRemoveError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.VolumeRemove(context.Background(), "volume_id", false) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestVolumeRemove(t *testing.T) { - expectedURL := "/volumes/volume_id" - - client := &Client{ - client: newMockClient(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) - } - if req.Method != "DELETE" { - return nil, fmt.Errorf("expected DELETE method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("body"))), - }, nil - }), - } - - err := client.VolumeRemove(context.Background(), "volume_id", false) - if err != nil { - t.Fatal(err) - } -} diff --git a/cmd/docker/docker.go b/cmd/docker/docker.go index 99642ba07f..0066137c0c 100644 --- a/cmd/docker/docker.go +++ b/cmd/docker/docker.go @@ -13,8 +13,8 @@ import ( cliconfig "github.com/docker/cli/cli/config" "github.com/docker/cli/cli/debug" cliflags "github.com/docker/cli/cli/flags" - "github.com/docker/cli/client" "github.com/docker/docker/api/types/versions" + "github.com/docker/docker/client" "github.com/docker/docker/dockerversion" "github.com/docker/docker/pkg/term" "github.com/spf13/cobra" diff --git a/client/README.md b/vendor/github.com/docker/docker/client/README.md similarity index 92% rename from client/README.md rename to vendor/github.com/docker/docker/client/README.md index e21844b93b..059dfb3ce7 100644 --- a/client/README.md +++ b/vendor/github.com/docker/docker/client/README.md @@ -12,7 +12,7 @@ import ( "fmt" "github.com/docker/docker/api/types" - "github.com/docker/cli/client" + "github.com/docker/docker/client" ) func main() { @@ -32,4 +32,4 @@ func main() { } ``` -[Full documentation is available on GoDoc.](https://godoc.org/github.com/docker/cli/client) +[Full documentation is available on GoDoc.](https://godoc.org/github.com/docker/docker/client) diff --git a/client/checkpoint_create.go b/vendor/github.com/docker/docker/client/checkpoint_create.go similarity index 100% rename from client/checkpoint_create.go rename to vendor/github.com/docker/docker/client/checkpoint_create.go diff --git a/client/checkpoint_delete.go b/vendor/github.com/docker/docker/client/checkpoint_delete.go similarity index 100% rename from client/checkpoint_delete.go rename to vendor/github.com/docker/docker/client/checkpoint_delete.go diff --git a/client/checkpoint_list.go b/vendor/github.com/docker/docker/client/checkpoint_list.go similarity index 100% rename from client/checkpoint_list.go rename to vendor/github.com/docker/docker/client/checkpoint_list.go diff --git a/client/client.go b/vendor/github.com/docker/docker/client/client.go similarity index 99% rename from client/client.go rename to vendor/github.com/docker/docker/client/client.go index 3f1ee8d432..df3698adc6 100644 --- a/client/client.go +++ b/vendor/github.com/docker/docker/client/client.go @@ -23,7 +23,7 @@ For example, to list running containers (the equivalent of "docker ps"): "fmt" "github.com/docker/docker/api/types" - "github.com/docker/cli/client" + "github.com/docker/docker/client" ) func main() { diff --git a/client/client_unix.go b/vendor/github.com/docker/docker/client/client_unix.go similarity index 100% rename from client/client_unix.go rename to vendor/github.com/docker/docker/client/client_unix.go diff --git a/client/client_windows.go b/vendor/github.com/docker/docker/client/client_windows.go similarity index 100% rename from client/client_windows.go rename to vendor/github.com/docker/docker/client/client_windows.go diff --git a/client/container_attach.go b/vendor/github.com/docker/docker/client/container_attach.go similarity index 100% rename from client/container_attach.go rename to vendor/github.com/docker/docker/client/container_attach.go diff --git a/client/container_commit.go b/vendor/github.com/docker/docker/client/container_commit.go similarity index 100% rename from client/container_commit.go rename to vendor/github.com/docker/docker/client/container_commit.go diff --git a/client/container_copy.go b/vendor/github.com/docker/docker/client/container_copy.go similarity index 100% rename from client/container_copy.go rename to vendor/github.com/docker/docker/client/container_copy.go diff --git a/client/container_create.go b/vendor/github.com/docker/docker/client/container_create.go similarity index 100% rename from client/container_create.go rename to vendor/github.com/docker/docker/client/container_create.go diff --git a/client/container_diff.go b/vendor/github.com/docker/docker/client/container_diff.go similarity index 100% rename from client/container_diff.go rename to vendor/github.com/docker/docker/client/container_diff.go diff --git a/client/container_exec.go b/vendor/github.com/docker/docker/client/container_exec.go similarity index 100% rename from client/container_exec.go rename to vendor/github.com/docker/docker/client/container_exec.go diff --git a/client/container_export.go b/vendor/github.com/docker/docker/client/container_export.go similarity index 100% rename from client/container_export.go rename to vendor/github.com/docker/docker/client/container_export.go diff --git a/client/container_inspect.go b/vendor/github.com/docker/docker/client/container_inspect.go similarity index 100% rename from client/container_inspect.go rename to vendor/github.com/docker/docker/client/container_inspect.go diff --git a/client/container_kill.go b/vendor/github.com/docker/docker/client/container_kill.go similarity index 100% rename from client/container_kill.go rename to vendor/github.com/docker/docker/client/container_kill.go diff --git a/client/container_list.go b/vendor/github.com/docker/docker/client/container_list.go similarity index 100% rename from client/container_list.go rename to vendor/github.com/docker/docker/client/container_list.go diff --git a/client/container_logs.go b/vendor/github.com/docker/docker/client/container_logs.go similarity index 100% rename from client/container_logs.go rename to vendor/github.com/docker/docker/client/container_logs.go diff --git a/client/container_pause.go b/vendor/github.com/docker/docker/client/container_pause.go similarity index 100% rename from client/container_pause.go rename to vendor/github.com/docker/docker/client/container_pause.go diff --git a/client/container_prune.go b/vendor/github.com/docker/docker/client/container_prune.go similarity index 100% rename from client/container_prune.go rename to vendor/github.com/docker/docker/client/container_prune.go diff --git a/client/container_remove.go b/vendor/github.com/docker/docker/client/container_remove.go similarity index 100% rename from client/container_remove.go rename to vendor/github.com/docker/docker/client/container_remove.go diff --git a/client/container_rename.go b/vendor/github.com/docker/docker/client/container_rename.go similarity index 100% rename from client/container_rename.go rename to vendor/github.com/docker/docker/client/container_rename.go diff --git a/client/container_resize.go b/vendor/github.com/docker/docker/client/container_resize.go similarity index 100% rename from client/container_resize.go rename to vendor/github.com/docker/docker/client/container_resize.go diff --git a/client/container_restart.go b/vendor/github.com/docker/docker/client/container_restart.go similarity index 100% rename from client/container_restart.go rename to vendor/github.com/docker/docker/client/container_restart.go diff --git a/client/container_start.go b/vendor/github.com/docker/docker/client/container_start.go similarity index 100% rename from client/container_start.go rename to vendor/github.com/docker/docker/client/container_start.go diff --git a/client/container_stats.go b/vendor/github.com/docker/docker/client/container_stats.go similarity index 100% rename from client/container_stats.go rename to vendor/github.com/docker/docker/client/container_stats.go diff --git a/client/container_stop.go b/vendor/github.com/docker/docker/client/container_stop.go similarity index 100% rename from client/container_stop.go rename to vendor/github.com/docker/docker/client/container_stop.go diff --git a/client/container_top.go b/vendor/github.com/docker/docker/client/container_top.go similarity index 100% rename from client/container_top.go rename to vendor/github.com/docker/docker/client/container_top.go diff --git a/client/container_unpause.go b/vendor/github.com/docker/docker/client/container_unpause.go similarity index 100% rename from client/container_unpause.go rename to vendor/github.com/docker/docker/client/container_unpause.go diff --git a/client/container_update.go b/vendor/github.com/docker/docker/client/container_update.go similarity index 100% rename from client/container_update.go rename to vendor/github.com/docker/docker/client/container_update.go diff --git a/client/container_wait.go b/vendor/github.com/docker/docker/client/container_wait.go similarity index 100% rename from client/container_wait.go rename to vendor/github.com/docker/docker/client/container_wait.go diff --git a/client/disk_usage.go b/vendor/github.com/docker/docker/client/disk_usage.go similarity index 100% rename from client/disk_usage.go rename to vendor/github.com/docker/docker/client/disk_usage.go diff --git a/client/errors.go b/vendor/github.com/docker/docker/client/errors.go similarity index 100% rename from client/errors.go rename to vendor/github.com/docker/docker/client/errors.go diff --git a/client/events.go b/vendor/github.com/docker/docker/client/events.go similarity index 100% rename from client/events.go rename to vendor/github.com/docker/docker/client/events.go diff --git a/client/hijack.go b/vendor/github.com/docker/docker/client/hijack.go similarity index 100% rename from client/hijack.go rename to vendor/github.com/docker/docker/client/hijack.go diff --git a/client/image_build.go b/vendor/github.com/docker/docker/client/image_build.go similarity index 100% rename from client/image_build.go rename to vendor/github.com/docker/docker/client/image_build.go diff --git a/client/image_create.go b/vendor/github.com/docker/docker/client/image_create.go similarity index 100% rename from client/image_create.go rename to vendor/github.com/docker/docker/client/image_create.go diff --git a/client/image_history.go b/vendor/github.com/docker/docker/client/image_history.go similarity index 100% rename from client/image_history.go rename to vendor/github.com/docker/docker/client/image_history.go diff --git a/client/image_import.go b/vendor/github.com/docker/docker/client/image_import.go similarity index 100% rename from client/image_import.go rename to vendor/github.com/docker/docker/client/image_import.go diff --git a/client/image_inspect.go b/vendor/github.com/docker/docker/client/image_inspect.go similarity index 100% rename from client/image_inspect.go rename to vendor/github.com/docker/docker/client/image_inspect.go diff --git a/client/image_list.go b/vendor/github.com/docker/docker/client/image_list.go similarity index 100% rename from client/image_list.go rename to vendor/github.com/docker/docker/client/image_list.go diff --git a/client/image_load.go b/vendor/github.com/docker/docker/client/image_load.go similarity index 100% rename from client/image_load.go rename to vendor/github.com/docker/docker/client/image_load.go diff --git a/client/image_prune.go b/vendor/github.com/docker/docker/client/image_prune.go similarity index 100% rename from client/image_prune.go rename to vendor/github.com/docker/docker/client/image_prune.go diff --git a/client/image_pull.go b/vendor/github.com/docker/docker/client/image_pull.go similarity index 100% rename from client/image_pull.go rename to vendor/github.com/docker/docker/client/image_pull.go diff --git a/client/image_push.go b/vendor/github.com/docker/docker/client/image_push.go similarity index 100% rename from client/image_push.go rename to vendor/github.com/docker/docker/client/image_push.go diff --git a/client/image_remove.go b/vendor/github.com/docker/docker/client/image_remove.go similarity index 100% rename from client/image_remove.go rename to vendor/github.com/docker/docker/client/image_remove.go diff --git a/client/image_save.go b/vendor/github.com/docker/docker/client/image_save.go similarity index 100% rename from client/image_save.go rename to vendor/github.com/docker/docker/client/image_save.go diff --git a/client/image_search.go b/vendor/github.com/docker/docker/client/image_search.go similarity index 100% rename from client/image_search.go rename to vendor/github.com/docker/docker/client/image_search.go diff --git a/client/image_tag.go b/vendor/github.com/docker/docker/client/image_tag.go similarity index 100% rename from client/image_tag.go rename to vendor/github.com/docker/docker/client/image_tag.go diff --git a/client/info.go b/vendor/github.com/docker/docker/client/info.go similarity index 100% rename from client/info.go rename to vendor/github.com/docker/docker/client/info.go diff --git a/client/interface.go b/vendor/github.com/docker/docker/client/interface.go similarity index 100% rename from client/interface.go rename to vendor/github.com/docker/docker/client/interface.go diff --git a/client/interface_experimental.go b/vendor/github.com/docker/docker/client/interface_experimental.go similarity index 100% rename from client/interface_experimental.go rename to vendor/github.com/docker/docker/client/interface_experimental.go diff --git a/client/interface_stable.go b/vendor/github.com/docker/docker/client/interface_stable.go similarity index 100% rename from client/interface_stable.go rename to vendor/github.com/docker/docker/client/interface_stable.go diff --git a/client/login.go b/vendor/github.com/docker/docker/client/login.go similarity index 100% rename from client/login.go rename to vendor/github.com/docker/docker/client/login.go diff --git a/client/network_connect.go b/vendor/github.com/docker/docker/client/network_connect.go similarity index 100% rename from client/network_connect.go rename to vendor/github.com/docker/docker/client/network_connect.go diff --git a/client/network_create.go b/vendor/github.com/docker/docker/client/network_create.go similarity index 100% rename from client/network_create.go rename to vendor/github.com/docker/docker/client/network_create.go diff --git a/client/network_disconnect.go b/vendor/github.com/docker/docker/client/network_disconnect.go similarity index 100% rename from client/network_disconnect.go rename to vendor/github.com/docker/docker/client/network_disconnect.go diff --git a/client/network_inspect.go b/vendor/github.com/docker/docker/client/network_inspect.go similarity index 100% rename from client/network_inspect.go rename to vendor/github.com/docker/docker/client/network_inspect.go diff --git a/client/network_list.go b/vendor/github.com/docker/docker/client/network_list.go similarity index 100% rename from client/network_list.go rename to vendor/github.com/docker/docker/client/network_list.go diff --git a/client/network_prune.go b/vendor/github.com/docker/docker/client/network_prune.go similarity index 100% rename from client/network_prune.go rename to vendor/github.com/docker/docker/client/network_prune.go diff --git a/client/network_remove.go b/vendor/github.com/docker/docker/client/network_remove.go similarity index 100% rename from client/network_remove.go rename to vendor/github.com/docker/docker/client/network_remove.go diff --git a/client/node_inspect.go b/vendor/github.com/docker/docker/client/node_inspect.go similarity index 100% rename from client/node_inspect.go rename to vendor/github.com/docker/docker/client/node_inspect.go diff --git a/client/node_list.go b/vendor/github.com/docker/docker/client/node_list.go similarity index 100% rename from client/node_list.go rename to vendor/github.com/docker/docker/client/node_list.go diff --git a/client/node_remove.go b/vendor/github.com/docker/docker/client/node_remove.go similarity index 100% rename from client/node_remove.go rename to vendor/github.com/docker/docker/client/node_remove.go diff --git a/client/node_update.go b/vendor/github.com/docker/docker/client/node_update.go similarity index 100% rename from client/node_update.go rename to vendor/github.com/docker/docker/client/node_update.go diff --git a/client/ping.go b/vendor/github.com/docker/docker/client/ping.go similarity index 100% rename from client/ping.go rename to vendor/github.com/docker/docker/client/ping.go diff --git a/client/plugin_create.go b/vendor/github.com/docker/docker/client/plugin_create.go similarity index 100% rename from client/plugin_create.go rename to vendor/github.com/docker/docker/client/plugin_create.go diff --git a/client/plugin_disable.go b/vendor/github.com/docker/docker/client/plugin_disable.go similarity index 100% rename from client/plugin_disable.go rename to vendor/github.com/docker/docker/client/plugin_disable.go diff --git a/client/plugin_enable.go b/vendor/github.com/docker/docker/client/plugin_enable.go similarity index 100% rename from client/plugin_enable.go rename to vendor/github.com/docker/docker/client/plugin_enable.go diff --git a/client/plugin_inspect.go b/vendor/github.com/docker/docker/client/plugin_inspect.go similarity index 100% rename from client/plugin_inspect.go rename to vendor/github.com/docker/docker/client/plugin_inspect.go diff --git a/client/plugin_install.go b/vendor/github.com/docker/docker/client/plugin_install.go similarity index 100% rename from client/plugin_install.go rename to vendor/github.com/docker/docker/client/plugin_install.go diff --git a/client/plugin_list.go b/vendor/github.com/docker/docker/client/plugin_list.go similarity index 100% rename from client/plugin_list.go rename to vendor/github.com/docker/docker/client/plugin_list.go diff --git a/client/plugin_push.go b/vendor/github.com/docker/docker/client/plugin_push.go similarity index 100% rename from client/plugin_push.go rename to vendor/github.com/docker/docker/client/plugin_push.go diff --git a/client/plugin_remove.go b/vendor/github.com/docker/docker/client/plugin_remove.go similarity index 100% rename from client/plugin_remove.go rename to vendor/github.com/docker/docker/client/plugin_remove.go diff --git a/client/plugin_set.go b/vendor/github.com/docker/docker/client/plugin_set.go similarity index 100% rename from client/plugin_set.go rename to vendor/github.com/docker/docker/client/plugin_set.go diff --git a/client/plugin_upgrade.go b/vendor/github.com/docker/docker/client/plugin_upgrade.go similarity index 100% rename from client/plugin_upgrade.go rename to vendor/github.com/docker/docker/client/plugin_upgrade.go diff --git a/client/request.go b/vendor/github.com/docker/docker/client/request.go similarity index 99% rename from client/request.go rename to vendor/github.com/docker/docker/client/request.go index 16c5c24bf8..6457b316a3 100644 --- a/client/request.go +++ b/vendor/github.com/docker/docker/client/request.go @@ -121,7 +121,6 @@ func (cli *Client) sendRequest(ctx context.Context, method, path string, query u return cli.doRequest(ctx, req) } -// nolint: gocyclo func (cli *Client) doRequest(ctx context.Context, req *http.Request) (serverResponse, error) { serverResp := serverResponse{statusCode: -1} diff --git a/client/secret_create.go b/vendor/github.com/docker/docker/client/secret_create.go similarity index 100% rename from client/secret_create.go rename to vendor/github.com/docker/docker/client/secret_create.go diff --git a/client/secret_inspect.go b/vendor/github.com/docker/docker/client/secret_inspect.go similarity index 100% rename from client/secret_inspect.go rename to vendor/github.com/docker/docker/client/secret_inspect.go diff --git a/client/secret_list.go b/vendor/github.com/docker/docker/client/secret_list.go similarity index 100% rename from client/secret_list.go rename to vendor/github.com/docker/docker/client/secret_list.go diff --git a/client/secret_remove.go b/vendor/github.com/docker/docker/client/secret_remove.go similarity index 100% rename from client/secret_remove.go rename to vendor/github.com/docker/docker/client/secret_remove.go diff --git a/client/secret_update.go b/vendor/github.com/docker/docker/client/secret_update.go similarity index 100% rename from client/secret_update.go rename to vendor/github.com/docker/docker/client/secret_update.go diff --git a/client/service_create.go b/vendor/github.com/docker/docker/client/service_create.go similarity index 100% rename from client/service_create.go rename to vendor/github.com/docker/docker/client/service_create.go diff --git a/client/service_inspect.go b/vendor/github.com/docker/docker/client/service_inspect.go similarity index 100% rename from client/service_inspect.go rename to vendor/github.com/docker/docker/client/service_inspect.go diff --git a/client/service_list.go b/vendor/github.com/docker/docker/client/service_list.go similarity index 100% rename from client/service_list.go rename to vendor/github.com/docker/docker/client/service_list.go diff --git a/client/service_logs.go b/vendor/github.com/docker/docker/client/service_logs.go similarity index 100% rename from client/service_logs.go rename to vendor/github.com/docker/docker/client/service_logs.go diff --git a/client/service_remove.go b/vendor/github.com/docker/docker/client/service_remove.go similarity index 100% rename from client/service_remove.go rename to vendor/github.com/docker/docker/client/service_remove.go diff --git a/client/service_update.go b/vendor/github.com/docker/docker/client/service_update.go similarity index 100% rename from client/service_update.go rename to vendor/github.com/docker/docker/client/service_update.go diff --git a/client/swarm_get_unlock_key.go b/vendor/github.com/docker/docker/client/swarm_get_unlock_key.go similarity index 100% rename from client/swarm_get_unlock_key.go rename to vendor/github.com/docker/docker/client/swarm_get_unlock_key.go diff --git a/client/swarm_init.go b/vendor/github.com/docker/docker/client/swarm_init.go similarity index 100% rename from client/swarm_init.go rename to vendor/github.com/docker/docker/client/swarm_init.go diff --git a/client/swarm_inspect.go b/vendor/github.com/docker/docker/client/swarm_inspect.go similarity index 100% rename from client/swarm_inspect.go rename to vendor/github.com/docker/docker/client/swarm_inspect.go diff --git a/client/swarm_join.go b/vendor/github.com/docker/docker/client/swarm_join.go similarity index 100% rename from client/swarm_join.go rename to vendor/github.com/docker/docker/client/swarm_join.go diff --git a/client/swarm_leave.go b/vendor/github.com/docker/docker/client/swarm_leave.go similarity index 100% rename from client/swarm_leave.go rename to vendor/github.com/docker/docker/client/swarm_leave.go diff --git a/client/swarm_unlock.go b/vendor/github.com/docker/docker/client/swarm_unlock.go similarity index 100% rename from client/swarm_unlock.go rename to vendor/github.com/docker/docker/client/swarm_unlock.go diff --git a/client/swarm_update.go b/vendor/github.com/docker/docker/client/swarm_update.go similarity index 100% rename from client/swarm_update.go rename to vendor/github.com/docker/docker/client/swarm_update.go diff --git a/client/task_inspect.go b/vendor/github.com/docker/docker/client/task_inspect.go similarity index 100% rename from client/task_inspect.go rename to vendor/github.com/docker/docker/client/task_inspect.go diff --git a/client/task_list.go b/vendor/github.com/docker/docker/client/task_list.go similarity index 100% rename from client/task_list.go rename to vendor/github.com/docker/docker/client/task_list.go diff --git a/client/task_logs.go b/vendor/github.com/docker/docker/client/task_logs.go similarity index 100% rename from client/task_logs.go rename to vendor/github.com/docker/docker/client/task_logs.go diff --git a/client/transport.go b/vendor/github.com/docker/docker/client/transport.go similarity index 50% rename from client/transport.go rename to vendor/github.com/docker/docker/client/transport.go index 73f6ef7b4d..401ab15d30 100644 --- a/client/transport.go +++ b/vendor/github.com/docker/docker/client/transport.go @@ -5,6 +5,14 @@ import ( "net/http" ) +// transportFunc allows us to inject a mock transport for testing. We define it +// here so we can detect the tlsconfig and return nil for only this type. +type transportFunc func(*http.Request) (*http.Response, error) + +func (tf transportFunc) RoundTrip(req *http.Request) (*http.Response, error) { + return tf(req) +} + // resolveTLSConfig attempts to resolve the TLS configuration from the // RoundTripper. func resolveTLSConfig(transport http.RoundTripper) *tls.Config { diff --git a/client/utils.go b/vendor/github.com/docker/docker/client/utils.go similarity index 99% rename from client/utils.go rename to vendor/github.com/docker/docker/client/utils.go index f3d8877df7..23d520ecb8 100644 --- a/client/utils.go +++ b/vendor/github.com/docker/docker/client/utils.go @@ -1,10 +1,9 @@ package client import ( + "github.com/docker/docker/api/types/filters" "net/url" "regexp" - - "github.com/docker/docker/api/types/filters" ) var headerRegexp = regexp.MustCompile(`\ADocker/.+\s\((.+)\)\z`) diff --git a/client/version.go b/vendor/github.com/docker/docker/client/version.go similarity index 100% rename from client/version.go rename to vendor/github.com/docker/docker/client/version.go diff --git a/client/volume_create.go b/vendor/github.com/docker/docker/client/volume_create.go similarity index 100% rename from client/volume_create.go rename to vendor/github.com/docker/docker/client/volume_create.go diff --git a/client/volume_inspect.go b/vendor/github.com/docker/docker/client/volume_inspect.go similarity index 100% rename from client/volume_inspect.go rename to vendor/github.com/docker/docker/client/volume_inspect.go diff --git a/client/volume_list.go b/vendor/github.com/docker/docker/client/volume_list.go similarity index 100% rename from client/volume_list.go rename to vendor/github.com/docker/docker/client/volume_list.go diff --git a/client/volume_prune.go b/vendor/github.com/docker/docker/client/volume_prune.go similarity index 100% rename from client/volume_prune.go rename to vendor/github.com/docker/docker/client/volume_prune.go diff --git a/client/volume_remove.go b/vendor/github.com/docker/docker/client/volume_remove.go similarity index 100% rename from client/volume_remove.go rename to vendor/github.com/docker/docker/client/volume_remove.go