rbeapi 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +3 -0
  3. data/CHANGELOG.md +25 -2
  4. data/Gemfile +13 -7
  5. data/Rakefile +8 -7
  6. data/lib/rbeapi/api/alias.rb +160 -0
  7. data/lib/rbeapi/api/bgp.rb +9 -9
  8. data/lib/rbeapi/api/dns.rb +3 -1
  9. data/lib/rbeapi/api/interfaces.rb +194 -32
  10. data/lib/rbeapi/api/ipinterfaces.rb +5 -3
  11. data/lib/rbeapi/api/managementdefaults.rb +119 -0
  12. data/lib/rbeapi/api/mlag.rb +6 -6
  13. data/lib/rbeapi/api/ntp.rb +1 -1
  14. data/lib/rbeapi/api/ospf.rb +171 -12
  15. data/lib/rbeapi/api/prefixlists.rb +19 -9
  16. data/lib/rbeapi/api/radius.rb +5 -5
  17. data/lib/rbeapi/api/routemaps.rb +12 -12
  18. data/lib/rbeapi/api/snmp.rb +6 -4
  19. data/lib/rbeapi/api/stp.rb +24 -24
  20. data/lib/rbeapi/api/switchports.rb +15 -9
  21. data/lib/rbeapi/api/tacacs.rb +1 -1
  22. data/lib/rbeapi/api/users.rb +4 -4
  23. data/lib/rbeapi/api/varp.rb +7 -3
  24. data/lib/rbeapi/api/vlans.rb +2 -2
  25. data/lib/rbeapi/api/vrrp.rb +61 -61
  26. data/lib/rbeapi/client.rb +9 -6
  27. data/lib/rbeapi/eapilib.rb +3 -3
  28. data/lib/rbeapi/netdev/snmp.rb +8 -6
  29. data/lib/rbeapi/switchconfig.rb +9 -10
  30. data/lib/rbeapi/version.rb +1 -1
  31. data/spec/support/fixtures.rb +4 -4
  32. data/spec/support/matchers/switch_config_sections.rb +2 -2
  33. data/spec/system/rbeapi/api/acl_spec.rb +2 -4
  34. data/spec/system/rbeapi/api/alias_spec.rb +168 -0
  35. data/spec/system/rbeapi/api/bgp_spec.rb +1 -2
  36. data/spec/system/rbeapi/api/interfaces_base_spec.rb +7 -8
  37. data/spec/system/rbeapi/api/interfaces_ethernet_spec.rb +36 -3
  38. data/spec/system/rbeapi/api/interfaces_portchannel_spec.rb +35 -3
  39. data/spec/system/rbeapi/api/interfaces_vlan_spec.rb +90 -0
  40. data/spec/system/rbeapi/api/interfaces_vxlan_spec.rb +3 -4
  41. data/spec/system/rbeapi/api/managementdefaults_spec.rb +31 -0
  42. data/spec/system/rbeapi/api/ospf_interfaces_spec.rb +36 -11
  43. data/spec/system/rbeapi/api/ospf_spec.rb +240 -17
  44. data/spec/system/rbeapi/api/prefixlists_spec.rb +105 -89
  45. data/spec/system/rbeapi/api/routemaps_spec.rb +15 -10
  46. data/spec/system/rbeapi/api/users_spec.rb +4 -5
  47. data/spec/system/rbeapi/api/vrrp_spec.rb +2 -5
  48. data/spec/system/rbeapi/client_spec.rb +1 -2
  49. data/spec/unit/rbeapi/api/acl/default_spec.rb +1 -2
  50. data/spec/unit/rbeapi/api/alias/default_spec.rb +119 -0
  51. data/spec/unit/rbeapi/api/alias/fixture_alias.text +3 -0
  52. data/spec/unit/rbeapi/api/bgp/bgp_neighbors_spec.rb +1 -2
  53. data/spec/unit/rbeapi/api/bgp/bgp_spec.rb +1 -2
  54. data/spec/unit/rbeapi/api/interfaces/base_spec.rb +1 -1
  55. data/spec/unit/rbeapi/api/interfaces/ethernet_spec.rb +35 -1
  56. data/spec/unit/rbeapi/api/interfaces/fixture_interfaces.text +68 -0
  57. data/spec/unit/rbeapi/api/interfaces/portchannel_spec.rb +41 -4
  58. data/spec/unit/rbeapi/api/interfaces/vlan_spec.rb +72 -0
  59. data/spec/unit/rbeapi/api/interfaces/vxlan_spec.rb +2 -2
  60. data/spec/unit/rbeapi/api/managementdefaults/default_spec.rb +50 -0
  61. data/spec/unit/rbeapi/api/managementdefaults/fixture_managementdefaults.yaml +1 -0
  62. data/spec/unit/rbeapi/api/prefixlists/default_spec.rb +98 -80
  63. data/spec/unit/rbeapi/api/prefixlists/fixture_prefixlists.text +9 -4
  64. data/spec/unit/rbeapi/api/users/default_spec.rb +2 -4
  65. data/spec/unit/rbeapi/api/vrrp/default_spec.rb +2 -5
  66. data/spec/unit/rbeapi/client_spec.rb +21 -14
  67. data/spec/unit/rbeapi/switchconfig_spec.rb +10 -3
  68. metadata +49 -59
