diff --git a/README.md b/README.md index 036d769..ef34a6d 100644 --- a/README.md +++ b/README.md @@ -552,12 +552,6 @@ response.success? => true ``` -### Error handling - -`Docker::API::InvalidParameter` and `Docker::API::InvalidRequestBody` may be raised when an invalid option is passed as argument (ie: an option not described in Docker API documentation for request query parameters nor request body (json) parameters). Even if no errors were raised, consider validating the status code and/or message of the response to check if the Docker daemon has fulfilled the operation properly. - -To completely skip the validation process, add `:skip_validation => true` in the hash to be validated. - ### Blocks Some methods can receive a block to alter the default execution: diff --git a/lib/docker/api/base.rb b/lib/docker/api/base.rb index 57aff2c..c1e5a0d 100644 --- a/lib/docker/api/base.rb +++ b/lib/docker/api/base.rb @@ -7,9 +7,8 @@ class Docker::API::Base # # @param connection [Docker::API::Connection]: Connection to be used. def initialize connection = nil - raise Docker::API::Error.new("Expected connection to be a Docker::API::Connection class") if connection != nil && !connection.is_a?(Docker::API::Connection) + raise StandardError.new("Expected connection to be a Docker::API::Connection class") if connection != nil && !connection.is_a?(Docker::API::Connection) @connection = connection || Docker::API::Connection.new - set_automated_validation end private @@ -59,18 +58,6 @@ def auth_encoder(authentication) Base64.urlsafe_encode64(authentication.to_json.to_s).chomp end - ## - # Validate a Hash object comparing its keys with a given Array of permitted values. Raise an error if the validation fail. - # - # @param error [Error]: Error to be raised of the validation fail. - # @param permitted [Array]: List of permitted keys. - # @param params [Hash]: Hash object to be validated. - def validate error, permitted, params - return if params[:skip_validation] - unpermitted = params.keys.map(&:to_s) - permitted.map(&:to_s) - raise error.new(permitted, unpermitted) if unpermitted.size > 0 - end - ## # Convert Ruby Hash into URL query parameters. # @@ -79,7 +66,7 @@ def validate error, permitted, params # @param hash [Hash]: Hash object to be converted in a query parameter-like string. def hash_to_params hash p = [] - hash.delete_if{ | k, v | k.to_s == "skip_validation" }.each { |k,v| p.push( v.is_a?(Hash) ? "#{k}=#{v.to_json}" : "#{k}=#{v}") } + hash.each { |k,v| p.push( v.is_a?(Hash) ? "#{k}=#{v.to_json}" : "#{k}=#{v}") } p.join("&").gsub(" ","") end @@ -93,19 +80,4 @@ def build_path path, params = {} params.size > 0 ? [path, hash_to_params(params)].join("?") : path end - ## - # Set the validation to happen automatically when method parameters include "params" or "body". - def set_automated_validation - (self.methods - Object.methods).each do |method| - params_index = method(method).parameters.map{|ar| ar[1]}.index(:params) - body_index = method(method).parameters.map{|ar| ar[1]}.index(:body) - - define_singleton_method(method) do |*args, &block| - validate Docker::API::InvalidParameter, Docker::API::VALID_PARAMS["#{self.class.name}"]["#{method}"], (args[params_index] || {}) if params_index - validate Docker::API::InvalidRequestBody, Docker::API::VALID_BODY["#{self.class.name}"]["#{method}"], (args[body_index] || {}) if body_index - super(*args,&block) - end - end - end - end \ No newline at end of file diff --git a/lib/docker/api/error.rb b/lib/docker/api/error.rb deleted file mode 100644 index 4aa8ed4..0000000 --- a/lib/docker/api/error.rb +++ /dev/null @@ -1,33 +0,0 @@ -module Docker - module API - - ## - # This class represents a validation error. - class ValidationError < StandardError - - ## - # @params permitted [Array]: permitted values. - # @params unpermitted [Array]: unpermitted values. - def initialize permitted, unpermitted - super("Unpermitted options found: #{unpermitted.to_s}. Permitted are #{permitted.to_s}") - end - end - - ## - # This class represents a parameter validation error. - class InvalidParameter < Docker::API::ValidationError; end - - ## - # This class represents a request body validation error. - class InvalidRequestBody < Docker::API::ValidationError; end - - ## - # This class represents a generic error. - class Error < StandardError - def initialize msg = "Error without specific message" - super(msg) - end - end - - end - end \ No newline at end of file diff --git a/lib/docker/api/image.rb b/lib/docker/api/image.rb index 2bea426..0cde0ef 100644 --- a/lib/docker/api/image.rb +++ b/lib/docker/api/image.rb @@ -133,7 +133,7 @@ def import path, params = {} # @param params [Hash]: Parameters that are appended to the URL. # @param authentication [Hash]: Authentication parameters. def push name, params = {}, authentication = {} - raise Docker::API::Error.new("Provide authentication parameters to push an image") unless authentication.any? + raise StandardError.new("Provide authentication parameters to push an image") unless authentication.any? @connection.request(method: :post, path: build_path("/images/#{name}/push", params), headers: { "X-Registry-Auth" => auth_encoder(authentication) } ) end diff --git a/lib/dockerapi.rb b/lib/dockerapi.rb index b1cf87b..a99fbf3 100644 --- a/lib/dockerapi.rb +++ b/lib/dockerapi.rb @@ -4,7 +4,6 @@ require "fileutils" require "docker/api/version" -require "docker/api/error" require "docker/api/connection" require "docker/api/response" require "docker/api/base" @@ -44,144 +43,6 @@ def self.print_response_to_stdout=(bool) @@print_response_to_stdout = bool end self.print_response_to_stdout = false - - ## - # Valid values for parameter validations. - VALID_PARAMS = { - "Docker::API::Image" => { - "build" => [:dockerfile, :t, :extrahosts, :remote, :q, :nocache, :cachefrom, :pull, :rm, :forcerm, :memory, :memswap, :cpushares, :cpusetcpus, :cpuperiod, :cpuquota, :buildargs, :shmsize, :squash, :labels, :networkmode, :platform, :target, :outputs], - "prune" => [:filters], - "list" => [:all, :filters, "shared-size", :digests], - "search" => [:term, :limit, :filters], - "tag" => [:repo, :tag], - "remove" => [:force, :noprune], - "import" => [:quiet], - "push" => [:tag], - "commit" => [:container, :repo, :tag, :comment, :author, :pause, :changes], - "create" => [:fromImage, :fromSrc, :repo, :tag, :message, :changes, :platform], - "delete_cache" => [:all, "keep-storage", :filters] - }, - "Docker::API::Container" => { - "list" => [:all, :limit, :size, :filters], - "details" => [:size], - "top" => [:ps_args], - "start" => [:detachKeys], - "stop" => [:signal, :t], - "restart" => [:signal, :t], - "kill" => [:signal], - "wait" => [:condition], - "rename" => [:name], - "resize" => [:w, :h], - "prune" => [:filters], - "remove" => [:v, :force, :link], - "logs" => [:follow, :stdout, :stderr, :since, :until, :timestamps, :tail], - "attach" => [:detachKeys, :logs, :stream, :stdin, :stdout, :stderr], - "stats" => [:stream, "one-shot"], - "get_archive" => [:path], - "put_archive" => [:path, :noOverwriteDirNonDir, :copyUIDGID], - "create" => [:name, :platform] - }, - "Docker::API::Volume" => { - "list" => [:filters], - "remove" => [:force], - "prune" => [:filters] - }, - "Docker::API::Network" => { - "list" => [:filters], - "details" => [:verbose, :scope], - "prune" => [:filters] - }, - "Docker::API::System" => { - "events" => [:since, :until, :filters], - "df" => [:type] - }, - "Docker::API::Exec" => { - "resize" => [:w, :h] - }, - "Docker::API::Swarm" => { - "leave" => [:force], - "update" => [:version, :rotateWorkerToken, :rotateManagerToken, :rotateManagerUnlockKey] - }, - "Docker::API::Node" => { - "list" => [:filters], - "update" => [:version], - "delete" => [:force] - }, - "Docker::API::Service" => { - "list" => [:filters, :status], - "update" => [:version, :registryAuthFrom, :rollback], - "details" => [:insertDefaults], - "logs" => [:details, :follow, :stdout, :stderr, :since, :timestamps, :tail] - }, - "Docker::API::Secret" => { - "list" => [:filters], - "update" => [:version] - }, - "Docker::API::Task" => { - "list" => [:filters], - "logs" => [:details, :follow, :stdout, :stderr, :since, :timestamps, :tail] - }, - "Docker::API::Plugin" => { - "list" => [:filters], - "privileges" => [:remote], - "install" => [:remote, :name], - "remove" => [:force], - "enable" => [:timeout], - "upgrade" => [:remote] - }, - "Docker::API::Config" => { - "list" => [:filters], - "update" => [:version] - } - } - - ## - # Valid values for request body validations. - VALID_BODY = { - "Docker::API::Image" => { - "commit" => [:Hostname, :Domainname, :User, :AttachStdin, :AttachStdout, :AttachStderr, :ExposedPorts, :Tty, :OpenStdin, :StdinOnce, :Env, :Cmd, :HealthCheck, :ArgsEscaped, :Image, :Volumes, :WorkingDir, :Entrypoint, :NetworkDisabled, :MacAddress, :OnBuild, :Labels, :StopSignal, :StopTimeout, :Shell] - }, - "Docker::API::Container" => { - "create" => [:Hostname,:Domainname,:User,:AttachStdin,:AttachStdout,:AttachStderr,:ExposedPorts,:Tty,:OpenStdin,:StdinOnce,:Env,:Cmd,:HealthCheck,:ArgsEscaped,:Image,:Volumes,:WorkingDir,:Entrypoint,:NetworkDisabled,:MacAddress,:OnBuild,:Labels,:StopSignal,:StopTimeout,:Shell,:HostConfig,:NetworkingConfig], - "update" => [:CpuShares, :Memory, :CgroupParent, :BlkioWeight, :BlkioWeightDevice, :BlkioDeviceReadBps, :BlkioDeviceWriteBps, :BlkioDeviceReadIOps, :BlkioDeviceWriteIOps, :CpuPeriod, :CpuQuota, :CpuRealtimePeriod, :CpuRealtimeRuntime, :CpusetCpus, :CpusetMems, :Devices, :DeviceCgroupRules, :DeviceRequest, :Memory, :KernelMemoryTCP, :MemoryReservation, :MemorySwap, :MemorySwappiness, :NanoCPUs, :OomKillDisable, :Init, :PidsLimit, :ULimits, :CpuCount, :CpuPercent, :IOMaximumIOps, :IOMaximumBandwidth, :RestartPolicy] - }, - "Docker::API::Volume" => { - "create" => [:Name, :Driver, :DriverOpts, :Labels, :ClusterVolumeSpec] - }, - "Docker::API::Network" => { - "create" => [:Name, :CheckDuplicate, :Driver, :Internal, :Attachable, :Ingress, :IPAM, :EnableIPv6, :Options, :Labels], - "connect" => [:Container, :EndpointConfig], - "disconnect" => [:Container, :Force] - }, - "Docker::API::System" => { - "auth" => [:username, :password, :email, :serveraddress, :identitytoken] - }, - "Docker::API::Exec" => { - "create" => [:AttachStdin, :AttachStdout, :AttachStderr, :ConsoleSize, :DetachKeys, :Tty, :Env, :Cmd, :Privileged, :User, :WorkingDir], - "start" => [:Detach, :Tty, :ConsoleSize] - }, - "Docker::API::Swarm" => { - "init" => [:ListenAddr, :AdvertiseAddr, :DataPathAddr, :DataPathPort, :DefaultAddrPool, :ForceNewCluster, :SubnetSize, :Spec], - "update" => [:Name, :Labels, :Orchestration, :Raft, :Dispatcher, :CAConfig, :EncryptionConfig, :TaskDefaults], - "unlock" => [:UnlockKey], - "join" => [:ListenAddr, :AdvertiseAddr, :DataPathAddr, :RemoteAddrs, :JoinToken] - }, - "Docker::API::Node" => { - "update" => [:Name, :Labels, :Role, :Availability] - }, - "Docker::API::Service" => { - "create" => [:Name, :Labels, :TaskTemplate, :Mode, :UpdateConfig, :RollbackConfig, :Networks, :EndpointSpec], - "update" => [:Name, :Labels, :TaskTemplate, :Mode, :UpdateConfig, :RollbackConfig, :Networks, :EndpointSpec] - }, - "Docker::API::Secret" => { - "create" => [:Name, :Labels, :Data, :Driver, :Templating], - "update" => [:Name, :Labels, :Data, :Driver, :Templating] - }, - "Docker::API::Config" => { - "create" => [:Name, :Labels, :Data, :Templating], - "update" => [:Name, :Labels, :Data, :Templating] - } - } end end diff --git a/spec/endpoints/config_spec.rb b/spec/endpoints/config_spec.rb index c170ed1..b9be511 100644 --- a/spec/endpoints/config_spec.rb +++ b/spec/endpoints/config_spec.rb @@ -22,7 +22,7 @@ it { expect(subject.list(filters: {id: { "config-id": true }}).request_params[:path]).to eq('/v1.43/configs?filters={"id":{"config-id":true}}') } it { expect(subject.list(filters: {label: { "label=key": true }}).request_params[:path]).to eq('/v1.43/configs?filters={"label":{"label=key":true}}') } it { expect(subject.list(filters: {name: { "config-name": true }}).request_params[:path]).to eq('/v1.43/configs?filters={"name":{"config-name":true}}') } - it { expect{subject.list(invalid: true)}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.list(invalid: true)}.not_to raise_error } end describe ".create" do @@ -30,7 +30,7 @@ it { expect(subject.create.request_params[:method]).to eq(:post) } it { expect(subject.create(Name: "rspec-config").request_params[:body]).to eq('{"Name":"rspec-config"}') } it { expect(subject.create({Name: "rspec-config",Labels: {foo: "bar"}, Data: "VEhJUyBJUyBOT1QgQSBSRUFMIENFUlRJRklDQVRFCg=="}).request_params[:body]).to eq('{"Name":"rspec-config","Labels":{"foo":"bar"},"Data":"VEhJUyBJUyBOT1QgQSBSRUFMIENFUlRJRklDQVRFCg=="}') } - it { expect{subject.create(invalid: true)}.to raise_error(Docker::API::InvalidRequestBody) } + it { expect{subject.create(invalid: true)}.not_to raise_error } end describe ".details" do @@ -46,8 +46,8 @@ it { expect(subject.update("rspec-config", {version: version}, spec).request_params[:path]).to eq('/v1.43/v1.43/configs/rspec-config/update?version=abc') } it { expect(subject.update("rspec-config", {version: version}, spec).request_params[:method]).to eq(:post) } - it { expect{subject.update("rspec-config", invalid: true)}.to raise_error(Docker::API::InvalidParameter) } - it { expect{subject.update("rspec-config", {version: version}, {invalid: true})}.to raise_error(Docker::API::InvalidRequestBody) } + it { expect{subject.update("rspec-config", invalid: true)}.not_to raise_error } + it { expect{subject.update("rspec-config", {version: version}, {invalid: true})}.not_to raise_error } end describe ".delete" do diff --git a/spec/endpoints/container_spec.rb b/spec/endpoints/container_spec.rb index a6ab66f..dbd0c4e 100644 --- a/spec/endpoints/container_spec.rb +++ b/spec/endpoints/container_spec.rb @@ -35,15 +35,15 @@ it { expect(subject.list( { all: true, filters: {name: {"test": true}} } ).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/json?all=true&filters={\"name\":{\"test\":true}}") } it { expect(subject.list( { all: true, filters: {exited: {"0": true} } } ).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/json?all=true&filters={\"exited\":{\"0\":true}}") } it { expect(subject.list( { all: true, filters: {status: ["running"] } } ).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/json?all=true&filters={\"status\":[\"running\"]}") } - it { expect { subject.list( { invalid: "invalid" } ) }.to raise_error(Docker::API::InvalidParameter) } + it { expect { subject.list( { invalid: "invalid" } ) }.not_to raise_error } end describe ".create" do it { expect(subject.create({name: "dockerapi", platform: "linux/amd64"}, {Image: "nginx"}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/create?name=dockerapi&platform=linux/amd64") } it { expect(subject.create({name: "dockerapi", platform: "linux/amd64"}, {Image: "nginx"}).request_params[:method]).to eq(:post) } it { expect(subject.create({name: "dockerapi", platform: "linux/amd64"}, {Image: "nginx"}).request_params[:body]).to eq('{"Image":"nginx"}') } - it { expect{subject.remove({invalid: "invalid", platform: "linux/amd64"}, {Image: "nginx"})}.to raise_error(Docker::API::InvalidParameter) } - it { expect{subject.create({name: "dockerapi", platform: "linux/amd64"}, {invalid: "invalid"})}.to raise_error(Docker::API::InvalidRequestBody) } + it { expect{subject.remove({invalid: "invalid", platform: "linux/amd64"}, {Image: "nginx"})}.not_to raise_error } + it { expect{subject.create({name: "dockerapi", platform: "linux/amd64"}, {invalid: "invalid"})}.not_to raise_error } end describe ".remove" do @@ -51,35 +51,35 @@ it { expect(subject.remove("dockerapi").request_params[:method]).to eq(:delete) } it { expect(subject.remove("dockerapi", {v: true}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/dockerapi?v=true") } it { expect(subject.remove("dockerapi", {force: true}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/dockerapi?force=true") } - it { expect{subject.remove("dockerapi", {invalid: "invalid"})}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.remove("dockerapi", {invalid: "invalid"})}.not_to raise_error } end describe ".start" do it { expect(subject.start("dockerapi").request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/dockerapi/start") } it { expect(subject.start("dockerapi", {detachKeys: "ctrl-c"}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/dockerapi/start?detachKeys=ctrl-c") } it { expect(subject.start("dockerapi").request_params[:method]).to eq(:post) } - it { expect{subject.start("dockerapi", {invalid: "invalid"})}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.start("dockerapi", {invalid: "invalid"})}.not_to raise_error } end describe ".stop" do it { expect(subject.stop("dockerapi").request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/dockerapi/stop") } it { expect(subject.stop("dockerapi", {signal: "SIGINT"}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/dockerapi/stop?signal=SIGINT") } it { expect(subject.stop("dockerapi").request_params[:method]).to eq(:post) } - it { expect{subject.stop("dockerapi", {invalid: "invalid"})}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.stop("dockerapi", {invalid: "invalid"})}.not_to raise_error } end describe ".kill" do it { expect(subject.kill("dockerapi").request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/dockerapi/kill") } it { expect(subject.kill("dockerapi", {signal: "SIGINT"}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/dockerapi/kill?signal=SIGINT") } it { expect(subject.kill("dockerapi").request_params[:method]).to eq(:post) } - it { expect{subject.kill("dockerapi", {invalid: "invalid"})}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.kill("dockerapi", {invalid: "invalid"})}.not_to raise_error } end describe ".restart" do it { expect(subject.restart("dockerapi").request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/dockerapi/restart") } it { expect(subject.restart("dockerapi", {signal: "SIGINT"}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/dockerapi/restart?signal=SIGINT") } it { expect(subject.restart("dockerapi").request_params[:method]).to eq(:post) } - it { expect{subject.restart("dockerapi", {invalid: "invalid"})}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.restart("dockerapi", {invalid: "invalid"})}.not_to raise_error } end describe ".pause" do @@ -97,7 +97,7 @@ it { expect(subject.top("dockerapi").request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/dockerapi/top") } it { expect(subject.top("dockerapi").request_params[:method]).to eq(:get) } it { expect(subject.top("dockerapi").json).to be_kind_of(Hash) } - it { expect{subject.top("dockerapi", {invalid_value: "invalid"})}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.top("dockerapi", {invalid_value: "invalid"})}.not_to raise_error } end describe ".wait" do @@ -118,7 +118,7 @@ describe ".resize" do it { expect(subject.resize("dockerapi", {h: 100, w: 100}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/dockerapi/resize?h=100&w=100") } it { expect(subject.resize("dockerapi", {h: 100, w: 100}).request_params[:method]).to eq(:post) } - it { expect{subject.resize("dockerapi", {invalid: "invalid"})}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.resize("dockerapi", {invalid: "invalid"})}.not_to raise_error } end describe ".details" do @@ -128,7 +128,7 @@ it { expect(subject.details("dockerapi", {size: true}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/dockerapi/json?size=true") } it { expect(subject.details("dockerapi").request_params[:method]).to eq(:get) } it { expect(subject.details("dockerapi").body).to match(/\"Name\":\"\/dockerapi\"/) } - it { expect{subject.details("dockerapi", {invalid_value: "invalid"})}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.details("dockerapi", {invalid_value: "invalid"})}.not_to raise_error } end describe ".logs" do @@ -139,7 +139,7 @@ it { expect(subject.logs("dockerapi", {stdout: true, until: 999999999}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/dockerapi/logs?stdout=true&until=999999999") } it { expect(subject.logs("dockerapi", {stdout: true, timestamps: true}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/dockerapi/logs?stdout=true×tamps=true") } it { expect(subject.logs("dockerapi", {stdout: true, tail: "all"}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/dockerapi/logs?stdout=true&tail=all") } - it { expect{subject.logs("dockerapi", {invalid_value: "invalid"})}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.logs("dockerapi", {invalid_value: "invalid"})}.not_to raise_error } end describe ".changes" do @@ -153,7 +153,7 @@ describe ".stats" do it { expect(subject.stats("dockerapi", {stream: false}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/dockerapi/stats?stream=false") } it { expect(subject.stats("dockerapi", {stream: false}).request_params[:method]).to eq(:get) } - it { expect{subject.stats("dockerapi", {invalid_value: "invalid"})}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.stats("dockerapi", {invalid_value: "invalid"})}.not_to raise_error } end describe ".export" do @@ -171,7 +171,7 @@ it { expect(subject.update("dockerapi", {RestartPolicy: {Name: "unless-stopped"}}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/dockerapi/update") } it { expect(subject.update("dockerapi", {RestartPolicy: {Name: "unless-stopped"}}).request_params[:method]).to eq(:post) } it { expect(subject.update("dockerapi", {RestartPolicy: {Name: "unless-stopped"}}).request_params[:body]).to eq('{"RestartPolicy":{"Name":"unless-stopped"}}') } - it { expect{subject.update("dockerapi", {invalid: "invalid"})}.to raise_error(Docker::API::InvalidRequestBody) } + it { expect{subject.update("dockerapi", {invalid: "invalid"})}.not_to raise_error } end describe ".rename" do @@ -182,7 +182,7 @@ describe ".attach" do it { expect(subject.attach("dockerapi").request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/dockerapi/attach") } it { expect(subject.attach("dockerapi").request_params[:method]).to eq(:post) } - it { expect{subject.attach("dockerapi", {invalid: "invalid"})}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.attach("dockerapi", {invalid: "invalid"})}.not_to raise_error } end describe ".prune" do @@ -192,7 +192,7 @@ it { expect(subject.prune.request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/containers/prune") } it { expect(subject.prune.request_params[:method]).to eq(:post) } it { expect(subject.prune.json).to be_kind_of(Hash) } - it { expect{described_class.new.prune( {invalid: "invalid"})}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.prune( {invalid: "invalid"})}.not_to raise_error } end end end \ No newline at end of file diff --git a/spec/endpoints/image_spec.rb b/spec/endpoints/image_spec.rb index 81699fd..4b0e789 100644 --- a/spec/endpoints/image_spec.rb +++ b/spec/endpoints/image_spec.rb @@ -57,13 +57,13 @@ it { expect(subject.search(term: "busybox", filters: {"is-automated": {"true": true}}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/images/search?term=busybox&filters={\"is-automated\":{\"true\":true}}") } it { expect(subject.search(term: "busybox", filters: {"is-official": {"true": true}}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/images/search?term=busybox&filters={\"is-official\":{\"true\":true}}") } it { expect(subject.search(term: "busybox", filters: {stars: {"20": true}}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/images/search?term=busybox&filters={\"stars\":{\"20\":true}}") } - it { expect{subject.search(invalid: "invalid")}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.search(invalid: "invalid")}.not_to raise_error } end describe ".tag" do it { expect(subject.tag("dockerapi").request_params[:path]).to eq ("/v#{Docker::API::API_VERSION}/images/dockerapi/tag") } it { expect(subject.tag("dockerapi", repo: "dockerapi/tag:1").request_params[:path]).to eq ("/v#{Docker::API::API_VERSION}/images/dockerapi/tag?repo=dockerapi/tag:1") } it { expect(subject.tag("dockerapi", repo: "dockerapi/tag", tag: "2").request_params[:path]).to eq ("/v#{Docker::API::API_VERSION}/images/dockerapi/tag?repo=dockerapi/tag&tag=2") } - it { expect{subject.tag("dockerapi", invalid: "invalid")}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.tag("dockerapi", invalid: "invalid")}.not_to raise_error } end describe ".prune" do it { expect(subject.prune.request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/images/prune") } @@ -80,8 +80,7 @@ it { expect(subject.remove("dockerapi").request_params[:method]).to eq(:delete) } it { expect(subject.remove("dockerapi", force: true).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/images/dockerapi?force=true") } it { expect(subject.remove("dockerapi", noprune: false).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/images/dockerapi?noprune=false") } - it { expect{subject.remove("dockerapi", invalid: "invalid")}.to raise_error(Docker::API::InvalidParameter) } - it { expect{subject.remove("dockerapi", invalid: "invalid")}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.remove("dockerapi", invalid: "invalid")}.not_to raise_error } end describe ".export" do before(:all) { Excon.stub({ :scheme => 'http', :host => '127.0.0.1', :method => :get, :port => 2375 }, { headers: {'Content-Type': 'text'}, body: 'a', status: 200 }) } @@ -107,14 +106,13 @@ it { expect(subject.import("import.tar", quiet: true).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/images/load?quiet=true") } it { expect(subject.import("import.tar", quiet: true).request_params[:method]).to eq(:post) } it { expect(subject.import("import.tar", quiet: true).request_params[:headers]["Content-Type"]).to eq("application/x-tar") } - it { expect{subject.import("import.tar", invalid: "invalid")}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.import("import.tar", invalid: "invalid")}.not_to raise_error } end describe ".push" do it { expect(subject.push("localhost:5000/dockerapi", {},{username: "janedoe", password: "password"}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/images/localhost:5000/dockerapi/push") } it { expect(subject.push("localhost:5000/dockerapi", {},{username: "janedoe", password: "password"}).request_params[:method]).to eq(:post) } it { expect(subject.push("localhost:5000/dockerapi", {},{username: "janedoe", password: "password"}).request_params[:headers]["X-Registry-Auth"]).to eq("eyJ1c2VybmFtZSI6ImphbmVkb2UiLCJwYXNzd29yZCI6InBhc3N3b3JkIn0=") } - it { expect{subject.push("localhost:5000/push:1", invalid: "invalid")}.to raise_error(Docker::API::InvalidParameter) } - it { expect{subject.push("localhost:5000/push:1")}.to raise_error(Docker::API::Error, "Provide authentication parameters to push an image") } + it { expect{subject.push("localhost:5000/push:1")}.to raise_error(StandardError, "Provide authentication parameters to push an image") } end describe ".commit" do before(:all) { Excon.stub({ :scheme => 'http', :host => '127.0.0.1', :method => :get, :port => 2375 }, { headers: {'Content-Type': 'application/json'}, body: '{"Config": {}}', status: 200 }) } @@ -130,9 +128,9 @@ it { expect(subject.commit(container: "dockerapi", repo: "dockerapi/dockerapi", tag: "5", pause: false ).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/commit?container=dockerapi&repo=dockerapi/dockerapi&tag=5&pause=false") } it { expect(subject.commit({container: "dockerapi", repo: "dockerapi/dockerapi:6"}, {OpenStdin: false, Cmd: "echo dockerapi", Entrypoint: [""]} ).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/commit?container=dockerapi&repo=dockerapi/dockerapi:6") } it { expect(subject.commit({container: "dockerapi", repo: "dockerapi/dockerapi:6"}, {OpenStdin: false, Cmd: "echo dockerapi", Entrypoint: [""]} ).request_params[:body]).to eq("{\"OpenStdin\":false,\"Cmd\":\"echo dockerapi\",\"Entrypoint\":[\"\"]}") } - it { expect{subject.commit(invalid: "invalid")}.to raise_error(Docker::API::InvalidParameter) } - it { expect{subject.commit({invalid: "invalid"}, {invalid: "invalid"})}.to raise_error(Docker::API::InvalidParameter) } - it { expect{subject.commit({}, {invalid: "invalid"})}.to raise_error(Docker::API::InvalidRequestBody) } + it { expect{subject.commit(invalid: "invalid")}.not_to raise_error } + it { expect{subject.commit({invalid: "invalid"}, {invalid: "invalid"})}.not_to raise_error } + it { expect{subject.commit({}, {invalid: "invalid"})}.not_to raise_error } end describe ".create" do context "from repository without authentication" do @@ -165,15 +163,15 @@ it { expect(subject.build(nil, remote: "https://address/to/image.tar.xz").request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/build?remote=https://address/to/image.tar.xz") } it { expect(subject.build(nil, remote: "https://address/to/Dockerfile").request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/build?remote=https://address/to/Dockerfile") } - it { expect{subject.build("build.tar.xz", invalid: "invalid")}.to raise_error(Docker::API::InvalidParameter) } - it { expect{subject.build(nil, remote: "https://address/to/image.tar.xz", invalid: "invalid")}.to raise_error(Docker::API::InvalidParameter) } - it { expect{subject.build(nil, invalid: "invalid", skip_validation: true)}.to raise_error(Docker::API::Error) } + it { expect{subject.build("build.tar.xz", invalid: "invalid")}.not_to raise_error } + it { expect{subject.build(nil, remote: "https://address/to/image.tar.xz", invalid: "invalid")}.not_to raise_error } + it { expect{subject.build(nil, invalid: "invalid")}.to raise_error(StandardError) } end describe ".delete_cache" do it { expect(subject.delete_cache.request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/build/prune") } it { expect(subject.delete_cache.request_params[:method]).to eq(:post) } it { expect(subject.delete_cache(all:true, "keep-storage": 100000, filters: {until: {"24h": true}, inuse: {"true": true}, shared: {"true": true}}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/build/prune?all=true&keep-storage=100000&filters={\"until\":{\"24h\":true},\"inuse\":{\"true\":true},\"shared\":{\"true\":true}}") } - it { expect{subject.delete_cache(invalid: "invalid")}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.delete_cache(invalid: "invalid")}.not_to raise_error } end end end \ No newline at end of file diff --git a/spec/endpoints/network_spec.rb b/spec/endpoints/network_spec.rb index 146420c..5fd0761 100644 --- a/spec/endpoints/network_spec.rb +++ b/spec/endpoints/network_spec.rb @@ -22,7 +22,7 @@ it { expect(subject.list(filters: { scope: {"local": true} }).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/networks?filters={\"scope\":{\"local\":true}}") } it { expect(subject.list(filters: { type: {"custom": true} }).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/networks?filters={\"type\":{\"custom\":true}}") } it { expect(subject.list(filters: { type: {"builtin": true} }).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/networks?filters={\"type\":{\"builtin\":true}}") } - it { expect{subject.list( invalid: true )}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.list( invalid: true )}.not_to raise_error } end describe ".details" do @@ -30,7 +30,7 @@ it { expect(subject.details( "bridge" ).request_params[:method]).to eq(:get) } it { expect(subject.details( "bridge", verbose: true ).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/networks/bridge?verbose=true") } it { expect(subject.details( "bridge", scope: "local" ).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/networks/bridge?scope=local") } - it { expect{subject.details( "bridge", invalid: true )}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.details( "bridge", invalid: true )}.not_to raise_error } end describe ".create" do @@ -38,7 +38,7 @@ it { expect(subject.create( Name: "rspec-network",CheckDuplicate: true,Driver: "bridge",Internal: true,Attachable: true,EnableIPv6: false).request_params[:method]).to eq(:post) } it { expect(subject.create( Name: "rspec-network",CheckDuplicate: true,Driver: "bridge",Internal: true,Attachable: true,EnableIPv6: false).request_params[:body]).to eq("{\"Name\":\"rspec-network\",\"CheckDuplicate\":true,\"Driver\":\"bridge\",\"Internal\":true,\"Attachable\":true,\"EnableIPv6\":false}") } it { expect(subject.create( Name: "rspec-network",CheckDuplicate: true,Driver: "bridge",Internal: true,Attachable: true,EnableIPv6: false).request_params[:headers]["Content-Type"]).to eq("application/json") } - it { expect{subject.create( invalid: true )}.to raise_error(Docker::API::InvalidRequestBody) } + it { expect{subject.create( invalid: true )}.not_to raise_error } end describe ".connect" do @@ -46,7 +46,7 @@ it { expect(subject.connect("rspec-network", Container: "rspec-container").request_params[:method]).to eq(:post) } it { expect(subject.connect("rspec-network", Container: "rspec-container").request_params[:body]).to eq("{\"Container\":\"rspec-container\"}") } it { expect(subject.connect("rspec-network", Container: "rspec-container").request_params[:headers]["Content-Type"]).to eq("application/json") } - it { expect{subject.connect( "rspec-network", invalid: true )}.to raise_error(Docker::API::InvalidRequestBody) } + it { expect{subject.connect( "rspec-network", invalid: true )}.not_to raise_error } end describe ".disconnect" do @@ -54,7 +54,7 @@ it { expect(subject.disconnect("rspec-network", Container: "rspec-container").request_params[:method]).to eq(:post) } it { expect(subject.disconnect("rspec-network", Container: "rspec-container").request_params[:body]).to eq("{\"Container\":\"rspec-container\"}") } it { expect(subject.disconnect("rspec-network", Container: "rspec-container").request_params[:headers]["Content-Type"]).to eq("application/json") } - it { expect{subject.disconnect( "rspec-network", invalid: true )}.to raise_error(Docker::API::InvalidRequestBody) } + it { expect{subject.disconnect( "rspec-network", invalid: true )}.not_to raise_error } end describe ".remove" do @@ -68,7 +68,7 @@ it { expect(subject.prune(filters: { until: {"10m": true} }).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/networks/prune?filters={\"until\":{\"10m\":true}}") } it { expect(subject.prune(filters: { until: {"1h30m": true} }).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/networks/prune?filters={\"until\":{\"1h30m\":true}}") } it { expect(subject.prune(filters: { label: {"key=value": true} }).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/networks/prune?filters={\"label\":{\"key=value\":true}}") } - it { expect{subject.prune( invalid: true )}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.prune( invalid: true )}.not_to raise_error } end end end \ No newline at end of file diff --git a/spec/endpoints/node_spec.rb b/spec/endpoints/node_spec.rb index 541dd6f..956fe3d 100644 --- a/spec/endpoints/node_spec.rb +++ b/spec/endpoints/node_spec.rb @@ -18,7 +18,7 @@ it { expect(subject.list(filters: {membership: {"accepted": true}}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/nodes?filters={\"membership\":{\"accepted\":true}}") } it { expect(subject.list(filters: {membership: {"pending": true}}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/nodes?filters={\"membership\":{\"pending\":true}}") } it { expect(subject.list(filters: {name: {"node_name": true}}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/nodes?filters={\"name\":{\"node_name\":true}}") } - it { expect{subject.list(invalid: true)}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.list(invalid: true)}.not_to raise_error } end describe ".details" do @@ -33,15 +33,15 @@ it { expect(subject.update("id", {version: "version"}, {Role: "manager", Availability: "drain" }).request_params[:headers]["Content-Type"]).to eq("application/json") } it { expect(subject.update("id", {version: "version"}, {Name: "node-name", Role: "manager", Availability: "active" }).request_params[:body]).to eq("{\"Name\":\"node-name\",\"Role\":\"manager\",\"Availability\":\"active\"}") } it { expect(subject.update("id", {version: "version"}, {Labels: {"KEY": "VALUE"}, Role: "manager", Availability: "active" }).request_params[:body]).to eq("{\"Labels\":{\"KEY\":\"VALUE\"},\"Role\":\"manager\",\"Availability\":\"active\"}") } - it { expect{subject.update("id", {invalid: true}, {})}.to raise_error(Docker::API::InvalidParameter) } - it { expect{subject.update("id", {version: "version"}, {invalid: true})}.to raise_error(Docker::API::InvalidRequestBody) } + it { expect{subject.update("id", {invalid: true}, {})}.not_to raise_error } + it { expect{subject.update("id", {version: "version"}, {invalid: true})}.not_to raise_error } end describe ".delete" do it { expect(subject.delete("id").request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/nodes/id") } it { expect(subject.delete("id").request_params[:method]).to eq(:delete) } it { expect(subject.delete("id", force: true).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/nodes/id?force=true") } - it { expect{subject.delete("id", invalid: true)}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.delete("id", invalid: true)}.not_to raise_error } end end diff --git a/spec/endpoints/plugin_spec.rb b/spec/endpoints/plugin_spec.rb index c062348..6f4753c 100644 --- a/spec/endpoints/plugin_spec.rb +++ b/spec/endpoints/plugin_spec.rb @@ -21,13 +21,13 @@ it { expect(subject.list.request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/plugins") } it { expect(subject.list.request_params[:method]).to eq(:get) } it { expect(subject.list(filters: {capability: { "name": true }}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/plugins?filters={\"capability\":{\"name\":true}}") } - it { expect{subject.list(invalid: true)}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.list(invalid: true)}.not_to raise_error } end describe ".privileges" do it { expect(subject.privileges(remote: "remote").request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/plugins/privileges?remote=remote") } it { expect(subject.privileges(remote: "remote").request_params[:method]).to eq(:get) } - it { expect{subject.privileges(invalid: true)}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.privileges(invalid: true)}.not_to raise_error } end describe ".install" do @@ -36,7 +36,7 @@ it { expect(subject.install({remote: "plugin", name: "local-name"}, {a: "b"}).request_params[:body]).to eq("{\"a\":\"b\"}") } it { expect(subject.install({remote: "plugin", name: "local-name"}, {a: "b"}).request_params[:headers]["Content-Type"]).to eq("application/json") } it { expect(subject.install({remote: "plugin", name: "local-name"}, {a: "b"}, {username: "janedoe", password: "password"}).request_params[:headers]["X-Registry-Auth"]).to eq("eyJ1c2VybmFtZSI6ImphbmVkb2UiLCJwYXNzd29yZCI6InBhc3N3b3JkIn0=") } - it { expect{subject.install(remote: "plugin", invalid: true)}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.install(remote: "plugin", invalid: true)}.not_to raise_error } end describe ".details" do @@ -54,7 +54,7 @@ describe ".enable" do it { expect(subject.enable("plugin", timeout: 0).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/plugins/plugin/enable?timeout=0") } it { expect(subject.enable("plugin", timeout: 0).request_params[:method]).to eq(:post) } - it { expect{subject.enable("plugin", invalid: true)}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.enable("plugin", invalid: true)}.not_to raise_error } end @@ -69,14 +69,14 @@ it { expect(subject.upgrade("plugin", {remote: "remote"}).request_params[:headers]["Content-Type"]).to eq("application/json") } it { expect(subject.upgrade("plugin", {remote: "remote"}, nil, {username: "janedoe", password: "password"}).request_params[:headers]["X-Registry-Auth"]).to eq("eyJ1c2VybmFtZSI6ImphbmVkb2UiLCJwYXNzd29yZCI6InBhc3N3b3JkIn0=") } it { expect(subject.upgrade("plugin", {remote: "remote"}, nil, {username: "janedoe", password: "password"}).request_params[:body]).to eq("null") } - it { expect{subject.upgrade("plugin", remote: "remote", invalid: true)}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.upgrade("plugin", remote: "remote", invalid: true)}.not_to raise_error } end describe ".remove" do it { expect(subject.remove("plugin").request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/plugins/plugin") } it { expect(subject.remove("plugin").request_params[:method]).to eq(:delete) } it { expect(subject.remove("plugin", force: true).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/plugins/plugin?force=true") } - it { expect{subject.remove("plugin", invalid: true)}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.remove("plugin", invalid: true)}.not_to raise_error } end describe ".create" do diff --git a/spec/endpoints/secret_spec.rb b/spec/endpoints/secret_spec.rb index 9b14020..3c65e97 100644 --- a/spec/endpoints/secret_spec.rb +++ b/spec/endpoints/secret_spec.rb @@ -18,8 +18,7 @@ it { expect(subject.list(filters: {label: { "label=key": true }}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/secrets?filters={\"label\":{\"label=key\":true}}") } it { expect(subject.list(filters: {name: { "secret-name": true }}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/secrets?filters={\"name\":{\"secret-name\":true}}") } it { expect(subject.list(filters: {names: { "secret-name": true }}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/secrets?filters={\"names\":{\"secret-name\":true}}") } - it { expect{subject.list(invalid: true)}.to raise_error(Docker::API::InvalidParameter) } - it { expect{subject.list(invalid: true, skip_validation: true)}.not_to raise_error } + it { expect{subject.list(invalid: true)}.not_to raise_error } end describe ".create" do @@ -27,8 +26,7 @@ it { expect(subject.create({Name: "secret",Labels: {foo: "bar"}, Data: "VEhJUyBJUyBOT1QgQSBSRUFMIENFUlRJRklDQVRFCg=="}).request_params[:method]).to eq(:post) } it { expect(subject.create({Name: "secret",Labels: {foo: "bar"}, Data: "VEhJUyBJUyBOT1QgQSBSRUFMIENFUlRJRklDQVRFCg=="}).request_params[:body]).to eq("{\"Name\":\"secret\",\"Labels\":{\"foo\":\"bar\"},\"Data\":\"VEhJUyBJUyBOT1QgQSBSRUFMIENFUlRJRklDQVRFCg==\"}") } it { expect(subject.create({Name: "secret",Labels: {foo: "bar"}, Data: "VEhJUyBJUyBOT1QgQSBSRUFMIENFUlRJRklDQVRFCg=="}).request_params[:headers]["Content-Type"]).to eq("application/json") } - it { expect{subject.create(invalid: true)}.to raise_error(Docker::API::InvalidRequestBody) } - it { expect{subject.create(invalid: true, skip_validation: true)}.not_to raise_error } + it { expect{subject.create(invalid: true)}.not_to raise_error } end describe ".details" do @@ -41,8 +39,8 @@ it { expect(subject.update("secret", {version: "version"}, {}).request_params[:method]).to eq(:post) } it { expect(subject.update("secret", {version: "version"}, {}).request_params[:body]).to eq("{}") } it { expect(subject.update("secret", {version: "version"}, {}).request_params[:headers]["Content-Type"]).to eq("application/json") } - it { expect{subject.update("secret", invalid: true)}.to raise_error(Docker::API::InvalidParameter) } - it { expect{subject.update("secret", {version: "version"}, {invalid: true})}.to raise_error(Docker::API::InvalidRequestBody) } + it { expect{subject.update("secret", invalid: true)}.not_to raise_error } + it { expect{subject.update("secret", {version: "version"}, {invalid: true})}.not_to raise_error } end describe ".delete" do diff --git a/spec/endpoints/service_spec.rb b/spec/endpoints/service_spec.rb index 76e0111..752aab1 100644 --- a/spec/endpoints/service_spec.rb +++ b/spec/endpoints/service_spec.rb @@ -20,7 +20,7 @@ it { expect(subject.list(filters: {label: ["key=value"]}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/services?filters={\"label\":[\"key=value\"]}") } it { expect(subject.list(filters: {mode: ["replicated", "global"]}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/services?filters={\"mode\":[\"replicated\",\"global\"]}") } it { expect(subject.list(filters: {name: ["service-name"]}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/services?filters={\"name\":[\"service-name\"]}") } - it { expect{subject.list(invalid: true)}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.list(invalid: true)}.not_to raise_error } end describe ".create" do @@ -29,14 +29,14 @@ it { expect(subject.create({Name: "dockerapi", TaskTemplate: {ContainerSpec: { Image: "busybox:1.31.1-uclibc" }},Mode: { Replicated: { Replicas: 2 } },EndpointSpec: { Ports: [{Protocol: "tcp", PublishedPort: 8080, TargetPort: 80}] }}).request_params[:body]).to eq("{\"Name\":\"dockerapi\",\"TaskTemplate\":{\"ContainerSpec\":{\"Image\":\"busybox:1.31.1-uclibc\"}},\"Mode\":{\"Replicated\":{\"Replicas\":2}},\"EndpointSpec\":{\"Ports\":[{\"Protocol\":\"tcp\",\"PublishedPort\":8080,\"TargetPort\":80}]}}") } it { expect(subject.create({Name: "dockerapi", TaskTemplate: {ContainerSpec: { Image: "busybox:1.31.1-uclibc" }},Mode: { Replicated: { Replicas: 2 } },EndpointSpec: { Ports: [{Protocol: "tcp", PublishedPort: 8080, TargetPort: 80}] }}).request_params[:headers]["Content-Type"]).to eq("application/json") } it { expect(subject.create({Name: "dockerapi", TaskTemplate: {ContainerSpec: { Image: "busybox:1.31.1-uclibc" }},Mode: { Replicated: { Replicas: 2 } },EndpointSpec: { Ports: [{Protocol: "tcp", PublishedPort: 8080, TargetPort: 80}] }}, {username: "janedoe", password: "password"}).request_params[:headers]["X-Registry-Auth"]).to eq("eyJ1c2VybmFtZSI6ImphbmVkb2UiLCJwYXNzd29yZCI6InBhc3N3b3JkIn0=") } - it { expect{subject.create({ invalid: true })}.to raise_error(Docker::API::InvalidRequestBody) } + it { expect{subject.create({ invalid: true })}.not_to raise_error } end describe ".details" do it { expect(subject.details( "dockerapi" ).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/services/dockerapi") } it { expect(subject.details( "dockerapi" ).request_params[:method]).to eq(:get) } it { expect(subject.details( "dockerapi", insertDefaults: true ).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/services/dockerapi?insertDefaults=true") } - it { expect{subject.details( "dockerapi", invalid: true )}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.details( "dockerapi", invalid: true )}.not_to raise_error } end describe ".logs" do @@ -47,7 +47,7 @@ it { expect(subject.logs( "dockerapi", timestamps: 0, stdout: true ).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/services/dockerapi/logs?timestamps=0&stdout=true") } it { expect(subject.logs( "dockerapi", tail: 10, stdout: true ).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/services/dockerapi/logs?tail=10&stdout=true") } it { expect(subject.logs( "dockerapi", tail: "all", stdout: true ).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/services/dockerapi/logs?tail=all&stdout=true") } - it { expect{subject.details( "dockerapi", invalid: true )}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.details( "dockerapi", invalid: true )}.not_to raise_error } end describe ".update" do @@ -56,8 +56,8 @@ it { expect(subject.update("dockerapi", {version: "version"}, {}).request_params[:headers]["Content-Type"]).to eq("application/json") } it { expect(subject.update("dockerapi", {version: "version"}, {}, {username: "janedoe", password: "password"}).request_params[:headers]["X-Registry-Auth"]).to eq("eyJ1c2VybmFtZSI6ImphbmVkb2UiLCJwYXNzd29yZCI6InBhc3N3b3JkIn0=") } it { expect(subject.update("dockerapi", {version: "version"}, {}.merge!({TaskTemplate: {RestartPolicy: { Condition: "any", MaxAttempts: 2 }}, Mode: { Replicated: { Replicas: 1 } }})).request_params[:body]).to eq("{\"TaskTemplate\":{\"RestartPolicy\":{\"Condition\":\"any\",\"MaxAttempts\":2}},\"Mode\":{\"Replicated\":{\"Replicas\":1}}}") } - it { expect{subject.update("dockerapi", {version: "version", invalid: true })}.to raise_error(Docker::API::InvalidParameter) } - it { expect{subject.update("dockerapi", {version: "version"}, { invalid: true })}.to raise_error(Docker::API::InvalidRequestBody) } + it { expect{subject.update("dockerapi", {version: "version", invalid: true })}.not_to raise_error } + it { expect{subject.update("dockerapi", {version: "version"}, { invalid: true })}.not_to raise_error } end describe ".delete" do diff --git a/spec/endpoints/swarm_spec.rb b/spec/endpoints/swarm_spec.rb index bcb6b5e..3a7e57d 100644 --- a/spec/endpoints/swarm_spec.rb +++ b/spec/endpoints/swarm_spec.rb @@ -19,7 +19,7 @@ it { expect(subject.init({AdvertiseAddr: "127.0.0.1:2375", ListenAddr: "0.0.0.0:4567", SubnetSize: 24, Spec: { Name: "default" }}).request_params[:method]).to eq(:post) } it { expect(subject.init({AdvertiseAddr: "127.0.0.1:2375", ListenAddr: "0.0.0.0:4567", SubnetSize: 24, Spec: { Name: "default" }}).request_params[:body]).to eq("{\"AdvertiseAddr\":\"127.0.0.1:2375\",\"ListenAddr\":\"0.0.0.0:4567\",\"SubnetSize\":24,\"Spec\":{\"Name\":\"default\"}}") } it { expect(subject.init({AdvertiseAddr: "127.0.0.1:2375", ListenAddr: "0.0.0.0:4567", SubnetSize: 24, Spec: { Name: "default" }}).request_params[:headers]["Content-Type"]).to eq("application/json") } - it { expect{subject.init(invalid: true)}.to raise_error(Docker::API::InvalidRequestBody) } + it { expect{subject.init(invalid: true)}.not_to raise_error } end describe ".details" do @@ -33,11 +33,10 @@ it { expect(subject.update({version: "version", rotateWorkerToken: true}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/swarm/update?version=version&rotateWorkerToken=true") } it { expect(subject.update({version: "version", rotateManagerToken: true}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/swarm/update?version=version&rotateManagerToken=true") } it { expect(subject.update({version: "version", rotateManagerUnlockKey: true}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/swarm/update?version=version&rotateManagerUnlockKey=true") } - it { expect{subject.update({version: "version", invalid: true})}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.update({version: "version", invalid: true})}.not_to raise_error } it { expect(subject.update({version: "version"}, {EncryptionConfig: { AutoLockManagers: true } }).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/swarm/update?version=version") } it { expect(subject.update({version: "version"}, {EncryptionConfig: { AutoLockManagers: true } }).request_params[:body]).to eq("{\"EncryptionConfig\":{\"AutoLockManagers\":true}}") } it { expect(subject.update({version: "version"}, {EncryptionConfig: { AutoLockManagers: true } }).request_params[:headers]["Content-Type"]).to eq("application/json") } - it { expect{subject.update({version: "version"},{invalid: true})}.to raise_error(Docker::API::InvalidRequestBody) } end describe ".unlock_key" do @@ -60,7 +59,7 @@ describe ".leave" do it { expect(subject.leave(force: true).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/swarm/leave?force=true") } it { expect(subject.leave(force: true).request_params[:method]).to eq(:post) } - it { expect{subject.leave(invalid: true)}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.leave(invalid: true)}.not_to raise_error } end end end \ No newline at end of file diff --git a/spec/endpoints/system_spec.rb b/spec/endpoints/system_spec.rb index 30d16e8..a1021ea 100644 --- a/spec/endpoints/system_spec.rb +++ b/spec/endpoints/system_spec.rb @@ -18,8 +18,7 @@ it { expect(subject.auth(username: "janedoe", password: "password", email: "janedow@email.com", serveraddress: "docker.io", identitytoken: "token").request_params[:body]).to eq("{\"username\":\"janedoe\",\"password\":\"password\",\"email\":\"janedow@email.com\",\"serveraddress\":\"docker.io\",\"identitytoken\":\"token\"}") } it { expect(subject.auth(username: "janedoe", password: "password", email: "janedow@email.com", serveraddress: "docker.io", identitytoken: "token").request_params[:headers]["Content-Type"]).to eq("application/json") } it { expect{subject.auth(username: "janedoe", password: "password", email: "janedow@email.com", serveraddress: "docker.io", identitytoken: "token")}.not_to raise_error } - it { expect{subject.auth(invalid: true)}.to raise_error(Docker::API::InvalidRequestBody) } - it { expect{subject.auth(invalid: true, skip_validation: true)}.not_to raise_error } + it { expect{subject.auth(invalid: true)}.not_to raise_error } end describe ".ping" do @@ -42,16 +41,14 @@ it { expect(subject.events.request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/events") } it { expect(subject.events.request_params[:method]).to eq(:get) } it { expect(subject.events(until: now).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/events?until=#{now}") } - it { expect{subject.events(invalid: true)}.to raise_error(Docker::API::InvalidParameter) } - it { expect{subject.events(invalid: true, skip_validation: false)}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.events(invalid: true)}.not_to raise_error } end describe ".df" do it { expect(subject.df.request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/system/df") } it { expect(subject.df.request_params[:method]).to eq(:get) } it { expect(subject.df(type: "container").request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/system/df?type=container" )} - it { expect{subject.df(invalid: "true")}.to raise_error(Docker::API::InvalidParameter) } - it { expect{subject.df(type: "container")}.not_to raise_error } + it { expect{subject.df(invalid: "true")}.not_to raise_error } end end diff --git a/spec/endpoints/task_spec.rb b/spec/endpoints/task_spec.rb index a9598fa..cd3a37e 100644 --- a/spec/endpoints/task_spec.rb +++ b/spec/endpoints/task_spec.rb @@ -17,8 +17,7 @@ it { expect(subject.list(filters: { "desired-state": {"accepted": true} }).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/tasks?filters={\"desired-state\":{\"accepted\":true}}") } it { expect(subject.list(filters: { "id": {"id-here": true} }).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/tasks?filters={\"id\":{\"id-here\":true}}") } it { expect(subject.list(filters: { "name": {"task-name": true} }).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/tasks?filters={\"name\":{\"task-name\":true}}") } - it { expect{subject.list(invalid: true)}.to raise_error(Docker::API::InvalidParameter) } - it { expect{subject.list(invalid: true, skip_validation: true)}.not_to raise_error } + it { expect{subject.list(invalid: true)}.not_to raise_error } end describe ".details" do @@ -33,8 +32,7 @@ it { expect(subject.logs( "id", timestamps: 0, stdout: true ).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/tasks/id/logs?timestamps=0&stdout=true") } it { expect(subject.logs( "id", tail: 10, stdout: true ).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/tasks/id/logs?tail=10&stdout=true") } it { expect(subject.logs( "id", tail: "all", stdout: true ).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/tasks/id/logs?tail=all&stdout=true") } - it { expect{subject.logs( "id", invalid: true )}.to raise_error(Docker::API::InvalidParameter) } - it { expect{subject.logs( "id", invalid: true, skip_validation: true )}.not_to raise_error } + it { expect{subject.logs( "id", invalid: true )}.not_to raise_error } end end end \ No newline at end of file diff --git a/spec/endpoints/volume_spec.rb b/spec/endpoints/volume_spec.rb index 5c6569c..a7b2049 100644 --- a/spec/endpoints/volume_spec.rb +++ b/spec/endpoints/volume_spec.rb @@ -17,7 +17,7 @@ it { expect(subject.list(filters: {dangling: {"true": true}}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/volumes?filters={\"dangling\":{\"true\":true}}") } it { expect(subject.list(filters: {driver: {"local": true}}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/volumes?filters={\"driver\":{\"local\":true}}") } it { expect(subject.list(filters: {name: {"bridge": true}}).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/volumes?filters={\"name\":{\"bridge\":true}}") } - it { expect{subject.list( invalid: true )}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.list( invalid: true )}.not_to raise_error } end describe ".create" do @@ -25,7 +25,7 @@ it { expect(subject.create(Name: "dockerapi", Driver: "local").request_params[:method]).to eq(:post) } it { expect(subject.create(Name: "dockerapi", Driver: "local").request_params[:body]).to eq("{\"Name\":\"dockerapi\",\"Driver\":\"local\"}") } it { expect(subject.create(Name: "dockerapi", Driver: "local").request_params[:headers]["Content-Type"]).to eq("application/json") } - it { expect{subject.create( invalid: true )}.to raise_error(Docker::API::InvalidRequestBody) } + it { expect{subject.create( invalid: true )}.not_to raise_error } end describe ".details" do @@ -36,7 +36,7 @@ describe ".remove" do it { expect(subject.remove("dockerapi").request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/volumes/dockerapi") } it { expect(subject.remove("dockerapi").request_params[:method]).to eq(:delete) } - it { expect{subject.remove( "dockerapi", invalid: true )}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.remove( "dockerapi", invalid: true )}.not_to raise_error } end describe ".prune" do @@ -44,7 +44,7 @@ it { expect(subject.prune.request_params[:method]).to eq(:post) } it { expect(subject.prune( filters: {label: {"key": true}} ).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/volumes/prune?filters={\"label\":{\"key\":true}}") } it { expect(subject.prune( filters: {label: {"key=value": true}} ).request_params[:path]).to eq("/v#{Docker::API::API_VERSION}/volumes/prune?filters={\"label\":{\"key=value\":true}}") } - it { expect{subject.prune( invalid: true )}.to raise_error(Docker::API::InvalidParameter) } + it { expect{subject.prune( invalid: true )}.not_to raise_error } end end end \ No newline at end of file diff --git a/spec/misc/connection_spec.rb b/spec/misc/connection_spec.rb index c9edb50..c3b87ef 100644 --- a/spec/misc/connection_spec.rb +++ b/spec/misc/connection_spec.rb @@ -2,7 +2,7 @@ it { expect(described_class.new).not_to be nil } it { expect(described_class.new.inspect).to match(/socket_key=\"unix:\/\/\/var\/run\/docker.sock\"/) } it { expect(described_class.new("http://localhost:2375").inspect).to match(/socket_key=\"http:\/\/localhost:2375\"/) } - it { expect{Docker::API::System.new(Excon.new("http://localhost:2375"))}.to raise_error(Docker::API::Error, "Expected connection to be a Docker::API::Connection class") } + it { expect{Docker::API::System.new(Excon.new("http://localhost:2375"))}.to raise_error(StandardError, "Expected connection to be a Docker::API::Connection class") } context "with stubs" do subject {Docker::API::System.new(stub_connection)}