@@ -49,6 +49,19 @@ should_query_flow_table_id(_Config) ->
4949 % % THEN
5050 assert_dobby_search_fun_correct (? DPID , TableNo ).
5151
52+ % %%=============================================================================
53+ % %% Assertions
54+ % %%=============================================================================
55+
56+ assert_dobby_search_fun_correct (Dpid , TableNo ) ->
57+ SearchFun = meck :capture (first , dby , search , 4 , _ArgNo = 1 ),
58+ Path = switch_to_flow_table_path (Dpid ),
59+ SearchResult = SearchFun (_FlowTableId = ? TABLE_IDENTIFIER ,
60+ flow_table_metadata_info (TableNo ),
61+ Path ,
62+ []),
63+ ? assertEqual ({stop , ? TABLE_IDENTIFIER }, SearchResult ).
64+
5265% %%=============================================================================
5366% %% Internal functions
5467% %%=============================================================================
@@ -58,14 +71,21 @@ mock_dobby() ->
5871unmock_dobby () ->
5972 ok = meck :unload (dby ).
6073
61- assert_dobby_search_fun_correct (Dpid , TableNo ) ->
62- SearchFun = meck :capture (first , dby , search , ['_' , '_' , Dpid , '_' ],
63- _ArgNo = 1 ),
64- NullLink = {Dpid , null , undefined },
65- SearchResult = SearchFun (? TABLE_IDENTIFIER ,
66- #{type => of_flow_table , table_no => TableNo },
67- #{type => of_resource },
68- [NullLink ]),
69- ? assertEqual ({stop , ? TABLE_IDENTIFIER }, SearchResult ).
74+ switch_to_flow_table_path (Dpid ) ->
75+ [{_SwIdentifier = Dpid ,
76+ _SwIdMetadataInfo = metadata ([{type , of_switch }]),
77+ _SwToFlowTableMetadataInfo = metadata ([{type , of_resource }])}].
78+
79+ flow_table_metadata_info (TableNo ) ->
80+ metadata ([{type , of_flow_table }, {table_no , TableNo }]).
7081
82+ metadata (Proplist ) ->
83+ lists :foldl (fun ({K , V }, AccMap ) ->
84+ IM = inner_metadata (V ),
85+ maps :put (atom_to_binary (K , utf8 ), IM , AccMap )
86+ end , #{}, Proplist ).
7187
88+ inner_metadata (V ) when is_atom (V ) ->
89+ inner_metadata (atom_to_binary (V , utf8 ));
90+ inner_metadata (V ) ->
91+ #{value => V , publisher_id => <<" ID" >>, timestamp => <<" TSTM" >>}.
0 commit comments