From d7439b435facc6819dd619836705b0f567ef3b5b Mon Sep 17 00:00:00 2001 From: Eishun Kondoh Date: Tue, 9 Apr 2019 23:51:24 +0900 Subject: [PATCH] quality: Add test cases for openflow actions --- lib/openflow/actions/nx_learn2.ex | 2 +- test/ofp_action_test.exs | 41 +++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/lib/openflow/actions/nx_learn2.ex b/lib/openflow/actions/nx_learn2.ex index f576c63..02fcd6f 100644 --- a/lib/openflow/actions/nx_learn2.ex +++ b/lib/openflow/actions/nx_learn2.ex @@ -20,7 +20,7 @@ defmodule Openflow.Action.NxLearn2 do alias __MODULE__ alias Openflow.Action.Experimenter - def new(options) do + def new(options \\ []) do %NxLearn2{ idle_timeout: options[:idle_timeout] || 0, hard_timeout: options[:hard_timeout] || 0, diff --git a/test/ofp_action_test.exs b/test/ofp_action_test.exs index ddad5af..0d6bf8a 100644 --- a/test/ofp_action_test.exs +++ b/test/ofp_action_test.exs @@ -691,7 +691,7 @@ defmodule OfpActionTest do end describe "Openflow.Action.NxLearn2" do - test "with learn2" do + test "with learn2 packet" do test_file = "test/packet_data/nx_learn2.raw" packet = File.read!(test_file) actions = Openflow.Action.read(packet) @@ -720,6 +720,17 @@ defmodule OfpActionTest do assert actions_bin == packet assert actions == [learn2] end + + test "with no options" do + learn2 = Openflow.Action.NxLearn2.new() + + learn2 + |> Openflow.Action.to_binary() + |> Openflow.Action.read() + |> Enum.at(0) + |> Kernel.==(learn2) + |> assert() + end end describe "Openflow.Action.NxMultipath" do @@ -800,6 +811,12 @@ defmodule OfpActionTest do assert actions_bin == packet assert actions == [reg_load] end + + test "with no options" do + assert_raise RuntimeError, "dst_field must be specified", fn -> + Openflow.Action.NxRegLoad.new() + end + end end describe "Openflow.Action.NxRegMove" do @@ -807,11 +824,31 @@ defmodule OfpActionTest do test_file = "test/packet_data/nx_reg_move.raw" packet = File.read!(test_file) actions = Openflow.Action.read(packet) - reg_move = Openflow.Action.NxRegMove.new(src_field: :nx_in_port, dst_field: :nx_vlan_tci) + + reg_move = + Openflow.Action.NxRegMove.new( + src_field: :nx_in_port, + dst_field: :nx_vlan_tci, + src_offset: 0, + dst_offset: 0 + ) + actions_bin = Openflow.Action.to_binary(reg_move) assert actions_bin == packet assert actions == [reg_move] end + + test "with no options" do + assert_raise RuntimeError, "src_field must be specified", fn -> + Openflow.Action.NxRegMove.new() + end + end + + test "with no dst_field options" do + assert_raise RuntimeError, "dst_field must be specified", fn -> + Openflow.Action.NxRegMove.new(src_field: :reg0) + end + end end describe "Openflow.Action.NxResubmit" do