Skip to content

Commit

Permalink
test: add test case for using -env in phases
Browse files Browse the repository at this point in the history
  • Loading branch information
isc-shuliu committed Jan 16, 2025
1 parent b84c7e8 commit 375dbfa
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 31 deletions.
58 changes: 58 additions & 0 deletions tests/integration_tests/Test/PM/Integration/EnvironmentConfig.cls
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 tests/integration_tests/Test/PM/Integration/InstallTimeConfig.cls

This file was deleted.

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"
}
}
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>
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
}

}

0 comments on commit 375dbfa

Please sign in to comment.