Skip to content

Commit 47e9788

Browse files
committed
CA-423202: Add unit tests for get_accumulative_livepatches
Signed-off-by: Ming Lu <ming.lu@cloud.com>
1 parent 2f8c908 commit 47e9788

1 file changed

Lines changed: 350 additions & 0 deletions

File tree

ocaml/tests/test_repository_helpers.ml

Lines changed: 350 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4815,6 +4815,355 @@ module MergeLivepatchFailures = Generic.MakeStateless (struct
48154815
]
48164816
end)
48174817

4818+
module GetAccumulativeLivepatches = Generic.MakeStateless (struct
4819+
module Io = struct
4820+
type input_t = {updates_info: UpdateInfo.t list; since: Livepatch.t}
4821+
4822+
type output_t = (LivePatch.t * string) list
4823+
4824+
let fields_of_input =
4825+
Fmt.Dump.
4826+
[
4827+
field "updates_info"
4828+
(fun (r : input_t) ->
4829+
List.map
4830+
(fun x -> UpdateInfo.to_json x |> Yojson.Basic.pretty_to_string)
4831+
r.updates_info
4832+
)
4833+
(list string)
4834+
; field "since"
4835+
(fun (r : input_t) ->
4836+
Livepatch.to_json r.since |> Yojson.Basic.pretty_to_string
4837+
)
4838+
string
4839+
]
4840+
4841+
let string_of_input_t = Fmt.(str "%a" Dump.(record @@ fields_of_input))
4842+
4843+
let string_of_output_t l =
4844+
Fmt.(str "%a" Dump.(list (pair string string)))
4845+
(List.map (fun (lp, id) -> (LivePatch.to_string lp, id)) l)
4846+
end
4847+
4848+
let transform Io.{updates_info; since} =
4849+
let updates_info = List.map (fun x -> (x.UpdateInfo.id, x)) updates_info in
4850+
get_accumulative_livepatches ~updates_info ~since
4851+
|> List.map (fun (lp, x) -> (lp, x.UpdateInfo.id))
4852+
4853+
let running_build_id = "2dd4f262f044a1f5af78aaa6e71f97ce956ad74e"
4854+
4855+
let lp =
4856+
LivePatch.
4857+
{
4858+
component= Xen
4859+
; base_build_id= ""
4860+
; base_version= "4.13.4"
4861+
; base_release= "10.24.xs8"
4862+
; to_version= ""
4863+
; to_release= ""
4864+
}
4865+
4866+
let update_info =
4867+
UpdateInfo.
4868+
{
4869+
id= ""
4870+
; summary= ""
4871+
; description= ""
4872+
; guidance= []
4873+
; guidance_applicabilities= []
4874+
; spec_info= ""
4875+
; url= ""
4876+
; update_type= "security"
4877+
; livepatches= []
4878+
; issued= Clock.Date.epoch
4879+
; severity= Severity.None
4880+
; title= ""
4881+
}
4882+
4883+
let tests =
4884+
`QuickAndAutoDocumented
4885+
[
4886+
( Io.
4887+
{
4888+
updates_info= [] (* No updates provide any live patches *)
4889+
; since=
4890+
Livepatch.
4891+
{
4892+
component= Xen
4893+
; base_build_id= running_build_id
4894+
; to_version= None (* No running live patch *)
4895+
; to_release= None
4896+
}
4897+
}
4898+
, []
4899+
)
4900+
; ( Io.
4901+
{
4902+
updates_info=
4903+
[
4904+
{
4905+
update_info with
4906+
id= "UPDATE-1"
4907+
; livepatches=
4908+
[
4909+
{
4910+
lp with
4911+
base_build_id= running_build_id
4912+
; to_version= "4.17.6"
4913+
; to_release= "1"
4914+
}
4915+
]
4916+
}
4917+
]
4918+
; since=
4919+
Livepatch.
4920+
{
4921+
component= Xen
4922+
; base_build_id= running_build_id
4923+
; to_version= None (* No running live patch *)
4924+
; to_release= None
4925+
}
4926+
}
4927+
, [
4928+
( {
4929+
lp with
4930+
base_build_id= running_build_id
4931+
; to_version= "4.17.6"
4932+
; to_release= "1"
4933+
}
4934+
, "UPDATE-1"
4935+
)
4936+
]
4937+
)
4938+
; ( Io.
4939+
{
4940+
updates_info=
4941+
[
4942+
{
4943+
update_info with
4944+
id= "UPDATE-1"
4945+
; livepatches=
4946+
[
4947+
{
4948+
lp with
4949+
base_build_id= running_build_id (* Can support *)
4950+
; to_version= "4.17.6"
4951+
; to_release= "1"
4952+
}
4953+
]
4954+
}
4955+
; {
4956+
update_info with
4957+
id= "UPDATE-2"
4958+
; livepatches=
4959+
[
4960+
{
4961+
lp with
4962+
base_build_id= running_build_id (* Can support *)
4963+
; to_version= "4.17.6"
4964+
; to_release= "2"
4965+
}
4966+
; {
4967+
lp with
4968+
base_build_id=
4969+
"67edb2dca295cbc1591a1802c52015e0b875812d"
4970+
; to_version= "4.17.6"
4971+
; to_release= "2"
4972+
}
4973+
]
4974+
}
4975+
]
4976+
; since=
4977+
Livepatch.
4978+
{
4979+
component= Xen
4980+
; base_build_id= running_build_id
4981+
; to_version= None (* No running live patch *)
4982+
; to_release= None
4983+
}
4984+
}
4985+
, [
4986+
( {
4987+
lp with
4988+
base_build_id= running_build_id
4989+
; to_version= "4.17.6"
4990+
; to_release= "2"
4991+
}
4992+
, "UPDATE-2"
4993+
)
4994+
; ( {
4995+
lp with
4996+
base_build_id= running_build_id
4997+
; to_version= "4.17.6"
4998+
; to_release= "1"
4999+
}
5000+
, "UPDATE-1"
5001+
)
5002+
]
5003+
)
5004+
; ( Io.
5005+
{
5006+
updates_info=
5007+
[
5008+
{
5009+
update_info with
5010+
id= "UPDATE-1"
5011+
; livepatches=
5012+
[
5013+
{
5014+
lp with
5015+
base_build_id= running_build_id (* Can support *)
5016+
; to_version= "4.17.6"
5017+
; to_release= "1"
5018+
}
5019+
]
5020+
}
5021+
; {
5022+
update_info with
5023+
id= "UPDATE-2"
5024+
; livepatches=
5025+
[
5026+
{
5027+
lp with
5028+
base_build_id= running_build_id (* Can support *)
5029+
; to_version= "4.17.6"
5030+
; to_release= "2"
5031+
}
5032+
; {
5033+
lp with
5034+
base_build_id=
5035+
"67edb2dca295cbc1591a1802c52015e0b875812d"
5036+
; to_version= "4.17.6"
5037+
; to_release= "2"
5038+
}
5039+
]
5040+
}
5041+
; {
5042+
update_info with
5043+
id= "UPDATE-3"
5044+
; livepatches=
5045+
(* Not suppported since this update *)
5046+
[
5047+
{
5048+
lp with
5049+
base_build_id=
5050+
"67edb2dca295cbc1591a1802c52015e0b875812d"
5051+
; to_version= "4.17.6"
5052+
; to_release= "3"
5053+
}
5054+
; {
5055+
lp with
5056+
base_build_id=
5057+
"332ed069fb106528e7161b31af07929375e4fdc6"
5058+
; to_version= "4.17.6"
5059+
; to_release= "3"
5060+
}
5061+
]
5062+
}
5063+
]
5064+
; since=
5065+
Livepatch.
5066+
{
5067+
component= Xen
5068+
; base_build_id= running_build_id
5069+
; to_version= None (* No running live patch *)
5070+
; to_release= None
5071+
}
5072+
}
5073+
, [] (* No applicable live patches returned. *)
5074+
)
5075+
; ( Io.
5076+
{
5077+
updates_info=
5078+
[
5079+
{
5080+
update_info with
5081+
id= "UPDATE-1"
5082+
; livepatches=
5083+
[
5084+
{
5085+
lp with
5086+
base_build_id= running_build_id (* Can support *)
5087+
; to_version= "4.17.6"
5088+
; to_release= "1"
5089+
}
5090+
]
5091+
}
5092+
; {
5093+
update_info with
5094+
id= "UPDATE-2"
5095+
; livepatches=
5096+
[
5097+
{
5098+
lp with
5099+
base_build_id= running_build_id (* Can support *)
5100+
; to_version= "4.17.6"
5101+
; to_release= "2"
5102+
}
5103+
; {
5104+
lp with
5105+
base_build_id=
5106+
"67edb2dca295cbc1591a1802c52015e0b875812d"
5107+
; to_version= "4.17.6"
5108+
; to_release= "2"
5109+
}
5110+
]
5111+
}
5112+
; {
5113+
update_info with
5114+
id= "UPDATE-3"
5115+
; livepatches=
5116+
[
5117+
{
5118+
lp with
5119+
base_build_id=
5120+
"67edb2dca295cbc1591a1802c52015e0b875812d"
5121+
; to_version= "4.17.6"
5122+
; to_release= "3"
5123+
}
5124+
; {
5125+
lp with
5126+
base_build_id=
5127+
"332ed069fb106528e7161b31af07929375e4fdc6"
5128+
; to_version= "4.17.6"
5129+
; to_release= "3"
5130+
}
5131+
]
5132+
}
5133+
]
5134+
; since=
5135+
Livepatch.
5136+
{
5137+
component= Xen
5138+
; base_build_id=
5139+
"67edb2dca295cbc1591a1802c52015e0b875812d"
5140+
(* The build id of the running component has been updated. *)
5141+
; to_version= None (* No running live patch *)
5142+
; to_release= None
5143+
}
5144+
}
5145+
, [
5146+
( {
5147+
lp with
5148+
base_build_id= "67edb2dca295cbc1591a1802c52015e0b875812d"
5149+
; to_version= "4.17.6"
5150+
; to_release= "3"
5151+
}
5152+
, "UPDATE-3"
5153+
)
5154+
; ( {
5155+
lp with
5156+
base_build_id= "67edb2dca295cbc1591a1802c52015e0b875812d"
5157+
; to_version= "4.17.6"
5158+
; to_release= "2"
5159+
}
5160+
, "UPDATE-2"
5161+
)
5162+
]
5163+
)
5164+
]
5165+
end)
5166+
48185167
let tests =
48195168
make_suite "repository_helpers_"
48205169
[
@@ -4841,6 +5190,7 @@ let tests =
48415190
)
48425191
; ("set_pending_guidances", SetPendingGuidance.tests)
48435192
; ("merge_livepatch_failures", MergeLivepatchFailures.tests)
5193+
; ("get_accumulative_livepatches", GetAccumulativeLivepatches.tests)
48445194
]
48455195

48465196
let () = Alcotest.run "Repository Helpers" tests

0 commit comments

Comments
 (0)