Skip to content

Commit dedd323

Browse files
James LechtnerJames Lechtner
authored andcommitted
Adding bulk of remaining tests for zpm "ci"
1 parent 26c1f47 commit dedd323

File tree

9 files changed

+162
-175
lines changed

9 files changed

+162
-175
lines changed

src/cls/IPM/Main.cls

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,105 +2460,6 @@ ClassMethod CleanInstall(ByRef commandInfo) [ Internal ]
24602460

24612461
// Forward execution to install
24622462
do ..Install(.commandInfo, log)
2463-
2464-
2465-
2466-
/*
2467-
zwrite commandInfo
2468-
return
2469-
set registry = ""
2470-
set moduleName = $get(commandInfo("parameters","module"))
2471-
if (moduleName["/") {
2472-
set $listbuild(registry, moduleName) = $listfromstring(moduleName, "/")
2473-
}
2474-
2475-
if pLog = "" {
2476-
set log = ##class(%IPM.General.HistoryTemp).CleanInstallInit(moduleName)
2477-
} else {
2478-
set log = pLog
2479-
}
2480-
2481-
try {
2482-
if (moduleName = "") {
2483-
$$$ThrowStatus($$$ERROR($$$GeneralError, "No module name specified."))
2484-
}
2485-
2486-
if moduleName = $$$IPMModuleName {
2487-
$$$ThrowOnError(..CheckModuleNamespace())
2488-
}
2489-
// check if any registries are configured and enabled
2490-
new SQLCODE, count
2491-
&sql(SELECT COUNT(*) into :count FROM %IPM_Repo.Definition WHERE Enabled = 1)
2492-
$$$ThrowSQLIfError(SQLCODE,%message)
2493-
if (SQLCODE = 0) && (count = 0) {
2494-
$$$ThrowStatus($$$ERROR($$$GeneralError, "No repositories are configured and enabled in this namespace."))
2495-
}
2496-
2497-
set version = $get(commandInfo("parameters","version"))
2498-
2499-
set searchCriteria = ##class(%IPM.Repo.SearchCriteria).%New()
2500-
set searchCriteria.Registry = registry
2501-
set searchCriteria.Name = $$$lcase(moduleName)
2502-
set searchCriteria.VersionExpression = version
2503-
$$$ThrowOnError(##class(%IPM.Repo.Utils).SearchRepositoriesForModule(searchCriteria,.results))
2504-
2505-
if (results.Count() > 0) {
2506-
set result = ""
2507-
#dim result As %IPM.Storage.QualifiedModuleInfo
2508-
// Results are ordered by semantic version, descending. (So the "latest" version will always be first.)
2509-
if ('$$$HasModifier(commandInfo,"prompt") || (results.Count() = 1)) { // && (tKeywords = "") {
2510-
set result = results.GetAt(1)
2511-
} elseif (results.Count() > 0) {
2512-
for i=1:1:results.Count() {
2513-
set tResultInfo = results.GetAt(i)
2514-
set tOptArray(i) = tResultInfo.DisplayName_" "_tResultInfo.VersionString_" @ "_tResultInfo.ServerName
2515-
}
2516-
2517-
set tValue = ""
2518-
set tResponse = ##class(%Library.Prompt).GetMenu("Which version?",.tValue,.tOptArray,,$$$InitialDisplayMask+$$$EnableQuitCharMask)
2519-
if (tResponse '= $$$SuccessResponse) {
2520-
$$$ThrowStatus($$$ERROR($$$GeneralError,"Operation cancelled."))
2521-
}
2522-
if (tValue '= "") {
2523-
set result = results.GetAt(tValue)
2524-
}
2525-
}
2526-
2527-
if (result '= "") {
2528-
do ##class(%IPM.Lifecycle.Base).GetDefaultParameters(.params)
2529-
merge params = commandInfo("data")
2530-
set params("cmd") = "ci"
2531-
set params("CleanInstall") = 1
2532-
set params("Verbose") = 1 // TODO: Replace this with actual new parameter instead of shoe-horning this in for logging at other parts of the loading
2533-
if result.Deployed {
2534-
set platformVersion = $system.Version.GetMajor() _ "." _$system.Version.GetMinor()
2535-
set result.PlatformVersion = platformVersion
2536-
if ('result.PlatformVersions.Find(platformVersion)) {
2537-
$$$ThrowStatus($$$ERROR($$$GeneralError, "Deployed package '"_moduleName_"' "_result.VersionString_" not supported on this platform "_platformVersion_"."))
2538-
}
2539-
}
2540-
$$$ThrowOnError(log.SetSource(result.ServerName))
2541-
$$$ThrowOnError(log.SetVersion(result.Version))
2542-
$$$ThrowOnError(##class(%IPM.Utils.Module).LoadQualifiedReference(result, .params, , log))
2543-
}
2544-
} else {
2545-
set tPrefix = ""
2546-
if (moduleName '= "") {
2547-
if (version '= "") {
2548-
$$$ThrowStatus($$$ERROR($$$GeneralError, moduleName_" "_version_" not found in any repository."))
2549-
} else {
2550-
$$$ThrowStatus($$$ERROR($$$GeneralError, "'"_moduleName_"' not found in any repository."))
2551-
}
2552-
} else {
2553-
write !,"No modules found. Are there any repositories configured in the current namespace?"
2554-
}
2555-
}
2556-
} catch ex {
2557-
$$$ThrowOnError(log.Finalize(ex.AsStatus()))
2558-
throw ex
2559-
}
2560-
$$$ThrowOnError(log.Finalize($$$OK))
2561-
*/
25622463
}
25632464