@@ -42,94 +42,111 @@ describe Rbeapi::Api::Prefixlists do
42
42
  Rbeapi::Client.connect_to('dut')
43
43
  end
44
44
 
45
- describe '#get' do
46
- before do
47
- node.config(['no ip prefix-list test1',
48
- 'ip prefix-list test1',
49
- 'seq 10 permit 1.2.3.0/24',
50
- 'seq 20 permit 2.3.4.0/24 le 30',
51
- 'seq 30 deny 3.4.5.0/24 ge 26 le 30',
52
- 'permit 5.6.7.16/28 eq 29'])
45
+ let(:delete_prefix_lists) do
46
+ config = subject.node.running_config
47
+ config.scan(/(?<=^ip\sprefix-list\s)[^\s]+(?=\sseq.+)?/).uniq.map do |name|
48
+ "no ip prefix-list #{name}"
53
49
  end
50
+ end
54
51
 
52
+ describe '#get' do
55
53
  let(:prefixlist) { subject.get('test1') }
56
54
 
57
- it 'returns the prefix list for an existing name' do
58
- expect(prefixlist).to be_a_kind_of(Array)
59
- end
60
-
61
- it 'returns all rules as hash' do
62
- expect(prefixlist).to all ( be_an(Hash) )
63
- end
64
-
65
- it 'has all keys for each rule' do
66
- prefixlist.each do |rule|
67
- expect(rule).to have_key('seq')
68
- expect(rule).to have_key('prefix')
69
- expect(rule).to have_key('action')
70
- end
71
- end
72
-
73
- let(:values) do
55
+ let(:expected) do
74
56
  [
75
- {
76
- 'seq' => '10',
57
+ { 'seq' => '10',
77
58
  'action' => 'permit',
78
- 'prefix' => '1.2.3.0/24'
79
- },
80
- {
81
- 'seq' => '20',
59
+ 'prefix' => '10.10.1.0/24' },
60
+ { 'seq' => '20',
82
61
  'action' => 'permit',
83
- 'prefix' => '2.3.4.0/24 le 30'
84
- },
85
- {
86
- 'seq' => '30',
62
+ 'prefix' => '10.20.1.0/24 le 30' },
63
+ { 'seq' => '30',
87
64
  'action' => 'deny',
88
- 'prefix' => '3.4.5.0/24 ge 26 le 30'
89
- },
90
- {
91
- 'seq' => '40',
65
+ 'prefix' => '10.30.1.0/24 ge 26 le 30' },
66
+ { 'seq' => '40',
92
67
  'action' => 'permit',
93
- 'prefix' => '5.6.7.16/28 eq 29'
94
- }
68
+ 'prefix' => '10.40.1.16/28 eq 29' }
95
69
  ]
96
70
  end
97
71
 
