Skip to content

Commit

Permalink
fixup! CP-52320 & CP-52795: Add unit tests for tgroup library
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielBuica committed Dec 4, 2024
1 parent 90b296c commit f91bdb1
Showing 1 changed file with 31 additions and 45 deletions.
76 changes: 31 additions & 45 deletions ocaml/libs/tgroup/test_tgroup.ml
Original file line number Diff line number Diff line change
@@ -1,77 +1,63 @@
module D = Debug.Make (struct let name = __MODULE__ end)

let test_identity () =
let user_agents_and_sids =
let specs =
[
(Some "XenCenter2024", "u1000")
; (None, "u1001")
; (None, "Special!@#")
; (Some "With-Hyphen", "123")
; (Some "", "")
; (Some " Xen Center 2024 ", ", u 1000 ")
; (Some "Xen Center ,/@.~# 2024", "root")
; (Some "XenCenter 2024.3.18", "")
((Some "XenCenter2024", "u1000"), "u1000/XenCenter2024")
; ((None, "u1001"), "u1001")
; ((None, "Special!@#"), "Special")
; ((Some "With-Hyphen", "123"), "123/WithHyphen")
; ((Some "", ""), "root")
; ((Some " Xen Center 2024 ", ", u 1000 "), "u1000/XenCenter2024")
; ((Some "Xen Center ,/@.~# 2024", "root"), "root/XenCenter2024")
; ((Some "XenCenter 2024.3.18", ""), "root/XenCenter2024318")
]
in
let expected_identities =
[
"u1000/XenCenter2024"
; "u1001"
; "Special"
; "123/WithHyphen"
; "root"
; "u1000/XenCenter2024"
; "root/XenCenter2024"
; "root/XenCenter2024318"
]
in
let test_make (user_agent, subject_sid) identity =

let test_make ((user_agent, subject_sid), expected_identity) =
let actual_identity =
Tgroup.Group.Identity.(make ?user_agent subject_sid |> to_string)
in
Alcotest.(check string) "Check expected identity" identity actual_identity
Alcotest.(check string)
"Check expected identity" expected_identity actual_identity
in
List.iter2 test_make user_agents_and_sids expected_identities
List.iter test_make specs

let test_of_creator () =
let dummy_identity =
Tgroup.Group.Identity.make ~user_agent:"XenCenter2024" "root"
in
let creator_args =
[
(None, None, None, None)
; (Some true, None, None, None)
; (Some true, Some "external", Some dummy_identity, Some "sm")
; (Some true, Some "internal", Some dummy_identity, Some "sm")
; (None, Some "intenal", Some dummy_identity, Some "cli")
; (None, None, Some dummy_identity, Some "sm")
]
in
let expected_groups =
let specs =
[
"external/unauthenticated"
; "external/intrapool"
; "external/intrapool"
; "external/intrapool"
; "internal/cli"
; "external/authenticated/root/XenCenter2024"
((None, None, None, None), "external/unauthenticated")
; ((Some true, None, None, None), "external/intrapool")
; ( (Some true, Some "external", Some dummy_identity, Some "sm")
, "external/intrapool"
)
; ( (Some true, Some "internal", Some dummy_identity, Some "sm")
, "external/intrapool"
)
; ((None, Some "intenal", Some dummy_identity, Some "cli"), "internal/cli")
; ( (None, None, Some dummy_identity, Some "sm")
, "external/authenticated/root/XenCenter2024"
)
]
in
let test_make (intrapool, endpoint, identity, originator) group =
let test_make ((intrapool, endpoint, identity, originator), expected_group) =
let actual_group =
Tgroup.Group.(
Creator.make ?intrapool ?endpoint ?identity ?originator ()
|> of_creator
|> to_string
)
in
Alcotest.(check string) "Check expected group" group actual_group
Alcotest.(check string) "Check expected group" expected_group actual_group
in
List.iter2 test_make creator_args expected_groups
List.iter test_make specs

let tests =
[
("Identity make", `Quick, test_identity)
("identity make", `Quick, test_identity)
; ("group of creator", `Quick, test_of_creator)
]

Expand Down

0 comments on commit f91bdb1

Please sign in to comment.