25642465
ClassMethod Reinstall(ByRef pCommandInfo) [ Internal ]

tests/integration_tests/Test/PM/Integration/LockFile.cls

Lines changed: 34 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ Method Test04Module2Dependencies1Transient()
127127
/// Edge cases below:
128128
/// All repository types
129129
/// Uses Module G
130-
/// TODO: Update lock-mod-oras: Created lock file with mods-other-repos filesystem repo instead of oras + remote repo
131-
Method Test05ModuleDependenciesAllRepositoryTypes()
130+
Method Test05AllRepositoryTypes()
132131
{
133132
set sc = $$$OK
134133
try {
@@ -165,41 +164,8 @@ Method Test05ModuleDependenciesAllRepositoryTypes()
165164
do $$$AssertStatusOK(sc,"Removed lock-file-other-repos repo successfully.")
166165

167166
// Now that modules and repositories are set up, do the actual test
168-
set moduleName = "lock-mod-oras"
169-
do ..AssertInstallCreatesLockFileAsExpected(moduleName)
170-
171-
// Go back to the initial state by uninstalling the module, dependencies, and repositories used for this test
172-
do ##class(%IPM.Main).Shell("uninstall -r "_moduleName)
173-
do $$$AssertStatusOK(sc, "Uninstalled "_moduleName_" and dependencies at the end of the test")
174-
175-
176-
// Now test installing from a lock file from a module in a remote repository
177-
set moduleName = "lock-mod-remote"
178-
179-
// TODO: Replace this with zpm "ci" once implemented
180-
set sc = ##class(%IPM.Main).Shell("install "_remoteRepo_"/"_moduleName)
181-
do $$$AssertStatusOK(sc, "Installed "_moduleName_" via the laock file successfully")
182-
183-
// Confirm that module and dependency classes were loaded correctly
184-
do $classmethod("LockModRemote.Class1", "MethodA")
185-
186-
187-
// Now test installing from a lock file from a module in an oras repository
188-
set moduleName = "lock-mod-oras"
189-
190-
// TODO: Replace this with zpm "ci" once implemented
191-
set sc = ##class(%IPM.Main).Shell("install "_orasRepo_"/"_moduleName)
192-
do $$$AssertStatusOK(sc, "Installed "_moduleName_" via the laock file successfully")
193-
194-
// Confirm that module and dependency classes were loaded correctly
195-
do $classmethod("LockModORAS.Class1", "MethodA")
196-
197-
198-
199-
200-
201-
202-
167+
do ..ExecuteGenericLockFileTest(remoteMod, "LockModRemote.Class1")
168+
do ..ExecuteGenericLockFileTest(orasMod, "LockModORAS.Class1")
203169

204170
do ##class(%IPM.Main).Shell("repo -delete -name "_remoteRepo)
205171
do $$$AssertStatusOK(sc, "Removed "_remoteRepo_" at the end of the test")
@@ -236,11 +202,11 @@ Method Test06ModuleMultipleVersions()
236202
do $$$AssertStatusOK(sc, "Uninstalled "_moduleName)
237203

238204
// Install module from lock file
239-
// TODO: Replace this with zpm "ci" once implemented
240-
set sc = ##class(%IPM.Main).Shell("install "_moduleName)
205+
set sc = ##class(%IPM.Main).Shell("ci "_moduleName)
206+
do $$$AssertStatusOK(sc, "Able to install "_moduleName_" v"_latestVersion_" from the lock file")
241207

242208
// Confirm classes and dependencies get installed as well
243-
do $classmethod("LockModH.Class1", "MethodA")
209+
do $classmethod("LockModH.Class1", "MethodB")
244210

245211
// Uninstall module before testing with other version
246212
set sc = ##class(%IPM.Main).Shell("uninstall -r "_moduleName)
@@ -267,8 +233,8 @@ Method Test06ModuleMultipleVersions()
267233
do $$$AssertStatusOK(sc, "Uninstalled "_moduleName)
268234

269235
// Install module from lock file
270-
// TODO: Replace this with zpm "ci" once implemented
271-
set sc = ##class(%IPM.Main).Shell("install "_moduleName)
236+
set sc = ##class(%IPM.Main).Shell("ci "_moduleName_" "_olderVersion)
237+
do $$$AssertStatusOK(sc, "Able to install "_moduleName_" v"_olderVersion_" from the lock file")
272238

273239
// Confirm classes and dependencies get installed as well
274240
do $classmethod("LockModH.Class1", "MethodA")
@@ -278,10 +244,10 @@ Method Test06ModuleMultipleVersions()
278244
}
279245

280246
/// Module with no pre-existing lock file
281-
/// - [TODO, with "ci" command] zpm "ci" should fail due to not being able to locate the lock file
282247
/// - Test creation of a lock file, for a module that did not already have one.
283248
/// - Differs from other tests which overwrite pre-existing lock files
284249
/// - Both cases SHOULD be functionally equivalent
250+
/// - zpm "ci" should fail due to not being able to locate the lock file
285251
/// Uses Module I
286252
Method Test07ModuleNoLockFile()
287253
{
@@ -302,22 +268,28 @@ Method Test07ModuleNoLockFile()
302268
set sc = ##class(%IPM.Main).Shell("uninstall -r "_moduleName)
303269
do $$$AssertStatusOK(sc, "Uninstalled "_moduleName)
304270

305-
// TODO: This should fail due to no lock file
306-
//Install module from lock file
307-
//do ..AssertInstallFromLockFileAsExpected(moduleName)
271+
// This should fail due to no lock file
272+
set sc = ##class(%IPM.Main).Shell("ci "_moduleName)
273+
do $$$AssertStatusNotOK(sc, "zpm ""ci"" fails on module "_moduleName_"due to not having a lock file")
308274
} catch e {
309275
do $$$AssertStatusOK(e.AsStatus(),"An exception occurred in Test07ModuleNoLockFile.")
310276
}
311277
}
312278

