Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stdlib test for Resolv::Hosts by removing /etc/hosts dependency #779

Conversation

pocke
Copy link
Member

@pocke pocke commented Sep 5, 2021

This PR removes dependency to /etc/hosts content from Resolv::Hosts stdlib test.

Problem

Resolv::Hosts test depended on /etc/hosts content. The test failed on my environment because /etc/hosts is empty.

$ cat /etc/hosts
# Static table lookup for hostnames.
# See hosts(5) for details.

$ bundle exec ruby -Ilib bin/test_runner.rb test/stdlib/resolv/Hosts_test.rb
⚠️⚠️⚠️⚠️ stdlib test assumes Ruby 3.0 but RUBY_VERSION==3.1.0 ⚠️⚠️⚠️⚠️
Loaded suite bin/test_runner
Started
..E
===============================================================================
Error: test_getaddress(ResolvHostsInstanceTest): Resolv::ResolvError: /etc/hosts has no name: localhost
/home/pocke/.rbenv/versions/trunk/lib/ruby/3.1.0/resolv.rb:220:in `getaddress'
/home/pocke/ghq/github.com/ruby/rbs/test/stdlib/test_helper.rb:84:in `block (2 levels) in wrapped_object'
/home/pocke/ghq/github.com/ruby/rbs/test/stdlib/test_helper.rb:247:in `assert_send_type'
test/stdlib/resolv/Hosts_test.rb:24:in `test_getaddress'
     21:   end
     22: 
     23:   def test_getaddress
  => 24:     assert_send_type "(String) -> String",
     25:       hosts, :getaddress, "localhost"
     26:   end
     27: 
===============================================================================
.E
===============================================================================
Error: test_getname(ResolvHostsInstanceTest): Resolv::ResolvError: /etc/hosts has no address: 127.0.0.1
/home/pocke/.rbenv/versions/trunk/lib/ruby/3.1.0/resolv.rb:245:in `getname'
/home/pocke/ghq/github.com/ruby/rbs/test/stdlib/test_helper.rb:84:in `block (2 levels) in wrapped_object'
/home/pocke/ghq/github.com/ruby/rbs/test/stdlib/test_helper.rb:247:in `assert_send_type'
test/stdlib/resolv/Hosts_test.rb:34:in `test_getname'
     31:   end
     32: 
     33:   def test_getname
  => 34:     assert_send_type "(String) -> String",
     35:       hosts, :getname, "127.0.0.1"
     36:   end
     37: 
===============================================================================
.
Finished in 0.003496298 seconds.
-------------------------------------------------------------------------------
6 tests, 12 assertions, 0 failures, 2 errors, 0 pendings, 0 omissions, 0 notifications
66.6667% passed
-------------------------------------------------------------------------------
1716.10 tests/s, 3432.20 assertions/s

Solution

Resolv::Hosts.new receives a path to the hosts file, the default is /etc/hosts. This patch creates a tempfile instead of /etc/hosts.

@soutaro soutaro merged commit c19ec8c into ruby:master Sep 5, 2021
@pocke pocke deleted the Fix_stdlib_test_for_Resolv__Hosts_by_removing__etc_hosts_dependency branch September 5, 2021 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants