Skip to content

Commit

Permalink
Skip test case for ipv6 when disable ipv6
Browse files Browse the repository at this point in the history
  • Loading branch information
taketo1113 committed Jan 27, 2024
1 parent c472504 commit 9bb2aa5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions spec/ddig/resolver/do53_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@

context "#lookup: ipv6" do
before(:each) do
skip unless enable_ipv6?

@ip = :ipv6
@nameservers = ['8.8.8.8', '2001:4860:4860::8888']

Expand Down
5 changes: 5 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

require "ddig"

# Load all Rspec support files
Dir['./spec/support/**/*.rb'].each { |file| require file }

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
Expand All @@ -12,4 +15,6 @@
config.expect_with :rspec do |c|
c.syntax = :expect
end

config.include Ddig::Ipv6Helper
end
20 changes: 20 additions & 0 deletions spec/support/ipv6_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Ddig
module Ipv6Helper
def enable_ipv6?
Socket.ip_address_list.each do |addrinfo|
if RUBY_VERSION <= '3.0'
# for ipaddr gem <= v1.2.2, Not support zone identifiers in IPv6 addresses
addr = IPAddr.new(addrinfo.ip_address.split('%').first)
else
addr = IPAddr.new(addrinfo.ip_address)
end

if addr.ipv6? && !addr.loopback? && !addr.link_local?
return true
end
end

return false
end
end
end

0 comments on commit 9bb2aa5

Please sign in to comment.