-
Notifications
You must be signed in to change notification settings - Fork 0
/
show_stats_steps.rb
87 lines (78 loc) · 2.28 KB
/
show_stats_steps.rb
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
# rubocop:disable LineLength
Then(/^the number of packets sent from "(.*?)" should be:$/) do |host_name, table|
command = "trema show_stats #{host_name}"
step "I run `#{command}`"
result = {}
cd('.') do
output_from(command).split("\n").each do |each|
case each
when /Packets sent/
next
when /Packets recevied/
break
when /-> (\S+) = (\d+) packet/
result[Regexp.last_match(1)] = Regexp.last_match(2).to_i
else
raise "Failed to parse line '#{each}'"
end
end
end
table.hashes.each do |each|
ip_address = each.fetch('destination')
expect(result.fetch(ip_address)).to eq(each.fetch('#packets').to_i)
end
end
Then(/^the number of packets received by "(.*?)" should be:$/) do |host_name, table|
command = "trema show_stats #{host_name}"
step "I run `#{command}`"
output = aruba.command_monitor.find(Aruba.platform.detect_ruby(command)).output
result = Hash.new(0)
cd('.') do
received = false
output.split("\n").each do |each|
case each
when /Packets sent/
next
when /Packets received/
received = true
next
when /(\S+) -> (\S+) = (\d+) packet/
next unless received
result[Regexp.last_match(1)] = Regexp.last_match(3).to_i
else
raise "Failed to parse line '#{each}'"
end
end
end
table.hashes.each do |each|
ip_address = each.fetch('source')
expect(result[ip_address]).to eq(each.fetch('#packets').to_i)
end
end
Then(/^the total number of received packets should be:$/) do |table|
table.hashes[0].each_pair do |host_name, npackets|
command = "trema show_stats #{host_name}"
step "I run `#{command}`"
output = aruba.command_monitor.find(Aruba.platform.detect_ruby(command)).output
result = 0
cd('.') do
received = false
output.split("\n").each do |each|
case each
when /Packets sent/
next
when /Packets received/
received = true
next
when /(\S+) -> (\S+) = (\d+) packet/
next unless received
result += Regexp.last_match(3).to_i
else
raise "Failed to parse line '#{each}'"
end
end
end
expect(result).to eq(npackets.to_i)
end
end
# rubocop:enable LineLength