diff --git a/test/unit/plugins/guests/redhat/cap/change_host_name_test.rb b/test/unit/plugins/guests/redhat/cap/change_host_name_test.rb index 10f43a359..b85802e94 100644 --- a/test/unit/plugins/guests/redhat/cap/change_host_name_test.rb +++ b/test/unit/plugins/guests/redhat/cap/change_host_name_test.rb @@ -39,5 +39,32 @@ describe "VagrantPlugins::GuestRedHat::Cap::ChangeHostName" do cap.change_host_name(machine, name) expect(comm.received_commands.size).to eq(1) end + + context "restarts the network" do + it "uses systemctl and NetworkManager.service" do + comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1) + comm.stub_command("test -f /usr/bin/systemctl && systemctl -q is-active NetworkManager.service", exit_code: 0) + cap.change_host_name(machine, name) + expect(comm.received_commands[1]).to match(/systemctl restart NetworkManager.service/) + end + + it "uses the service command" do + comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1) + comm.stub_command("test -f /usr/bin/systemctl && systemctl -q is-active NetworkManager.service", exit_code: 1) + comm.stub_command("test -f /etc/init.d/network", exit_code: 0) + cap.change_host_name(machine, name) + expect(comm.received_commands[1]).to match(/service network restart/) + end + end + + context "cannot restart the network" do + it "prints cannot restart message" do + comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1) + comm.stub_command("test -f /usr/bin/systemctl && systemctl -q is-active NetworkManager.service", exit_code: 1) + comm.stub_command("test -f /etc/init.d/network", exit_code: 1) + cap.change_host_name(machine, name) + expect(comm.received_commands[1]).to match(/printf "Could not restart the network to set the new hostname!/) + end + end end end