98
- it 'returns the correct values for all the keys' do
99
- expect(prefixlist).to eq(values)
72
+ let(:keys) { %w(seq action prefix) }
73
+
74
+ [
75
+ { title: 'single-line',
76
+ cmds: ['ip prefix-list test1 seq 10 permit 10.10.1.0/24',
77
+ 'ip prefix-list test1 seq 20 permit 10.20.1.0/24 le 30',
78
+ 'ip prefix-list test1 seq 30 deny 10.30.1.0/24 ge 26 le 30',
79
+ 'ip prefix-list test1 permit 10.40.1.16/28 eq 29'] },
80
+ { title: 'multi-line',
81
+ cmds: ['ip prefix-list test1',
82
+ 'seq 10 permit 10.10.1.0/24',
83
+ 'seq 20 permit 10.20.1.0/24 le 30',
84
+ 'seq 30 deny 10.30.1.0/24 ge 26 le 30',
85
+ 'permit 10.40.1.16/28 eq 29'] }
86
+ ].each do |context|
87
+ context "when prefix list is #{context[:title]}" do
88
+ before { node.config(delete_prefix_lists + context[:cmds]) }
89
+
90
+ it 'returns all rules in an array' do
91
+ expect(prefixlist).to be_a_kind_of(Array)
92
+ end
93
+
94
+ it 'returns each rule as hash' do
95
+ expect(prefixlist).to all be_an(Hash)
96
+ end
97
+
98
+ it 'has all keys for each rule' do
99
+ prefixlist.each do |rule|
100
+ expect(rule.keys).to match_array(keys)
101
+ end
102
+ end
103
+
104
+ it 'returns the correct values for all rules' do
105
+ expect(prefixlist).to eq(expected)
106
+ end
107
+ end
100
108
  end
101
109
  end
102
110
 
103
111
  describe '#getall' do
104
- let(:del_pref_lists) {
105
- subject.getall.keys.map { |k| "no ip prefix-list #{k}" }
106
- }
107
-
108
- before do
109
- node.config(del_pref_lists +
110
- ['ip prefix-list test1',
111
- 'seq 10 permit 1.2.3.0/24',
112
- 'seq 20 permit 2.3.4.0/24 le 30',
113
- 'seq 30 deny 3.4.5.0/24 ge 26 le 30',
114
- 'permit 5.6.7.8/28',
115
- 'ip prefix-list test2',
116
- 'seq 10 permit 10.11.0.0/16',
117
- 'seq 20 permit 10.12.0.0/16 le 24',
118
- 'ip prefix-list test3'])
119
- end
120
-
121
112
  let(:prefixlists) { subject.getall }
122
113
 
123
- it 'returns the collection as hash' do
124
- expect(prefixlists).to be_a_kind_of(Hash)
125
- end
126
-
127
- it 'returns all prefix lists as array' do
128
- expect(prefixlists).to all ( be_an(Array) )
129
- end
130
-
131
- it 'has three prefix lists' do
132
- expect(prefixlists.size).to eq(3)
114
+ [
115
+ { title: 'single-line',
116
+ cmds: ['ip prefix-list test1 seq 10 permit 10.10.1.0/24',
117
+ 'ip prefix-list test1 seq 20 permit 10.20.1.0/24 le 30',
118
+ 'ip prefix-list test1 seq 30 deny 10.30.1.0/24 ge 26 le 30',
119
+ 'ip prefix-list test1 permit 10.40.1.8/28',
120
+ 'ip prefix-list test2 seq 10 permit 10.11.0.0/16',
121
+ 'ip prefix-list test2 seq 20 permit 10.12.0.0/16 le 24',
122
+ 'ip prefix-list test3 permit 10.13.0.0/16'] },
123
+ { title: 'multi-line',
124
+ cmds: ['ip prefix-list test1',
125
+ 'seq 10 permit 10.10.1.0/24',
126
+ 'seq 20 permit 10.20.1.0/24 le 30',
127
+ 'seq 30 deny 10.30.1.0/24 ge 26 le 30',
128
+ 'permit 10.40.1.8/28',
129
+ 'ip prefix-list test2',
130
+ 'seq 10 permit 10.11.0.0/16',
131
+ 'seq 20 permit 10.12.0.0/16 le 24',
132
+ 'ip prefix-list test3',
133
+ 'permit 10.13.0.0/16'] }
134
+ ].each do |context|
135
+ context "when prefix lists are #{context[:title]}" do
136
+ before { node.config(delete_prefix_lists + context[:cmds]) }
137
+
138
+ it 'returns the collection as hash' do
139
+ expect(prefixlists).to be_a_kind_of(Hash)
140
+ end
141
+
142
+ it 'returns each prefix lists as an array' do
143
+ expect(prefixlists).to all be_an(Array)
144
+ end
145
+
146
+ it 'has three prefix lists' do
147
+ expect(prefixlists.size).to eq(3)
148
+ end
149
+ end
133
150
  end
134
151
  end
135
152
 
@@ -149,40 +166,39 @@ describe Rbeapi::Api::Prefixlists do
149
166
  describe '#add_rule' do
150
167
  before do
