From 9bb2aa5b31a9a501a93abbeddbd01ad57148f591 Mon Sep 17 00:00:00 2001 From: Taketo Takashima Date: Sat, 27 Jan 2024 23:22:29 +0900 Subject: [PATCH] Skip test case for ipv6 when disable ipv6 --- spec/ddig/resolver/do53_spec.rb | 2 ++ spec/spec_helper.rb | 5 +++++ spec/support/ipv6_helper.rb | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 spec/support/ipv6_helper.rb diff --git a/spec/ddig/resolver/do53_spec.rb b/spec/ddig/resolver/do53_spec.rb index eb2906c..d454e4c 100644 --- a/spec/ddig/resolver/do53_spec.rb +++ b/spec/ddig/resolver/do53_spec.rb @@ -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'] diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b8f0e21..9c1e876 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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" @@ -12,4 +15,6 @@ config.expect_with :rspec do |c| c.syntax = :expect end + + config.include Ddig::Ipv6Helper end diff --git a/spec/support/ipv6_helper.rb b/spec/support/ipv6_helper.rb new file mode 100644 index 0000000..ab5b6fd --- /dev/null +++ b/spec/support/ipv6_helper.rb @@ -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