blob: c7d28af6bddeba623cb77bac8334686e52c74569 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
require 'spec_helper'
describe Oxidized::Node do
before(:each) do
Oxidized.asetus = Asetus.new
Oxidized.setup_logger
Oxidized::Node.any_instance.stubs(:resolve_repo)
Oxidized::Node.any_instance.stubs(:resolve_output)
@node = Oxidized::Node.new(name: 'example.com',
input: 'ssh',
output: 'git',
model: 'junos',
username: 'alma',
password: 'armud',
prompt: 'test_prompt')
end
describe '#new' do
it 'should resolve input' do
@node.input[0].to_s.split('::')[1].must_equal 'SSH'
end
it 'should resolve model' do
@node.model.class.must_equal JunOS
end
it 'should resolve username' do
@node.auth[:username].must_equal 'alma'
end
it 'should resolve password' do
@node.auth[:password].must_equal 'armud'
end
it 'should require prompt' do
@node.prompt.must_equal 'test_prompt'
end
end
describe '#run' do
it 'should fetch the configuration' do
stub_oxidized_ssh
status, = @node.run
status.must_equal :success
end
it 'should record the success' do
stub_oxidized_ssh
before_successes = @node.stats.successes
j = Oxidized::Job.new @node
j.join
@node.stats.add j
after_successes = @node.stats.successes
successes = after_successes - before_successes
successes.must_equal 1
end
it 'should record a failure' do
stub_oxidized_ssh_fail
before_fails = @node.stats.failures
j = Oxidized::Job.new @node
j.join
@node.stats.add j
after_fails = @node.stats.failures
fails = after_fails - before_fails
fails.must_equal 1
end
end
describe '#repo' do
before do
Oxidized.config.output.default = 'git'
Oxidized::Node.any_instance.unstub(:resolve_repo)
end
let(:group) { nil }
let(:node) do
Oxidized::Node.new(
ip: '127.0.0.1', group: group, model: 'junos'
)
end
it 'when there are no groups' do
Oxidized.config.output.git.repo = '/tmp/repository.git'
node.repo.must_equal '/tmp/repository.git'
end
describe 'when there are groups' do
let(:group) { 'ggrroouupp' }
before do
Oxidized.config.output.git.single_repo = single_repo
end
describe 'with only one repository' do
let(:single_repo) { true }
before do
Oxidized.config.output.git.repo = '/tmp/repository.git'
end
it 'should use the correct remote' do
node.repo.must_equal '/tmp/repository.git'
end
end
describe 'with more than one repository' do
let(:single_repo) { nil }
before do
Oxidized.config.output.git.repo.ggrroouupp = '/tmp/ggrroouupp.git'
end
it 'should use the correct remote' do
node.repo.must_equal '/tmp/ggrroouupp.git'
end
end
end
end
end
|