151
168
  node.config(['no ip prefix-list test5',
152
- 'ip prefix-list test5'])
169
+ 'no ip prefix-list test6',
170
+ 'ip prefix-list test5'])
153
171
  end
154
172
 
155
173
  it 'adds rule to an existing prefix list' do
156
174
  expect(subject.get('test5')).to eq([])
157
- expect(subject.add_rule('test5', 'permit', '1.1.1.0/24')).to be_truthy
158
- expect(subject.get('test5')).to eq([{
159
- "seq" => "10",
160
- "action" => "permit",
161
- "prefix" => "1.1.1.0/24"}])
175
+ expect(subject.add_rule('test5', 'permit', '10.50.1.0/24')).to be_truthy
176
+ expect(subject.get('test5')).to eq([{ 'seq' => '10',
177
+ 'action' => 'permit',
178
+ 'prefix' => '10.50.1.0/24' }])
162
179
  end
163
180
 
164
181
  it 'adds rule to a non-existent prefix list' do
165
182
  expect(subject.get('test6')).to eq(nil)
166
- expect(subject.add_rule('test6', 'deny', '2.2.2.0/24')).to be_truthy
167
- expect(subject.get('test6')).to eq([{
168
- "seq" => "10",
169
- "action" => "deny",
170
- "prefix" => "2.2.2.0/24"}])
183
+ expect(subject.add_rule('test6', 'deny', '10.60.1.0/24')).to be_truthy
184
+ expect(subject.get('test6')).to eq([{ 'seq' => '10',
185
+ 'action' => 'deny',
186
+ 'prefix' => '10.60.1.0/24' }])
171
187
  end
172
188
  end
173
189
 
174
190
  describe '#delete' do
175
191
  before do
176
192
  node.config(['no ip prefix-list test7',
177
- 'no ip prefix-list test8',
178
- 'ip prefix-list test7',
179
- 'seq 10 permit 7.7.0.0/16',
180
- 'ip prefix-list test8',
181
- 'seq 10 permit 8.8.0.0/16',
182
- 'deny 9.9.0.0/16 le 24'])
193
+ 'no ip prefix-list test8',
194
+ 'ip prefix-list test7',
195
+ 'seq 10 permit 10.70.0.0/16',
196
+ 'ip prefix-list test8',
197
+ 'seq 10 permit 10.80.0.0/16',
198
+ 'deny 10.82.0.0/16 le 24'])
183
199
  end
184
200
 
185
- it 'delets a prefix list' do
201
+ it 'deletes a prefix list' do
186
202
  expect(subject.get('test7')).to be_truthy
187
203
  expect(subject.delete('test7')).to be_truthy
188
204
  expect(subject.get('test7')).to eq(nil)
@@ -195,4 +211,4 @@ describe Rbeapi::Api::Prefixlists do
195
211
  expect(subject.get('test8')[1]).to eq(nil)
196
212
  end
197
213
  end
198
- end
214
+ end
@@ -124,8 +124,7 @@ describe Rbeapi::Api::Routemaps do
124
124
  continue: 99, description: 'descript',
125
125
  match: ['ip address prefix-list MYLOOPBACK',
126
126
  'interface Loopback0'],
127
- set: ['community internet 5555:5555'])
128
- ).to be_truthy
127
+ set: ['community internet 5555:5555'])).to be_truthy
129
128
  expect(subject.get('test')).to eq(test_entry)
130
129
  end
131
130
 
@@ -135,7 +134,8 @@ describe Rbeapi::Api::Routemaps do
135
134
  expect(subject.get('test1')).to be_truthy
136
135
  expect(subject.get('test1').assoc('permit')[0]).to eq('permit')
137
136
  expect(
138
- subject.get('test1').assoc('permit')[1].assoc(10)[0]).to eq(10)
137
+ subject.get('test1').assoc('permit')[1].assoc(10)[0]
138
+ ).to eq(10)
139
139
  expect(
140
140
  subject.get('test1').assoc('permit')[1].assoc(10)[1][:continue]
141
141
  ).to eq(nil)
@@ -213,11 +213,13 @@ describe Rbeapi::Api::Routemaps do
213
213
  expect(
214
214
  subject.set_match_statements('test', 'permit', 10,
215
215
  ['ip address prefix-list MYLOOPBACK',
216
- 'interface Loopback0'])).to be_truthy
216
+ 'interface Loopback0'])
217
+ ).to be_truthy
217
218
  expect(subject.get('test'))
