From 0f254d1d3b5616a388bb333eabf41c4dc7488454 Mon Sep 17 00:00:00 2001 From: Shuheng Liu Date: Fri, 25 Oct 2024 10:26:24 -0400 Subject: [PATCH] wip: remove dummy modules in integration tests Somehow it's not working, all modules are removed ?! --- .../Test/PM/Integration/Base.cls | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/integration_tests/Test/PM/Integration/Base.cls b/tests/integration_tests/Test/PM/Integration/Base.cls index b033f0c7..762f0dfd 100644 --- a/tests/integration_tests/Test/PM/Integration/Base.cls +++ b/tests/integration_tests/Test/PM/Integration/Base.cls @@ -1,3 +1,5 @@ +Include %IPM.Common + Class Test.PM.Integration.Base Extends %UnitTest.TestCase { @@ -13,11 +15,18 @@ Property ClientNSCreated As %Boolean [ InitialExpression = 0 ]; Property RegistryAdded As %Boolean [ InitialExpression = 0 ]; +Property PreexistingModules As %Library.ArrayOfDataTypes; + +Property OriginalNamespace As %String; + +// Multidimensional doesn't work well + Method Setup() As %Status { Set tSC = $$$OK Try { New $Namespace + Set tSC = $$$ADDSC(tSC, ..RecordOldModules()) do $$$AssertStatusOK(##class(%IPM.Repo.Filesystem.Definition).%DeleteExtent()) do $$$AssertStatusOK(##class(%IPM.Repo.Remote.Definition).%DeleteExtent()) @@ -69,12 +78,53 @@ Method TearDown() As %Status if ..RegistryAdded { Do $$$AssertStatusOK(##class(%IPM.Repo.Definition).ServerDefinitionKeyDelete(..#REGISTRYNAME)) } + Set tSC = $$$ADDSC(tSC, ..DeleteNewModules()) } Catch e { Set tSC = e.AsStatus() } Quit tSC } +Method DeleteNewModules() As %Status +{ + Set sc = $$$OK + Try { + Do ##class(%IPM.Main).GetListModules(..OriginalNamespace, "", .list) + Zwrite "", "DeleteNewModules", $classname(), list + For i = 1:1:list { + Set modName = $ListGet(list(i)) + // $$$IPMModuleName should be already in PreexistingModules, but just in case + If modName = $$$IPMModuleName { + Continue + } + If ..PreexistingModules.IsDefined(modName) { + Set sc = $$$ADDSC(sc, ##class(%IPM.Main).Shell("uninstall "_modName)) + } + } + } Catch e { + Set sc = $$$ADDSC(sc, e.AsStatus()) + } + Return sc +} + +/// OnBeforeAllTests is not compatible with $$$AssertSkipped +Method RecordOldModules() As %Status +{ + Try { + Set ..OriginalNamespace = $Namespace + Do ##class(%IPM.Main).GetListModules($Namespace, "", .list) + Zwrite "", "RecordOldModules", $classname(), list + Do ..PreexistingModules.Clear() + For i = 1:1:list { + Set modName = $ListGet(list(i)) + Do ..PreexistingModules.SetAt("", modName) + } + } Catch e { + Return e.AsStatus() + } + Return $$$OK +} + ClassMethod ReadXDataToModule(pNamespace As %String = {$NAMESPACE}, pXDataName As %String, ByRef pModule As %IPM.Storage.Module) As %Status { New $Namespace