-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test case for using -env in phases
- Loading branch information
1 parent
b84c7e8
commit 375dbfa
Showing
5 changed files
with
105 additions
and
31 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
tests/integration_tests/Test/PM/Integration/EnvironmentConfig.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
Class Test.PM.Integration.EnvironmentConfig Extends Test.PM.Integration.Base | ||
{ | ||
|
||
Method TestInstallTimeConfig() | ||
{ | ||
Set TargetPath = "install-time-config" | ||
Set localRepoPath = ..GetModuleDir(TargetPath) | ||
Set packageName = "install-time-config" | ||
Set envPath1 = ##class(%File).Construct($Get(^UnitTestRoot), "_data", TargetPath, "env1.json") | ||
Set envPath2 = ##class(%File).Construct($Get(^UnitTestRoot), "_data", TargetPath, "env2.json") | ||
|
||
Set tSC = ##class(%IPM.Main).Shell("repo -fs -name local -path " _ localRepoPath) | ||
Do $$$AssertStatusOK(tSC, "Set up local repo successfully") | ||
|
||
Do ##class(%IPM.Utils.Module).BeginCaptureOutput(.cookie) | ||
// If the env.json files is not properly read, the RunOnLoad() method generator in the package will throw an error, causing a `Compile` failure | ||
Set tSC = ##class(%IPM.Main).Shell($$$FormatText("install %1 -env %2;%3", packageName, envPath1, envPath2)) | ||
Do ##class(%IPM.Utils.Module).EndCaptureOutput(cookie, .output) | ||
Do $$$AssertStatusOK(tSC, "Installed module with its dependency successfully") | ||
Do $$$AssertTrue(..FindStringInMultiDimArray("Successfully acquired magic value: 1234", .output)) | ||
Do $$$AssertTrue(..FindStringInMultiDimArray("Successfully acquired magic value: 42", .output)) | ||
|
||
Set tSC = ##class(%IPM.Main).Shell("repo -delete-all") | ||
Do $$$AssertStatusOK(tSC, "Deleted all repos successfully") | ||
|
||
Set tSC = ##class(%IPM.Main).Shell("repo -reset-defaults") | ||
Do $$$AssertStatusOK(tSC, "Reset repo to default successfully") | ||
} | ||
|
||
Method TestPhaseConfig() | ||
{ | ||
Set TargetPath = "phase-config" | ||
Set packagePath = ..GetModuleDir(TargetPath, "package") | ||
Set envPath = ##class(%File).Construct($Get(^UnitTestRoot), "_data", TargetPath, "env.json") | ||
Set packageName = "phase-config" | ||
|
||
Do ##class(%IPM.Utils.Module).BeginCaptureOutput(.cookie) | ||
Set tSC = ##class(%IPM.Main).Shell($$$FormatText("load %1 -env %2", packagePath, envPath)) | ||
Do ##class(%IPM.Utils.Module).EndCaptureOutput(cookie, .output) | ||
Do $$$AssertStatusOK(tSC, "Loaded module successfully") | ||
Do $$$AssertTrue(..FindStringInMultiDimArray("AfterCompile: xxx", .output)) | ||
|
||
For template = "verify %1 -only -env %2", "%1 verify -only -env %2" { | ||
Do ##class(%IPM.Utils.Module).BeginCaptureOutput(.cookie) | ||
Set tSC = ##class(%IPM.Main).Shell($$$FormatText(template, packageName, envPath)) | ||
Do ##class(%IPM.Utils.Module).EndCaptureOutput(cookie, .output) | ||
Do $$$AssertStatusOK(tSC, "Verified module successfully") | ||
Do $$$AssertTrue(..FindStringInMultiDimArray("BeforeVerify: yyy", .output)) | ||
} | ||
|
||
Do ##class(%IPM.Utils.Module).BeginCaptureOutput(.cookie) | ||
Set tSC = ##class(%IPM.Main).Shell($$$FormatText("%1 custom -env %2", packageName, envPath)) | ||
Do ##class(%IPM.Utils.Module).EndCaptureOutput(cookie, .output) | ||
Do $$$AssertStatusOK(tSC, "Ran custom phase ""MyPhase"" successfully") | ||
Do $$$AssertTrue(..FindStringInMultiDimArray("MyPhase: zzz", .output)) | ||
} | ||
|
||
} |
31 changes: 0 additions & 31 deletions
31
tests/integration_tests/Test/PM/Integration/InstallTimeConfig.cls
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
tests/integration_tests/Test/PM/Integration/_data/phase-config/env.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"phase-config": { | ||
"after-compile": "xxx", | ||
"before-verify": "yyy", | ||
"my-phase": "zzz" | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/integration_tests/Test/PM/Integration/_data/phase-config/package/module.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Export generator="Cache" version="25"> | ||
<Document name="phase-config.ZPM"> | ||
<Module> | ||
<Name>phase-config</Name> | ||
<Version>0.0.1</Version> | ||
<Packaging>module</Packaging> | ||
<SourcesRoot>src</SourcesRoot> | ||
<Resource Name="PhaseConfig.Main.CLS"></Resource> | ||
<Invoke Class="PhaseConfig.Main" Method="AfterCompile" Phase="Compile" When="After" /> | ||
<Invoke Class="PhaseConfig.Main" Method="BeforeVerify" Phase="Verify" When="Before" /> | ||
<Invoke Class="PhaseConfig.Main" Method="MyPhase" CustomPhase="Custom" /> | ||
</Module> | ||
</Document> | ||
</Export> |
25 changes: 25 additions & 0 deletions
25
...integration_tests/Test/PM/Integration/_data/phase-config/package/src/PhaseConfig/Main.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Class PhaseConfig.Main | ||
{ | ||
|
||
ClassMethod AfterCompile() | ||
{ | ||
Set config = ##class(%IPM.General.EnvironmentConfig).%Get() | ||
Set value = config.GetArg("phase-config", "after-compile") | ||
Write !, "AfterCompile: ", value | ||
} | ||
|
||
ClassMethod BeforeVerify() | ||
{ | ||
Set config = ##class(%IPM.General.EnvironmentConfig).%Get() | ||
Set value = config.GetArg("phase-config", "before-verify") | ||
Write !, "BeforeVerify: ", value | ||
} | ||
|
||
ClassMethod MyPhase() | ||
{ | ||
Set config = ##class(%IPM.General.EnvironmentConfig).%Get() | ||
Set value = config.GetArg("phase-config", "my-phase") | ||
Write !, "MyPhase: ", value | ||
} | ||
|
||
} |