From e63148c3a6c6e073132a87ecc57fd41934e51031 Mon Sep 17 00:00:00 2001 From: Alysson Costa Date: Sun, 17 Aug 2025 14:36:41 -0400 Subject: [PATCH 01/17] Add E2E tests --- .github/workflows/ci.yml | 4 +++ spec/e2e/e2e_spec.rb | 60 +++++++++++++++++++++++++++++++++++ spec/endpoints/system_spec.rb | 12 +++---- spec/spec_helper.rb | 2 ++ 4 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 spec/e2e/e2e_spec.rb diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f716f3..3839cda 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,3 +17,7 @@ jobs: run: bundle install - name: Run unit tests run: rspec + - name: Install Docker + run: curl https://get.docker.com | sh + - name: Run E2E tests + run: rspec --tag e2e \ No newline at end of file diff --git a/spec/e2e/e2e_spec.rb b/spec/e2e/e2e_spec.rb new file mode 100644 index 0000000..2d03419 --- /dev/null +++ b/spec/e2e/e2e_spec.rb @@ -0,0 +1,60 @@ +require "digest" + +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:alpine3.22-slim", 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(403) } + 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:alpine" ).status).to be(200) end + it "inspects the image" do expect(image.details( "nginx:alpine3.22-slim" ).json).to be_kind_of(Hash) end + it "tags the image" do expect(image.tag("nginx:alpine", repo: "localhost/dockerapi").status).to be(201) end + it "removes an image" do expect(image.remove("nginx:alpine").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 "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(Digest::MD5.file("./html.tar").hexdigest).to match(/9043af123b66581466211a9e6dd0c175/) 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 diff --git a/spec/endpoints/system_spec.rb b/spec/endpoints/system_spec.rb index 1b1c106..30d16e8 100644 --- a/spec/endpoints/system_spec.rb +++ b/spec/endpoints/system_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6aab492..c07e810 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 From 2f361a235bccae923da17406c42b26d4b916877d Mon Sep 17 00:00:00 2001 From: Alysson Costa Date: Sun, 17 Aug 2025 14:43:42 -0400 Subject: [PATCH 02/17] Fix values --- spec/e2e/e2e_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/e2e/e2e_spec.rb b/spec/e2e/e2e_spec.rb index 2d03419..15ea1ad 100644 --- a/spec/e2e/e2e_spec.rb +++ b/spec/e2e/e2e_spec.rb @@ -31,7 +31,7 @@ end describe "Misc of requests that are expected to fail" do - it { expect(image.create(fromImage: "doesn-exist:latest").status).to eq(403) } + 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) } @@ -51,7 +51,7 @@ it "starts container" do expect(container.start("dockerapi1").status).to be(204) 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(Digest::MD5.file("./html.tar").hexdigest).to match(/9043af123b66581466211a9e6dd0c175/) end + it "verifies the content of the copied file" do expect(Digest::MD5.file("./html.tar").hexdigest).to match(/c3e1d9b10a9f397e745d312505242615/) 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 From 3a1aba6ac2bc9ddfa17b6a38b241abd18a5d329b Mon Sep 17 00:00:00 2001 From: Alysson Costa Date: Sun, 17 Aug 2025 14:44:27 -0400 Subject: [PATCH 03/17] Remove docker install --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3839cda..b19fe57 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,5 @@ jobs: run: bundle install - name: Run unit tests run: rspec - - name: Install Docker - run: curl https://get.docker.com | sh - name: Run E2E tests run: rspec --tag e2e \ No newline at end of file From 285f07e44d96f03407bcc6bd3c4d419d261c7b7c Mon Sep 17 00:00:00 2001 From: Alysson Costa Date: Fri, 22 Aug 2025 14:27:31 -0400 Subject: [PATCH 04/17] Fix stub for service --- spec/endpoints/service_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/endpoints/service_spec.rb b/spec/endpoints/service_spec.rb index 89a7f92..76e0111 100644 --- a/spec/endpoints/service_spec.rb +++ b/spec/endpoints/service_spec.rb @@ -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) } From 6cea5762b030acd623c82fa364c0a9f1e9c9ae39 Mon Sep 17 00:00:00 2001 From: Alysson Costa Date: Fri, 22 Aug 2025 15:51:31 -0400 Subject: [PATCH 05/17] WIP E2E test --- spec/e2e/e2e_spec.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/spec/e2e/e2e_spec.rb b/spec/e2e/e2e_spec.rb index 15ea1ad..b75c46a 100644 --- a/spec/e2e/e2e_spec.rb +++ b/spec/e2e/e2e_spec.rb @@ -1,12 +1,13 @@ require "digest" RSpec.describe "End-to-end test", e2e: true do + let(:sha){ "nginx:sha256@94f1c83ea210e0568f87884517b4fe9a39c74b7677e0ad3de72700cfa3da7268" } before(:all) do end after(:all) do Docker::API::Image.new.remove("localhost/dockerapi", force: true) - Docker::API::Image.new.remove("nginx:alpine3.22-slim", force: true) + Docker::API::Image.new.remove(image, force: true) File.delete("./html.tar") end container = Docker::API::Container.new @@ -42,13 +43,14 @@ end describe "Basic workflow" do - it "downloads an image" do expect(image.create( fromImage: "nginx:alpine" ).status).to be(200) end - it "inspects the image" do expect(image.details( "nginx:alpine3.22-slim" ).json).to be_kind_of(Hash) end - it "tags the image" do expect(image.tag("nginx:alpine", repo: "localhost/dockerapi").status).to be(201) end - it "removes an image" do expect(image.remove("nginx:alpine").status).to be(200) end + it "downloads an image" do expect(image.create( fromImage: sha ).status).to be(200) end + it "inspects the image" do expect(image.details( sha ).json).to be_kind_of(Hash) end + it "tags the image" do expect(image.tag(sha, repo: "localhost/dockerapi").status).to be(201) end + it "removes an image" do expect(image.remove(sha).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(Digest::MD5.file("./html.tar").hexdigest).to match(/c3e1d9b10a9f397e745d312505242615/) end From 9d9daec37157bc68b438d97669bc700d080b1326 Mon Sep 17 00:00:00 2001 From: Alysson Costa Date: Fri, 22 Aug 2025 15:53:08 -0400 Subject: [PATCH 06/17] WIP E2E test --- spec/e2e/e2e_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/e2e/e2e_spec.rb b/spec/e2e/e2e_spec.rb index b75c46a..f0dacad 100644 --- a/spec/e2e/e2e_spec.rb +++ b/spec/e2e/e2e_spec.rb @@ -1,7 +1,6 @@ require "digest" RSpec.describe "End-to-end test", e2e: true do - let(:sha){ "nginx:sha256@94f1c83ea210e0568f87884517b4fe9a39c74b7677e0ad3de72700cfa3da7268" } before(:all) do end @@ -10,6 +9,7 @@ Docker::API::Image.new.remove(image, force: true) File.delete("./html.tar") end + sha = "nginx:sha256@94f1c83ea210e0568f87884517b4fe9a39c74b7677e0ad3de72700cfa3da7268" container = Docker::API::Container.new image = Docker::API::Image.new volume = Docker::API::Volume.new From 5c828c826a505f6cdc9c470d1d87f84259df0a52 Mon Sep 17 00:00:00 2001 From: Alysson Costa Date: Fri, 22 Aug 2025 15:55:13 -0400 Subject: [PATCH 07/17] WIP E2E test --- spec/e2e/e2e_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/e2e/e2e_spec.rb b/spec/e2e/e2e_spec.rb index f0dacad..936142e 100644 --- a/spec/e2e/e2e_spec.rb +++ b/spec/e2e/e2e_spec.rb @@ -43,7 +43,7 @@ end describe "Basic workflow" do - it "downloads an image" do expect(image.create( fromImage: sha ).status).to be(200) end + 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( sha ).json).to be_kind_of(Hash) end it "tags the image" do expect(image.tag(sha, repo: "localhost/dockerapi").status).to be(201) end it "removes an image" do expect(image.remove(sha).status).to be(200) end From 4620e09ebecd023d9219d831f49e8634cedb9056 Mon Sep 17 00:00:00 2001 From: Alysson Costa Date: Fri, 22 Aug 2025 15:55:57 -0400 Subject: [PATCH 08/17] WIP E2E test --- spec/e2e/e2e_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/e2e/e2e_spec.rb b/spec/e2e/e2e_spec.rb index 936142e..cf8d8e1 100644 --- a/spec/e2e/e2e_spec.rb +++ b/spec/e2e/e2e_spec.rb @@ -6,7 +6,7 @@ end after(:all) do Docker::API::Image.new.remove("localhost/dockerapi", force: true) - Docker::API::Image.new.remove(image, force: true) + Docker::API::Image.new.remove(sha, force: true) File.delete("./html.tar") end sha = "nginx:sha256@94f1c83ea210e0568f87884517b4fe9a39c74b7677e0ad3de72700cfa3da7268" From 45eb979d925681409451608b054d75a90885e832 Mon Sep 17 00:00:00 2001 From: Alysson Costa Date: Fri, 22 Aug 2025 15:57:10 -0400 Subject: [PATCH 09/17] WIP E2E test --- spec/e2e/e2e_spec.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/spec/e2e/e2e_spec.rb b/spec/e2e/e2e_spec.rb index cf8d8e1..fd16936 100644 --- a/spec/e2e/e2e_spec.rb +++ b/spec/e2e/e2e_spec.rb @@ -6,10 +6,9 @@ end after(:all) do Docker::API::Image.new.remove("localhost/dockerapi", force: true) - Docker::API::Image.new.remove(sha, force: true) + Docker::API::Image.new.remove("nginx:sha256@94f1c83ea210e0568f87884517b4fe9a39c74b7677e0ad3de72700cfa3da7268", force: true) File.delete("./html.tar") end - sha = "nginx:sha256@94f1c83ea210e0568f87884517b4fe9a39c74b7677e0ad3de72700cfa3da7268" container = Docker::API::Container.new image = Docker::API::Image.new volume = Docker::API::Volume.new @@ -44,9 +43,9 @@ 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( sha ).json).to be_kind_of(Hash) end - it "tags the image" do expect(image.tag(sha, repo: "localhost/dockerapi").status).to be(201) end - it "removes an image" do expect(image.remove(sha).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 From cccff026fd63afbec38cac321b9f98bbef98b523 Mon Sep 17 00:00:00 2001 From: Alysson Costa Date: Fri, 22 Aug 2025 16:03:07 -0400 Subject: [PATCH 10/17] WIP E2E test --- spec/e2e/e2e_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/e2e/e2e_spec.rb b/spec/e2e/e2e_spec.rb index fd16936..cce4ec3 100644 --- a/spec/e2e/e2e_spec.rb +++ b/spec/e2e/e2e_spec.rb @@ -6,7 +6,7 @@ end after(:all) do Docker::API::Image.new.remove("localhost/dockerapi", force: true) - Docker::API::Image.new.remove("nginx:sha256@94f1c83ea210e0568f87884517b4fe9a39c74b7677e0ad3de72700cfa3da7268", force: true) + Docker::API::Image.new.remove("nginx@sha256:94f1c83ea210e0568f87884517b4fe9a39c74b7677e0ad3de72700cfa3da7268", force: true) File.delete("./html.tar") end container = Docker::API::Container.new @@ -42,10 +42,10 @@ 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 "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 From 4a8f9bf457c71d7c781924ee96b9ad0314a5a10b Mon Sep 17 00:00:00 2001 From: Alysson Costa Date: Fri, 22 Aug 2025 16:03:39 -0400 Subject: [PATCH 11/17] WIP E2E test --- spec/e2e/e2e_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/e2e/e2e_spec.rb b/spec/e2e/e2e_spec.rb index cce4ec3..88faba3 100644 --- a/spec/e2e/e2e_spec.rb +++ b/spec/e2e/e2e_spec.rb @@ -52,7 +52,7 @@ 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(Digest::MD5.file("./html.tar").hexdigest).to match(/c3e1d9b10a9f397e745d312505242615/) end + it "verifies the content of the copied file" do expect(Digest::MD5.file("./html.tar").hexdigest).to match(/0c3e863136f8c4e3faa1a6d1d4f3dbd0/) 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 From 8d49b6dd07ce5d705548b721175431fea483ebe8 Mon Sep 17 00:00:00 2001 From: Alysson Costa Date: Fri, 22 Aug 2025 16:06:13 -0400 Subject: [PATCH 12/17] WIP E2E test --- spec/e2e/e2e_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/e2e/e2e_spec.rb b/spec/e2e/e2e_spec.rb index 88faba3..ddbcf7b 100644 --- a/spec/e2e/e2e_spec.rb +++ b/spec/e2e/e2e_spec.rb @@ -52,7 +52,7 @@ 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(Digest::MD5.file("./html.tar").hexdigest).to match(/0c3e863136f8c4e3faa1a6d1d4f3dbd0/) 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 From 1eb68b175dbe554c6af2fb0eb1fa0492e60b562a Mon Sep 17 00:00:00 2001 From: Alysson Costa Date: Fri, 22 Aug 2025 16:06:24 -0400 Subject: [PATCH 13/17] WIP E2E test --- spec/e2e/e2e_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/e2e/e2e_spec.rb b/spec/e2e/e2e_spec.rb index ddbcf7b..b1caeab 100644 --- a/spec/e2e/e2e_spec.rb +++ b/spec/e2e/e2e_spec.rb @@ -1,5 +1,3 @@ -require "digest" - RSpec.describe "End-to-end test", e2e: true do before(:all) do From 6cf3823ef4223f379c35a25c06369c1a89156c3d Mon Sep 17 00:00:00 2001 From: Alysson Costa Date: Fri, 22 Aug 2025 16:08:09 -0400 Subject: [PATCH 14/17] WIP E2E test --- spec/e2e/e2e_spec.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/spec/e2e/e2e_spec.rb b/spec/e2e/e2e_spec.rb index b1caeab..b4ef9cc 100644 --- a/spec/e2e/e2e_spec.rb +++ b/spec/e2e/e2e_spec.rb @@ -4,9 +4,10 @@ end after(:all) do Docker::API::Image.new.remove("localhost/dockerapi", force: true) - Docker::API::Image.new.remove("nginx@sha256:94f1c83ea210e0568f87884517b4fe9a39c74b7677e0ad3de72700cfa3da7268", force: true) + Docker::API::Image.new.remove(image_ref, force: true) File.delete("./html.tar") end + image_ref = "nginx@sha256:94f1c83ea210e0568f87884517b4fe9a39c74b7677e0ad3de72700cfa3da7268" container = Docker::API::Container.new image = Docker::API::Image.new volume = Docker::API::Volume.new @@ -40,10 +41,10 @@ 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 "downloads an image" do expect(image.create( fromImage: image_ref ).status).to be(200) end + it "inspects the image" do expect(image.details( image_ref ).json).to be_kind_of(Hash) end + it "tags the image" do expect(image.tag(image_ref, repo: "localhost/dockerapi").status).to be(201) end + it "removes an image" do expect(image.remove(image_ref).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 From 24668dbd323fd46dd4cc48271a1d3b3f7220f716 Mon Sep 17 00:00:00 2001 From: Alysson Costa Date: Fri, 22 Aug 2025 16:09:07 -0400 Subject: [PATCH 15/17] WIP E2E test --- spec/e2e/e2e_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/e2e/e2e_spec.rb b/spec/e2e/e2e_spec.rb index b4ef9cc..a374966 100644 --- a/spec/e2e/e2e_spec.rb +++ b/spec/e2e/e2e_spec.rb @@ -1,4 +1,5 @@ RSpec.describe "End-to-end test", e2e: true do + let(:image_ref) { "nginx@sha256:94f1c83ea210e0568f87884517b4fe9a39c74b7677e0ad3de72700cfa3da7268" } before(:all) do end @@ -7,7 +8,7 @@ Docker::API::Image.new.remove(image_ref, force: true) File.delete("./html.tar") end - image_ref = "nginx@sha256:94f1c83ea210e0568f87884517b4fe9a39c74b7677e0ad3de72700cfa3da7268" + container = Docker::API::Container.new image = Docker::API::Image.new volume = Docker::API::Volume.new From 378fdf194a3556a56eaff5d714812c555a1c7c04 Mon Sep 17 00:00:00 2001 From: Alysson Costa Date: Fri, 22 Aug 2025 16:09:46 -0400 Subject: [PATCH 16/17] WIP E2E test --- spec/e2e/e2e_spec.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/spec/e2e/e2e_spec.rb b/spec/e2e/e2e_spec.rb index a374966..b1caeab 100644 --- a/spec/e2e/e2e_spec.rb +++ b/spec/e2e/e2e_spec.rb @@ -1,14 +1,12 @@ RSpec.describe "End-to-end test", e2e: true do - let(:image_ref) { "nginx@sha256:94f1c83ea210e0568f87884517b4fe9a39c74b7677e0ad3de72700cfa3da7268" } before(:all) do end after(:all) do Docker::API::Image.new.remove("localhost/dockerapi", force: true) - Docker::API::Image.new.remove(image_ref, 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 @@ -42,10 +40,10 @@ end describe "Basic workflow" do - it "downloads an image" do expect(image.create( fromImage: image_ref ).status).to be(200) end - it "inspects the image" do expect(image.details( image_ref ).json).to be_kind_of(Hash) end - it "tags the image" do expect(image.tag(image_ref, repo: "localhost/dockerapi").status).to be(201) end - it "removes an image" do expect(image.remove(image_ref).status).to be(200) end + 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 From aa7b396990dfacecc8df7f00145b3f4b66968aae Mon Sep 17 00:00:00 2001 From: Alysson Costa Date: Fri, 22 Aug 2025 16:13:16 -0400 Subject: [PATCH 17/17] Documentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 51c1ddf..036d769 100644 --- a/README.md +++ b/README.md @@ -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.