279+
/// TODO: This succeeds, compiling modules doesn't see dependency issues and by the time
280+
/// we call LockModJ.Class1::MethodA() all dependencies are loaded so no issues there.
281+
/// - Is that okay?
282+
/// - I'm inclined to say yes. Dependencies out of order isn't too realistic a use case
283+
/// anyways so maybe delete this case altogether?
313284
/// Try install on a lock file that lists dependencies out of order
314285
/// Uses Module J
315286
Method Test08ModuleDependenciesOutOfOrder()
316287
{
317288
set moduleName = ..#ModuleJ
318289

319-
// TODO: Replace this with zpm "ci" once implemented
320-
//set sc = ##class(%IPM.Main).Shell("install "_moduleName)
290+
zpm "install -lock "_moduleName
291+
292+
//set sc = ##class(%IPM.Main).Shell("ci "_moduleName)
321293
//do $$$AssertStatusNotOK(sc, "Installing from lock file with dependencies listed out of order fails")
322294
}
323295

@@ -349,7 +321,9 @@ Method Test10ComplexNestedDependencies()
349321
/// 3. Uninstall the module (and dependencies)
350322
/// 4. Install from lock file via zpm "ci"
351323
/// 5. Call method in installed module (which in turn calls dependency methods) to confirm "ci" loads all modules correctly
352-
Method ExecuteGenericLockFileTest(moduleName As %String)
324+
Method ExecuteGenericLockFileTest(
325+
moduleName As %String,
326+
className As %String = "")
353327
{
354328
// Install and create lock file for module
355329
do ..AssertInstallCreatesLockFileAsExpected(moduleName)
@@ -359,7 +333,7 @@ Method ExecuteGenericLockFileTest(moduleName As %String)
359333
do $$$AssertStatusOK(sc, "Uninstalled "_moduleName)
360334

361335
// Install module from lock file
362-
do ..AssertInstallFromLockFileAsExpected(moduleName)
336+
do ..AssertInstallFromLockFileAsExpected(moduleName, className)
363337
}
364338

