|
| 1 | +module Message = Client.Client.Message |
| 2 | + |
| 3 | +let rpc = Quicktest_args.rpc |
| 4 | + |
| 5 | +module Testable = struct |
| 6 | + let ref () = |
| 7 | + let fmt = Fmt.of_to_string Ref.string_of in |
| 8 | + Alcotest.testable fmt ( = ) |
| 9 | +end |
| 10 | + |
| 11 | +let get_all_records_where_test rpc session_id () = |
| 12 | + let with_api fn = fn ~rpc ~session_id in |
| 13 | + let create_message = with_api Message.create in |
| 14 | + |
| 15 | + let vm = List.hd (with_api Client.Client.VM.get_all) in |
| 16 | + let vm_uuid = with_api Client.Client.VM.get_uuid ~self:vm in |
| 17 | + |
| 18 | + let host = List.hd (with_api Client.Client.Host.get_all) in |
| 19 | + let host_uuid = with_api Client.Client.Host.get_uuid ~self:host in |
| 20 | + |
| 21 | + (* Create several different messages *) |
| 22 | + let messages = |
| 23 | + [ |
| 24 | + create_message ~name:"VM_EXPLODED" ~priority:100L ~cls:`VM |
| 25 | + ~obj_uuid:vm_uuid ~body:"body" |
| 26 | + ; create_message ~name:"HOST_EXPLODED" ~priority:100L ~cls:`Host |
| 27 | + ~obj_uuid:host_uuid ~body:"body" |
| 28 | + ; create_message ~name:"VM_DROWNED" ~priority:50L ~cls:`VM ~obj_uuid:vm_uuid |
| 29 | + ~body:"body" |
| 30 | + ] |
| 31 | + in |
| 32 | + |
| 33 | + let get_messages_where = with_api Message.get_all_records_where in |
| 34 | + |
| 35 | + let queries = |
| 36 | + [ |
| 37 | + (* query | is message expected in the list [bool ; bool ; bool] *) |
| 38 | + ({| field "name" = "VM_EXPLODED" |}, [true; false; false]) |
| 39 | + ; ({| field "priority" = "100" |}, [true; true; false]) |
| 40 | + ; ({| field "cls" = "VM" |}, [true; false; true]) |
| 41 | + ; ({| field "cls" = "VM" and field "priority" = "50"|}, [false; false; true]) |
| 42 | + ; ({| field "cls" = "VDI"|}, [false; false; false]) |
| 43 | + ; ({| field "class" = "VM"|}, [false; false; false]) |
| 44 | + ; ( {| field "cls" = "VM" or field "name" = "HOST_EXPLODED"|} |
| 45 | + , [true; true; true] |
| 46 | + ) |
| 47 | + ] |
| 48 | + in |
| 49 | + let lists = |
| 50 | + List.map |
| 51 | + (fun (expr, expected) -> (expr, get_messages_where ~expr, expected)) |
| 52 | + queries |
| 53 | + in |
| 54 | + |
| 55 | + (* Check that filtering returns correct messages *) |
| 56 | + let message_test msg list expected = |
| 57 | + let list = List.map fst list in |
| 58 | + List.iter2 |
| 59 | + (fun msg_ref expected -> |
| 60 | + Alcotest.check' Alcotest.bool ~msg ~expected |
| 61 | + ~actual:(List.mem msg_ref list) |
| 62 | + ) |
| 63 | + messages expected |
| 64 | + in |
| 65 | + List.iter (fun (msg, list, expected) -> message_test msg list expected) lists |
| 66 | + |
| 67 | +let tests () = |
| 68 | + let open Qt_filter in |
| 69 | + [ |
| 70 | + [("Message.get_all_records_where test", `Quick, get_all_records_where_test)] |
| 71 | + |> conn |
| 72 | + ] |
| 73 | + |> List.concat |
0 commit comments