Skip to content

Commit

Permalink
Fix resolv.conf being saved outside of the test directory
Browse files Browse the repository at this point in the history
`NameResolverTest` uses the `in_tmp/2` helper function to scope tests to
temporary directories for that specific test. It includes a call to `File.cd!/1`
and deals with the resolv.conf file generated relatively. However, using
`start_supervised!/2` may not be changed into the tmp test directory and
`fake_resolv.conf` files could be created in the root of the project.

This makes an absolute path to the resolv.conf when starting the NameResolver process
to prevent those files from being generated in the root
  • Loading branch information
jjcarstens authored and fhunleth committed Aug 3, 2022
1 parent 2c92df9 commit d805024
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions test/vintage_net/name_resolver_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule VintageNet.NameResolverTest do
use VintageNetTest.Case
use VintageNetTest.Case, async: true
import ExUnit.CaptureLog
alias VintageNet.NameResolver

Expand All @@ -23,7 +23,7 @@ defmodule VintageNet.NameResolverTest do

test "empty resolvconf is empty", context do
in_tmp(context.test, fn ->
start_supervised!({NameResolver, [resolvconf: @resolvconf_path]})
start_supervised!({NameResolver, [resolvconf: Path.join(File.cwd!(), @resolvconf_path)]})
assert File.exists?(@resolvconf_path)

assert File.read!(@resolvconf_path) ==
Expand All @@ -35,7 +35,7 @@ defmodule VintageNet.NameResolverTest do

test "adding one interface", context do
in_tmp(context.test, fn ->
start_supervised!({NameResolver, [resolvconf: @resolvconf_path]})
start_supervised!({NameResolver, [resolvconf: Path.join(File.cwd!(), @resolvconf_path)]})
NameResolver.setup("eth0", "example.com", ["1.1.1.1", "8.8.8.8"])

contents = File.read!(@resolvconf_path)
Expand All @@ -58,7 +58,7 @@ defmodule VintageNet.NameResolverTest do

test "adding two interfaces", context do
in_tmp(context.test, fn ->
start_supervised!({NameResolver, [resolvconf: @resolvconf_path]})
start_supervised!({NameResolver, [resolvconf: Path.join(File.cwd!(), @resolvconf_path)]})
NameResolver.setup("eth0", "example.com", ["1.1.1.1", "8.8.8.8"])
NameResolver.setup("wlan0", "example2.com", ["1.1.1.2", "8.8.8.9"])

Expand Down Expand Up @@ -92,7 +92,7 @@ defmodule VintageNet.NameResolverTest do

test "clearing all interfaces", context do
in_tmp(context.test, fn ->
start_supervised!({NameResolver, [resolvconf: @resolvconf_path]})
start_supervised!({NameResolver, [resolvconf: Path.join(File.cwd!(), @resolvconf_path)]})
NameResolver.setup("eth0", "example.com", ["1.1.1.1", "8.8.8.8"])
NameResolver.setup("wlan0", "example2.com", ["1.1.1.2", "8.8.8.9"])
NameResolver.clear_all()
Expand All @@ -106,7 +106,7 @@ defmodule VintageNet.NameResolverTest do

test "tuple IP addresses", context do
in_tmp(context.test, fn ->
start_supervised!({NameResolver, [resolvconf: @resolvconf_path]})
start_supervised!({NameResolver, [resolvconf: Path.join(File.cwd!(), @resolvconf_path)]})
NameResolver.setup("eth0", "example.com", [{1, 1, 1, 1}])

contents = File.read!(@resolvconf_path)
Expand All @@ -128,7 +128,7 @@ defmodule VintageNet.NameResolverTest do

test "no search domain", context do
in_tmp(context.test, fn ->
start_supervised!({NameResolver, [resolvconf: @resolvconf_path]})
start_supervised!({NameResolver, [resolvconf: Path.join(File.cwd!(), @resolvconf_path)]})
NameResolver.setup("eth0", nil, [{1, 1, 1, 1}])

contents = File.read!(@resolvconf_path)
Expand All @@ -152,7 +152,7 @@ defmodule VintageNet.NameResolverTest do
start_supervised!(
{NameResolver,
[
resolvconf: @resolvconf_path,
resolvconf: Path.join(File.cwd!(), @resolvconf_path),
additional_name_servers: [{8, 8, 8, 8}, {1, 2}]
]}
)
Expand All @@ -178,7 +178,7 @@ defmodule VintageNet.NameResolverTest do
start_supervised!(
{NameResolver,
[
resolvconf: @resolvconf_path,
resolvconf: Path.join(File.cwd!(), @resolvconf_path),
additional_name_servers: [{8, 8, 8, 8}, {1, 1, 1, 1}]
]}
)
Expand Down Expand Up @@ -218,7 +218,7 @@ defmodule VintageNet.NameResolverTest do

test "name servers updated in property table", context do
in_tmp(context.test, fn ->
start_supervised!({NameResolver, [resolvconf: @resolvconf_path]})
start_supervised!({NameResolver, [resolvconf: Path.join(File.cwd!(), @resolvconf_path)]})

NameResolver.setup("eth0", nil, [{4, 4, 4, 4}, {3, 3, 3, 3}])

Expand Down

0 comments on commit d805024

Please sign in to comment.