Skip to content

Commit

Permalink
Issue vagrant-landrush#310 Using explicit sc.exe instead of sc
Browse files Browse the repository at this point in the history
- Using sc.exe avoids confusion with PowerShell's sc commandlet.
- Adding tests
  • Loading branch information
hferentschik committed Sep 3, 2018
1 parent 678cfa8 commit fd5e514
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
3 changes: 0 additions & 3 deletions .rubocop.yml
Expand Up @@ -8,6 +8,3 @@ AllCops:

Style/FrozenStringLiteralComment:
Enabled: false

Style/EndOfLine:
EnforcedStyle: lf
Expand Up @@ -145,8 +145,12 @@ def info(msg)
@env.ui.info("[landrush] #{msg}") unless @env.nil?
end

def wired_autoconfig_service_state
`sc query dot3svc`
end

def wired_autoconfig_service_running?
cmd_out = `sc query dot3svc`
cmd_out = wired_autoconfig_service_state
cmd_out =~ /\s*STATE\s+:\s+4\s+RUNNING/m
end

Expand Down
Expand Up @@ -6,6 +6,25 @@ module Windows
describe ConfigureVisibilityOnHost do
TEST_IP = '10.42.42.42'.freeze

DOT_3_SVC_RUNNING = 'SERVICE_NAME: dot3svc
TYPE : 30 WIN32
STATE : 4 RUNNING
(STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
'.freeze

DOT_3_SVC_STOPPED = 'SERVICE_NAME: dot3svc
TYPE : 30 WIN32
STATE : 1 STOPPED
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
'.freeze

before do
@vboxmanage_found = !Vagrant::Util::Which.which('VBoxManage').nil?
@has_admin_privileges = Landrush::Cap::Windows::ConfigureVisibilityOnHost.admin_mode?
Expand All @@ -32,13 +51,25 @@ module Windows
end
end

describe '#wired_autoconfig_service_running?' do
it 'service running' do
Landrush::Cap::Windows::ConfigureVisibilityOnHost.expects(:wired_autoconfig_service_state).returns(DOT_3_SVC_RUNNING)
assert ConfigureVisibilityOnHost.send(:wired_autoconfig_service_running?)
end

it 'service stopped' do
Landrush::Cap::Windows::ConfigureVisibilityOnHost.expects(:wired_autoconfig_service_state).returns(DOT_3_SVC_STOPPED)
refute ConfigureVisibilityOnHost.send(:wired_autoconfig_service_running?)
end
end

def network_state
`netsh interface ip show config`.split(/\n/).reject(&:empty?)
end

def get_network_name(old_network_state, new_network_state)
new_network_state.reject! { |line| old_network_state.include? line }
new_network_state[0].match(/.*\"(.*)\"$/).captures[0]
new_network_state[0].match(/.*"(.*)"$/).captures[0]
end

# Creates a test interface using VBoxMange and sets a known test IP
Expand Down

0 comments on commit fd5e514

Please sign in to comment.