diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f716f3..b19fe57 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,3 +17,5 @@ jobs: run: bundle install - name: Run unit tests run: rspec + - name: Run E2E tests + run: rspec --tag e2e \ No newline at end of file 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. diff --git a/spec/e2e/e2e_spec.rb b/spec/e2e/e2e_spec.rb new file mode 100644 index 0000000..b1caeab --- /dev/null +++ b/spec/e2e/e2e_spec.rb @@ -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 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) } 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