Class: Mu::Xtractr::Packets::Test

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/mu/xtractr/test/tc_packets.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#xtractrObject (readonly)

Returns the value of attribute xtractr.



22
23
24
# File 'lib/mu/xtractr/test/tc_packets.rb', line 22

def xtractr
  @xtractr
end

Instance Method Details

#setupObject



24
25
26
# File 'lib/mu/xtractr/test/tc_packets.rb', line 24

def setup
    @xtractr = Xtractr.new
end

#test_countObject



45
46
47
48
49
50
# File 'lib/mu/xtractr/test/tc_packets.rb', line 45

def test_count
    counts = xtractr.packets(1..10).count('pkt.src')
    assert_equal(3, counts.size)
    counts.each { |c| assert_kind_of(Views::Count, c) }
    assert_equal(true, counts[0].count > counts[-1].count)
end

#test_eachObject



32
33
34
35
36
37
# File 'lib/mu/xtractr/test/tc_packets.rb', line 32

def test_each
    pkts = xtractr.packets(1..10)
    pkts.each { |pkt| assert_kind_of(Packet, pkt) }
    pkts.each_packet { |pkt| assert_kind_of(Packet, pkt) }
    pkts.each_with_index { |pkt, i| assert_equal(i+1, pkt.id) }
end

#test_firstObject



39
40
41
42
43
# File 'lib/mu/xtractr/test/tc_packets.rb', line 39

def test_first
    pkt = xtractr.packets(1..10).first
    assert_kind_of(Packet, pkt)
    assert_equal(1, pkt.id)
end

#test_inspectObject



78
79
80
# File 'lib/mu/xtractr/test/tc_packets.rb', line 78

def test_inspect
    assert_nothing_raised { xtractr.packets(1..10).inspect }
end

#test_PacketsObject



28
29
30
# File 'lib/mu/xtractr/test/tc_packets.rb', line 28

def test_Packets
    assert(Packets.ancestors.include?(Enumerable), "Packets doesn't mixin Enumerable")
end

#test_saveObject



68
69
70
71
72
73
74
75
76
# File 'lib/mu/xtractr/test/tc_packets.rb', line 68

def test_save
    filename = '/tmp/foo.pcap'
    pkts = xtractr.packets('pkt.service:HTTP pkt.dir:0')
    pkts.save filename
    assert_equal(true, File.exist?(filename))
    assert_equal(53015, File.size(filename))
ensure
    File.unlink filename
end

#test_sumObject



61
62
63
64
65
66
# File 'lib/mu/xtractr/test/tc_packets.rb', line 61

def test_sum
    sums = xtractr.packets(1..10).sum('pkt.src', 'pkt.length')
    assert_equal(3, sums.size)
    sums.each { |s| assert_kind_of(Views::Sum, s) }
    assert_equal(true, sums[0].sum > sums[-1].sum)
end

#test_valuesObject



52
53
54
55
56
57
58
59
# File 'lib/mu/xtractr/test/tc_packets.rb', line 52

def test_values
    values = xtractr.packets(1..10).values('pkt.src')
    assert_equal(3, values.size)
    values.each do |v| 
        assert_kind_of(Field::Value, v)
        assert_equal('pkt.src', v.field.name)
    end
end