Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ jobs:
run: bundle install
- name: Run unit tests
run: rspec
- name: Run E2E tests
run: rspec --tag e2e
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ The default blocks can be found in `Docker::API::Base`.

## Development

Run `rake spec` to run the tests.
Run `rspec` to run the unit tests. Run `rspec --tag e2e` to run End-to-End tests (requires Docker locally).

Run `bin/console` for an interactive prompt that will allow you to experiment.

Expand Down
59 changes: 59 additions & 0 deletions spec/e2e/e2e_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
RSpec.describe "End-to-end test", e2e: true do
before(:all) do

end
after(:all) do
Docker::API::Image.new.remove("localhost/dockerapi", force: true)
Docker::API::Image.new.remove("nginx@sha256:94f1c83ea210e0568f87884517b4fe9a39c74b7677e0ad3de72700cfa3da7268", force: true)
File.delete("./html.tar")
end
container = Docker::API::Container.new
image = Docker::API::Image.new
volume = Docker::API::Volume.new
system = Docker::API::System.new

describe "System calls" do
it { expect(system.ping.status).to eq(200) }
it { expect(system.info.status).to eq(200) }
it { expect(system.info.success?).to eq(true) }
it { expect(system.info.json).to be_kind_of(Hash) }
it { expect(system.info.path).to eq("/v#{Docker::API::API_VERSION}/info") }
it { expect(system.version.status).to eq(200) }
it { expect(system.version.success?).to eq(true) }
it { expect(system.version.json).to be_kind_of(Hash) }
it { expect(system.version.path).to eq("/v#{Docker::API::API_VERSION}/version") }
it { expect(system.df.status).to eq(200) }
it { expect(system.df.success?).to eq(true) }
it { expect(system.df.json).to be_kind_of(Hash) }
it { expect(system.df.path).to eq("/v#{Docker::API::API_VERSION}/system/df") }
end

describe "Misc of requests that are expected to fail" do
it { expect(image.create(fromImage: "doesn-exist:latest").status).to eq(404) }
it { expect(image.create(fromSrc: "http://404").status).to eq(500) }
it { expect(image.details("doesn-exist").status).to eq(404) }
it { expect(image.tag("doesn-exist", repo: "dockerapi/tag").status).to eq(404) }
it { expect(image.remove("doesn-exist").status).to eq(404) }
it { expect(container.create( {platform: "os/no-arch"}, {Image: "image"}).status).to eq(404) }
it { expect(container.start("doesn-exist").status).to eq(404 )}
it { expect(container.remove("doesn-exist").status).to eq(404) }
end

describe "Basic workflow" do
it "downloads an image" do expect(image.create( fromImage: "nginx@sha256:94f1c83ea210e0568f87884517b4fe9a39c74b7677e0ad3de72700cfa3da7268" ).status).to be(200) end
it "inspects the image" do expect(image.details( "nginx@sha256:94f1c83ea210e0568f87884517b4fe9a39c74b7677e0ad3de72700cfa3da7268" ).json).to be_kind_of(Hash) end
it "tags the image" do expect(image.tag("nginx@sha256:94f1c83ea210e0568f87884517b4fe9a39c74b7677e0ad3de72700cfa3da7268", repo: "localhost/dockerapi").status).to be(201) end
it "removes an image" do expect(image.remove("nginx@sha256:94f1c83ea210e0568f87884517b4fe9a39c74b7677e0ad3de72700cfa3da7268").status).to be(200) end
it "creates a volume" do expect(volume.create( Name:"dockerapi" ).status).to be(201) end
it "creates a container" do expect(container.create( {name: "dockerapi1"}, {Image: "localhost/dockerapi", HostConfig: {Binds: ["dockerapi:/usr/share/nginx/html"], PortBindings: {"80/tcp": [ {HostIp: "0.0.0.0", HostPort: "3080"} ]}}}).status).to be(201) end
it "starts container" do expect(container.start("dockerapi1").status).to be(204) end
it "sleeps to wait container" do sleep 2 end
it "requests the container on port 3080" do expect(Excon.get('http://127.0.0.1:3080').body).to match(/Welcome to nginx!/) end
it "copies content from container" do expect(container.get_archive("dockerapi1", "./html.tar", path: "/usr/share/nginx/html/").status).to be(200) end
it "verifies the content of the copied file" do expect(File.exist?("./html.tar")).to be(true) end
it "stops container" do expect(container.stop("dockerapi1").status).to be(204) end
it "waits for the container to stop" do expect(container.wait("dockerapi1").status).to be(200) end
it "removes container" do expect(container.remove("dockerapi1").status).to be(204) end
it "removes a volume" do expect(volume.remove("dockerapi").status).to be(204) end
end
end
2 changes: 1 addition & 1 deletion spec/endpoints/service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RSpec.describe Docker::API::Service do
subject { described_class.new }
subject { described_class.new(stub_connection) }

it { is_expected.to respond_to(:list) }
it { is_expected.to respond_to(:details) }
Expand Down
12 changes: 5 additions & 7 deletions spec/endpoints/system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@

describe ".events" do
let(:now) { Time.now.to_i }
subject { described_class.new.events(until: now ) }
it { expect(described_class.new).to respond_to(:events) }
it { expect(subject.status).to eq(200) }
it { expect(subject.success?).to eq(true) }
it { expect(subject.path).to eq("/v#{Docker::API::API_VERSION}/events?until=#{now}") }
it { expect{described_class.new.events(invalid: true)}.to raise_error(Docker::API::InvalidParameter) }
it { expect{described_class.new.events(invalid: true, skip_validation: false)}.to raise_error(Docker::API::InvalidParameter) }
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) }
end

describe ".df" do
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!

config.filter_run_excluding :e2e

config.expect_with :rspec do |c|
c.syntax = :expect
end
Expand Down