Class: Mu::Xtractr::Flows::Test

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/mu/xtractr/test/tc_flows.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_flows.rb', line 22

def xtractr
  @xtractr
end

Instance Method Details

#setupObject



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

def setup
    @xtractr = Xtractr.new
end

#test_countObject



58
59
60
61
62
63
# File 'lib/mu/xtractr/test/tc_flows.rb', line 58

def test_count
    flows = xtractr.flows 'flow.service:DNS'
    counts = flows.count 'dns.qry.name'
    assert_equal(4, counts.size)
    counts.each { |c| assert_kind_of(Views::Count, c) }
end

#test_eachObject



40
41
42
43
44
45
46
47
# File 'lib/mu/xtractr/test/tc_flows.rb', line 40

def test_each
    flows = xtractr.flows 'flow.service:DNS'
    v = flows.each { |f| assert_kind_of(Flow, f) }
    assert_equal(flows, v)
    
    v = flows.each_flow { |f| assert_kind_of(Flow, f) }
    assert_equal(flows, v)
end

#test_firstObject



49
50
51
52
53
54
55
56
# File 'lib/mu/xtractr/test/tc_flows.rb', line 49

def test_first
    flows = xtractr.flows 'flow.service:DNS'
    flow = flows.first
    assert_kind_of(Flow, flow)
    
    flow = xtractr.flows('flow.service:blah').first
    assert_nil(flow)
end

#test_FlowsObject



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

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

#test_inspectObject



88
89
90
# File 'lib/mu/xtractr/test/tc_flows.rb', line 88

def test_inspect
    assert_nothing_raised { xtractr.flows.inspect }
end

#test_qObject



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

def test_q
    flows = xtractr.flows
    assert_equal('*', flows.q)
    
    flows = xtractr.flows 'flow.service:DNS'
    assert_equal('flow.service:DNS', flows.q)        
end

#test_saveObject



79
80
81
82
83
84
85
86
# File 'lib/mu/xtractr/test/tc_flows.rb', line 79

def test_save
    filename = '/tmp/foo.pcap'
    xtractr.flows(1..3).save(filename)
    assert_equal(true, File.exist?(filename))
    assert_equal(20898, File.size(filename))
ensure
    File.unlink filename
end

#test_sumObject



72
73
74
75
76
77
# File 'lib/mu/xtractr/test/tc_flows.rb', line 72

def test_sum
    flows = xtractr.flows 'flow.service:DNS'
    sums = flows.sum 'dns.qry.name', 'flow.bytes'
    assert_equal(4, sums.size)
    sums.each { |s| assert_kind_of(Views::Sum, s) }
end

#test_valuesObject



65
66
67
68
69
70
# File 'lib/mu/xtractr/test/tc_flows.rb', line 65

def test_values
    flows = xtractr.flows 'flow.service:DNS'
    values = flows.values 'dns.qry.name'
    assert_equal(4, values.size)
    values.each { |v| assert_kind_of(Field::Value, v) }
end