218
219
  .to eq('permit' => { 10 => {
219
220
  match: ['ip address prefix-list MYLOOPBACK',
220
- 'interface Loopback0'] } })
221
+ 'interface Loopback0']
222
+ } })
221
223
  end
222
224
 
223
225
  it 'adds more match statements' do
@@ -230,12 +232,13 @@ describe Rbeapi::Api::Routemaps do
230
232
  expect(subject
231
233
  .set_match_statements('test', 'permit', 10,
232
234
  ['interface Vlan100',
233
- 'ip address prefix-list MYLOOPBACK'])
234
- ).to be_truthy
235
+ 'ip address prefix-list MYLOOPBACK']))
236
+ .to be_truthy
235
237
  expect(subject.get('test'))
236
238
  .to eq('permit' => { 10 => {
237
239
  match: ['ip address prefix-list MYLOOPBACK',
238
- 'interface Vlan100'] } })
240
+ 'interface Vlan100']
241
+ } })
239
242
  expect(subject
240
243
  .set_match_statements('test', 'permit', 10,
241
244
  ['interface Vlan100'])).to be_truthy
@@ -261,7 +264,8 @@ describe Rbeapi::Api::Routemaps do
261
264
  expect(subject.get('test1'))
262
265
  .to eq('permit' => { 10 => {
263
266
  match: ['ip address prefix-list MYLOOPBACK',
264
- 'interface Loopback0'] } })
267
+ 'interface Loopback0']
268
+ } })
265
269
  end
266
270
  end
267
271
 
@@ -290,7 +294,8 @@ describe Rbeapi::Api::Routemaps do
290
294
  'community internet 4444:4444'])).to be_truthy
291
295
  expect(subject.get('test1'))
292
296
  .to eq('permit' => { 10 => {
293
- set: ['community internet 4444:4444 5555:5555'] } })
297
+ set: ['community internet 4444:4444 5555:5555']
298
+ } })
294
299
  end
295
300
  end
296
301
 
@@ -68,8 +68,7 @@ describe Rbeapi::Api::Users do
68
68
  nopassword: false,
69
69
  encryption: 'md5',
70
70
  secret: md5_secret,
71
- sshkey: sshkey
72
- }
71
+ sshkey: sshkey }
73
72
  end
74
73
 
75
74
  describe '#getall' do
@@ -82,8 +81,7 @@ describe Rbeapi::Api::Users do
82
81
  'rbeapi' => { name: 'rbeapi', privilege: 1, role: nil,
83
82
  nopassword: false, encryption: 'md5',
84
83
  secret: md5_secret,
85
- sshkey: sshkey }
86
- }
84
+ sshkey: sshkey } }
87
85
  end
88
86
 
89
87
  before do
@@ -91,7 +89,8 @@ describe Rbeapi::Api::Users do
91
89
  'no username user1',
92
90
  'username admin privilege 1 role network-admin nopassword',
93
91
  "username rbeapi privilege 1 secret 5 #{md5_secret}",
94
- "username rbeapi sshkey #{sshkey}"])
92
+ "username rbeapi sshkey #{sshkey}",
93
+ 'management defaults', 'default secret hash'])
95
94
  end
96
95
 
97
96
  it 'returns the username collection' do
@@ -57,15 +57,12 @@ describe Rbeapi::Api::Vrrp do
57
57
  timers_advertise: 1,
58
58
  track: [
59
59
  { name: 'Ethernet1', action: 'decrement', amount: 5 }
60
- ]
61
- },
60
+ ] },
62
61
  40 => { primary_ip: '40.10.5.32', delay_reload: 0, description: nil,
63
62
  enable: true, ip_version: 2, mac_addr_adv_interval: 30,
64
63
  preempt: true, preempt_delay_min: 0, preempt_delay_reload: 0,
65
64
  priority: 200, secondary_ip: [], timers_advertise: 1,
66
- track: @tracks
67
- }
68
- }
65
+ track: @tracks } }
69
66
  end
70
67
 
71
68
  it 'returns the virtual router resource' do
@@ -171,8 +171,7 @@ describe Rbeapi::Client do
171
171
  username: 'test2',
172
172
  password: 'test',
173
173
  transport: 'http',
174
- host: 'test2'
175
- )).to eq(nil)
174
+ host: 'test2')).to eq(nil)
176
175
  expect(subject.config.get_connection('test2'))
