quality: Add test cases for table_stats messages

This commit is contained in:
Eishun Kondoh 2019-05-05 23:51:21 +09:00
parent 2bfccd693f
commit 344c00d31d
3 changed files with 52 additions and 3 deletions

View file

@ -11,8 +11,8 @@ defmodule Openflow.Multipart.Table.Request do
def ofp_type, do: 18 def ofp_type, do: 18
def new(xid \\ 0) do def new(options \\ []) do
%Request{xid: xid} %Request{xid: options[:xid] || 0}
end end
def read("") do def read("") do

View file

@ -38,7 +38,7 @@ defmodule OfpQueueStatsTest do
tx_bytes: 0, tx_bytes: 0,
tx_errors: 0, tx_errors: 0,
tx_packets: 0 tx_packets: 0
}, },
%Openflow.Multipart.QueueStats{ %Openflow.Multipart.QueueStats{
duration_nsec: 0, duration_nsec: 0,
duration_sec: 0, duration_sec: 0,

View file

@ -0,0 +1,49 @@
defmodule OfpTableStatsTest do
use ExUnit.Case
describe "Openflow.Multipart.Table.Request" do
test "with default values" do
table_stats =
%Openflow.Multipart.Table.Request{}
|> Map.to_list()
|> Openflow.Multipart.Table.Request.new()
|> Openflow.to_binary()
|> Openflow.read()
|> Kernel.elem(1)
assert table_stats.xid == 0
end
end
describe "Openflow.Multipart.Table.Reply" do
test "with test packet_data" do
table_stats =
"test/packet_data/4-28-ofp_table_stats_reply.packet"
|> File.read!()
|> Openflow.read()
|> Kernel.elem(1)
%Openflow.Multipart.Table.Reply{
aux_id: nil,
datapath_id: nil,
flags: [],
tables: [
%Openflow.Multipart.TableStats{
active_count: 4,
lookup_count: 4,
matched_count: 4,
table_id: 0
},
%Openflow.Multipart.TableStats{
active_count: 4,
lookup_count: 4,
matched_count: 4,
table_id: 1
}
],
version: 4,
xid: 0
} = table_stats
end
end
end