|
10 | 10 | allow(Facter::Core::Execution).to receive(:execute).and_call_original
|
11 | 11 |
|
12 | 12 | if Facter.value(:kernel) == 'windows'
|
13 |
| - docker_command = 'powershell -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -c docker' |
| 13 | + @docker_command = 'powershell -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -c docker' |
14 | 14 | allow(Facter::Core::Execution).to receive(:which).with('dhcpcd').and_return('C:\Windows\dhcpd.exe')
|
15 | 15 | allow(Facter::Core::Execution).to receive(:which).with('route').and_return('C:\Windows\System32\ROUTE.EXE')
|
16 | 16 | allow(Facter::Core::Execution).to receive(:which).with('docker').and_return('C:\Program Files\Docker\docker.exe')
|
17 | 17 | else
|
18 |
| - docker_command = 'docker' |
| 18 | + @docker_command = 'docker' |
19 | 19 | allow(Facter::Core::Execution).to receive(:which).with('route').and_return('/usr/bin/route')
|
20 | 20 | allow(Facter::Core::Execution).to receive(:which).with('dhcpcd').and_return('/usr/bin/dhcpd')
|
21 | 21 | allow(Facter::Core::Execution).to receive(:which).with('docker').and_return('/usr/bin/docker')
|
22 | 22 | end
|
23 | 23 | docker_info = File.read(fixtures('facts', 'docker_info'))
|
24 |
| - allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} info --format '{{json .}}'", timeout: 90).and_return(docker_info) |
| 24 | + allow(Facter::Core::Execution).to receive(:execute).with("#{@docker_command} info --format '{{json .}}'", timeout: 90).and_return(docker_info) |
25 | 25 | processors = File.read(fixtures('facts', 'processors'))
|
26 | 26 | allow(Facter.fact(:processors)).to receive(:value).and_return(JSON.parse(processors))
|
27 | 27 | docker_version = File.read(fixtures('facts', 'docker_version'))
|
28 |
| - allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} version --format '{{json .}}'", timeout: 90).and_return(docker_version) |
| 28 | + allow(Facter::Core::Execution).to receive(:execute).with("#{@docker_command} version --format '{{json .}}'", timeout: 90).and_return(docker_version) |
29 | 29 | docker_network_list = File.read(fixtures('facts', 'docker_network_list'))
|
30 |
| - allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} network ls | tail -n +2", timeout: 90).and_return(docker_network_list) |
| 30 | + allow(Facter::Core::Execution).to receive(:execute).with("#{@docker_command} network ls | tail -n +2", timeout: 90).and_return(docker_network_list) |
31 | 31 | docker_network_names = []
|
32 | 32 | docker_network_list.each_line { |line| docker_network_names.push line.split[1] }
|
33 | 33 | docker_network_names.each do |network|
|
34 | 34 | inspect = File.read(fixtures('facts', "docker_network_inspect_#{network}"))
|
35 |
| - allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} network inspect #{network}", timeout: 90).and_return(inspect) |
| 35 | + allow(Facter::Core::Execution).to receive(:execute).with("#{@docker_command} network inspect #{network}", timeout: 90).and_return(inspect) |
36 | 36 | end
|
37 | 37 | docker_worker_token = File.read(fixtures('facts', 'docker_swarm_worker_token'))
|
38 |
| - allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} swarm join-token worker -q", timeout: 90).and_return(docker_worker_token.chomp) |
| 38 | + allow(Facter::Core::Execution).to receive(:execute).with("#{@docker_command} swarm join-token worker -q", timeout: 90).and_return(docker_worker_token.chomp) |
39 | 39 | docker_manager_token = File.read(fixtures('facts', 'docker_swarm_manager_token'))
|
40 |
| - allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} swarm join-token manager -q", timeout: 90).and_return(docker_manager_token.chomp) |
| 40 | + allow(Facter::Core::Execution).to receive(:execute).with("#{@docker_command} swarm join-token manager -q", timeout: 90).and_return(docker_manager_token.chomp) |
41 | 41 | end
|
42 | 42 | after(:each) { Facter.clear }
|
43 | 43 |
|
|
129 | 129 | )
|
130 | 130 | end
|
131 | 131 | end
|
| 132 | + |
| 133 | + describe 'docker swarm worker join-token with inactive swarm cluster' do |
| 134 | + before :each do |
| 135 | + docker_info = File.read(fixtures('facts', 'docker_info_swarm_inactive')) |
| 136 | + allow(Facter::Core::Execution).to receive(:execute).with("#{@docker_command} info --format '{{json .}}'", timeout: 90).and_return(docker_info) |
| 137 | + end |
| 138 | + it do |
| 139 | + expect(Facter.fact(:docker_worker_join_token).value).to be_nil |
| 140 | + end |
| 141 | + end |
| 142 | + |
| 143 | + describe 'docker swarm manager join-token with inactive swarm cluster' do |
| 144 | + before :each do |
| 145 | + docker_info = File.read(fixtures('facts', 'docker_info_swarm_inactive')) |
| 146 | + allow(Facter::Core::Execution).to receive(:execute).with("#{@docker_command} info --format '{{json .}}'", timeout: 90).and_return(docker_info) |
| 147 | + end |
| 148 | + |
| 149 | + it do |
| 150 | + expect(Facter.fact(:docker_manager_join_token).value).to be_nil |
| 151 | + end |
| 152 | + end |
132 | 153 | end
|
0 commit comments