177
176
  .to eq(username: 'test2',
178
177
  password: 'test',
@@ -63,8 +63,7 @@ describe Rbeapi::Api::Acl do
63
63
  '50' => { seqno: '50', action: 'permit', srcaddr: '16.0.0.0',
64
64
  srcprefixlen: '8', log: nil },
65
65
  '60' => { seqno: '60', action: 'permit', srcaddr: '9.10.11.0',
66
- srcprefixlen: '255.255.255.0', log: 'log' }
67
- }
66
+ srcprefixlen: '255.255.255.0', log: 'log' } }
68
67
  end
69
68
 
70
69
  it 'returns the ACL resource' do
@@ -0,0 +1,119 @@
1
+ #
2
+ # Copyright (c) 2015, Arista Networks, Inc.
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are
7
+ # met:
8
+ #
9
+ # Redistributions of source code must retain the above copyright notice,
10
+ # this list of conditions and the following disclaimer.
11
+ #
12
+ # Redistributions in binary form must reproduce the above copyright
13
+ # notice, this list of conditions and the following disclaimer in the
14
+ # documentation and/or other materials provided with the distribution.
15
+ #
16
+ # Neither the name of Arista Networks nor the names of its
17
+ # contributors may be used to endorse or promote products derived from
18
+ # this software without specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS
24
+ # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27
+ # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28
+ # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29
+ # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
30
+ # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ #
32
+ require 'spec_helper'
33
+
34
+ require 'rbeapi/api/alias'
35
+
36
+ include FixtureHelpers
37
+
38
+ describe Rbeapi::Api::Alias do
39
+ subject { described_class.new(node) }
40
+
41
+ let(:node) { double('node') }
42
+
43
+ let(:test) do
44
+ { name: 'Alias1',
45
+ command: 'my command' }
46
+ end
47
+ let(:name) { test[:name] }
48
+
49
+ def aliases
50
+ aliases = Fixtures[:alias]
51
+ return aliases if aliases
52
+ fixture('alias', format: :text, dir: File.dirname(__FILE__))
53
+ end
54
+
55
+ before :each do
56
+ allow(subject.node).to receive(:running_config).and_return(aliases)
57
+ end
58
+
59
+ describe '#getall' do
60
+ let(:test1_entries) do
61
+ { 'Alias1' => { name: 'Alias1', command: 'my command' },
62
+ 'Alias2' => { name: 'Alias2', command: 'my command 2' },
63
+ 'Alias3' => { name: 'Alias3',
64
+ command: '1 conf\n2 int %1\n3 description %2\n'\
65
+ '4 end\nend' } }
66
+ end
67
+
68
+ it 'returns the alias collection' do
69
+ expect(subject.getall).to include(test1_entries)
70
+ end
71
+
72
+ it 'returns a hash collection' do
73
+ expect(subject.getall).to be_a_kind_of(Hash)
74
+ end
75
+
76
+ it 'has three entries' do
77
+ expect(subject.getall.size).to eq(3)
78
+ end
79
+ end
80
+
81
+ describe '#get' do
82
+ it 'returns the alias resource for given name' do
83
+ expect(subject.get(name)).to eq(test)
84
+ end
85
+
86
+ it 'returns a hash' do
87
+ expect(subject.get(name)).to be_a_kind_of(Hash)
88
+ end
89
+
90
+ it 'has two entries' do
91
+ expect(subject.get(name).size).to eq(2)
92
+ end
93
+ end
94
+
95
+ describe '#create' do
96
+ it 'create a new alias entry' do
97
+ expect(node).to receive(:config).with(['alias Alias1 my command'])
98
+ expect(subject.create('Alias1', command: 'my command')).to be_truthy
99
+ end
100
+ it 'raises ArgumentError for create without required args ' do
101
+ expect { subject.create('Alias') }.to \
102
+ raise_error ArgumentError
103
+ end
104
+ end
105
+
106
+ describe '#set_command' do
107
+ it 'set the command' do
108
+ expect(node).to receive(:config).with(['alias Alias4 my command'])
109
+ expect(subject.create('Alias4', command: 'my command')).to be_truthy
110
+ end
111
+ end
112
+
113
+ describe '#delete' do
114
+ it 'delete a alias resource' do
115
+ expect(node).to receive(:config).with('no alias Alias1')
116
+ expect(subject.delete('Alias1')).to be_truthy
117
+ end
118
+ end
119
+ end