365339
/// Base cases of creating a lock file upon install of a module
@@ -390,8 +364,6 @@ ClassMethod AreLockFilesEqual(
390364
try {
391365
set actualLockFileContents = ##class(%DynamicAbstractObject).%FromJSONFile(actualLockFilePath)
392366
set expectedLockFileContents = ##class(%DynamicAbstractObject).%FromJSONFile(expectedLockFilePath)
393-
zwrite actualLockFileContents
394-
zwrite expectedLockFileContents
395367
return actualLockFileContents.%ToJSON() = expectedLockFileContents.%ToJSON()
396368
} catch (ex) {
397369
// Should error if we fail to open either the actual or expected file
@@ -400,16 +372,20 @@ ClassMethod AreLockFilesEqual(
400372
}
401373

402374
/// Base case of installing a module from a lock file and confirming everything gets loaded as expected
403-
Method AssertInstallFromLockFileAsExpected(moduleName As %String)
375+
Method AssertInstallFromLockFileAsExpected(
376+
moduleName As %String,
377+
className As %String = "")
404378
{
405-
// TODO: Replace this with zpm "ci" once implemented
406-
set sc = ##class(%IPM.Main).Shell("install "_moduleName)
379+
set sc = ##class(%IPM.Main).Shell("ci "_moduleName)
380+
do $$$AssertStatusOK(sc, "Installed "_moduleName_" via the lock file successfully")
407381

408382
set sc = $$$OK
409383
try {
410-
// Letter of the module is in the 10th place: "lock-mod-x-..."
411-
set packageLetter = $zconvert($extract(moduleName, 10), "u")
412-
set className = "LockMod"_packageLetter_".Class1"
384+
if (className = "") {
385+
// Letter of the module is in the 10th place: "lock-mod-x-..."
386+
set packageLetter = $zconvert($extract(moduleName, 10), "u")
387+
set className = "LockMod"_packageLetter_".Class1"
388+
}
413389
do $classmethod(className, "MethodA")
414390
} catch (ex) {
415391
set sc = ex.AsStatus()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "lock-mod-remote",
3+
"version": "1.0.0",
4+
"repository": "lock-file-remote",
5+
"lockFileVersion": "1",
6+
"repositories": {
7+
"lock-file-base": {
8+
"type": "filesystem",
9+
"readOnly": false,
10+
"root": "/home/irisowner/zpm/tests/integration_tests/Test/PM/Integration/_data/lock-test/mods-base-cases/",
11+
"depth": 0
12+
},
13+
"lock-file-remote": {
14+
"type": "remote",
15+
"readOnly": false,
16+
"url": "http://registry:52773/registry"
17+
}
18+
},
19+
"dependencies": {
20+
"lock-mod-a-no-deps": {
21+
"version": "1.0.0",
22+
"repository": "lock-file-base"
23+
},
24+
"lock-mod-e-1-dep-0-transient": {
25+
"version": "1.0.0",
26+
"repository": "lock-file-base",
27+
"dependencies": {
28+
"lock-mod-a-no-deps": "^1.0.0"
29+
}
30+
}
31+
}
32+
}

tests/integration_tests/Test/PM/Integration/_data/lock-test/mods-edge-cases/lock-mod-h-multiple-versions-v2/cls/LockModH/Class1.cls

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ ClassMethod MethodA()
55
{
66
write !, "This is LockModH v2 ##class(LockModH.Class1).MethodA()"
77

8-
write !, "Now calling dependency classes (LockModB, LockModE)"
9-
do ##class(LockModB.Class1).MethodA()
8+
write !, "Now calling dependency classes (LockModA, LockModE)"
109
do ##class(LockModE.Class1).MethodA()
1110
}
1211

Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
Class LockModH.Class1
22
{
33

4-
ClassMethod MethodA()
4+
/// Method renamed from MethodA in v2 to MethodB in v3
5+
ClassMethod MethodB()
56
{
6-
write !, "This is LockModH v3 ##class(LockModH.Class1).MethodA()"
7+
write !, "This is LockModH v3 ##class(LockModH.Class1).MethodB()"
78

8-
write !, "Now calling dependency classes (LockModA, LockModB, LockModE)"
9-
do ##class(LockModA.Class1).MethodA()
10-
do ##class(LockModB.Class1).MethodA()
9+
write !, "Now calling dependency classes (LockModE, LockModB)"
1110
do ##class(LockModE.Class1).MethodA()
11+
do ##class(LockModB.Class1).MethodA()
1212
}
1313

1414
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "lock-mod-j-deps-misordered",
3+
"version": "1.0.0",
4+
"repository": "lock-file-edge",
5+
"lockFileVersion": "1",
6+
"repositories": {
7+
"lock-file-base": {
8+
"type": "filesystem",
9+
"readOnly": false,
10+
"root": "/home/irisowner/zpm/tests/integration_tests/Test/PM/Integration/_data/lock-test/mods-base-cases/",
11+
"depth": 0
12+
},
13+
"lock-file-edge": {
14+
"type": "filesystem",
15+
"readOnly": false,
16+
"root": "/home/irisowner/zpm/tests/integration_tests/Test/PM/Integration/_data/lock-test/mods-edge-cases/",
17+
"depth": 0
18+
}
19+
},
20+
"dependencies": {
21+
"lock-mod-c-2-deps-0-transient": {
22+
"version": "1.0.0",
23+
"repository": "lock-file-base",
24+
"dependencies": {
25+
"lock-mod-a-no-deps": "^1.0.0",
26+
"lock-mod-b-no-deps": "^1.0.0"
27+
}
28+
},
29+
"lock-mod-a-no-deps": {
30+
"version": "1.0.0",
31+
"repository": "lock-file-base"
32+
},
33+
"lock-mod-b-no-deps": {
34+
"version": "1.0.0",
35+
"repository": "lock-file-base"
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)