Skip to content

Commit

Permalink
add special matcher for docker api uri to exclude extra slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfiredrill committed May 21, 2023
1 parent 8779b14 commit 07f8fca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions spec/lib/docker_wrapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

describe DockerWrapper do
it "creates a new docker container" do
VCR.use_cassette "create_container" do
VCR.use_cassette "create_container", match_requests_on: [:method, :docker_api_uri_matcher] do
container = DockerWrapper.find_or_create 'mcfiredrill/icecast', 'coolradio_icecast'
expect(container.id).to_not eq nil
end
end

it "starts the container with ports exposed" do
VCR.use_cassette "start container" do
VCR.use_cassette "start container", match_requests_on: [:method, :docker_api_uri_matcher] do
container = DockerWrapper.find_or_create 'mcfiredrill/icecast', 'coolradio_icecast'
container.start
expect(container.host_port(8000)).to_not eq nil
Expand All @@ -18,7 +18,7 @@
end

it "sets the env" do
VCR.use_cassette "set_env" do
VCR.use_cassette "set_env", match_requests_on: [:method, :docker_api_uri_matcher] do
container = DockerWrapper.find_or_create 'mcfiredrill/icecast', 'coolradio_icecast_with_env', ["RADIO_NAME=coolradio"]
container.start
expect(container.env.include?("RADIO_NAME=coolradio")).to eq true
Expand Down
14 changes: 14 additions & 0 deletions spec/support/vcr_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def test_docker_uri
config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
config.hook_into :webmock # or :fakeweb

config.debug_logger = File.open("log/vcr.log", 'w')

config.define_cassette_placeholder("<DOCKER_HOST>") do
test_docker_uri
end
Expand Down Expand Up @@ -56,4 +58,16 @@ def test_docker_uri

uri_regex.match?(uri1.path) && uri_regex.match?(uri2.path)
end

config.register_request_matcher :docker_api_uri_matcher do |request_1, request_2|
uri_1 = URI(request_1.uri)
uri_2 = URI(request_2.uri)

# Remove consecutive slashes from the URI paths
path_1 = uri_1.path.gsub(/\/+/, '/')
path_2 = uri_2.path.gsub(/\/+/, '/')

# Compare the modified paths for equality
path_1 == path_2
end
end

0 comments on commit 07f8fca

Please sign in to comment.