Class KubeTestHelper
Misc local unit test helpers.
Namespace: Neon.Kube.Xunit
Assembly: Neon.Kube.Xunit.dll
Syntax
public static class KubeTestHelper
Fields
TestGID
ghcr.io/neonrelease/test image test group ID.
Declaration
public const string TestGID = "6666"
Field Value
Type | Description |
---|---|
string |
TestUID
ghcr.io/neonrelease/test image test user ID.
Declaration
public const string TestUID = "5555"
Field Value
Type | Description |
---|---|
string |
TestUsername
ghcr.io/neonrelease/test image test user name.
Declaration
public const string TestUsername = "test"
Field Value
Type | Description |
---|---|
string |
Methods
CaptureDeploymentLogsAndThrow(Exception, Type, string, int?)
Used by cluster deployment related unit tests to capture the deployment logs for deployment failures.
Declaration
public static void CaptureDeploymentLogsAndThrow(Exception e, Type testClassType, string testName, int? iteration = null)
Parameters
Type | Name | Description |
---|---|---|
Exception | e | Specifies the exception that reported the failure. |
Type | testClassType | Identifies the unit test class type. |
string | testName | Identifies the unit test. |
int? | iteration | Optionally specifies the test iteration. |
Remarks
Deployment logs will be copied to the user's ~/.neonkube-dev/test-logs/classname.testname[/iteration] folder.
This is pretty easy to use:
- Call ResetDeploymentTest(Type, string) at the top of your test methods, passing your test class type as well as the test method's name.
-
Wrap your test code in a
try/catch
and call this method in the exception handler.
That's all there is to it. The ResetDeploymentTest(Type, string)
call will clear any previously captured logs the first time it's called by
the test runner and will do nothing thereafter. When called, this method
copies the deployment log files from ~/.neonkube/logs/** to the
folder named like ~/.neonkube-dev/test-logs/... folder and then it
throws a NeonKubeException wrapping e
.
CreateTestFolder(params Tuple<string, string>[])
Creates and optionally populates a temporary test folder with test files.
Declaration
public static TempFolder CreateTestFolder(params Tuple<string, string>[] files)
Parameters
Type | Name | Description |
---|---|---|
Tuple<string, string>[] | files | The files to be created. The first item in each tuple entry will be the local file name and the second the contents of the file. |
Returns
Type | Description |
---|---|
TempFolder |
Remarks
note
Ensure that the TempFolder(string, string) returned is disposed so it and any files within will be deleted.
KillNeonCli()
Kills any neon.exe and neon-cli.exe processes. Call this when handling cluster deployment unit test failures to ensure that any orhpaned tool processes don't hand around.
Declaration
public static void KillNeonCli()
KubeTestManager()
Starts and returns a KubeTestManager() instance. This will put KubeHelper into test mode. You must dispose the instance before the tests complete to revert back to normal mode.
Declaration
public static KubeTestManager KubeTestManager()
Returns
Type | Description |
---|---|
KubeTestManager | The KubeTestManager(). |
ResetDeploymentTest(Type, string)
Resets deployment test related logs and also kills any neon.exe and neon-cli.exe processes to prepare for another test run. Call this method in your unit test, passing the type of your test class.
Declaration
public static void ResetDeploymentTest(Type testClassType, string testName)
Parameters
Type | Name | Description |
---|---|---|
Type | testClassType | Identifies the unit test class type. |
string | testName | Identifies the unit test. |
Remarks
This is used in conjunction with CaptureDeploymentLogsAndThrow(Exception, Type, string, int?) to capture deployment logs on test failures. This method handles the removal of any logs captured from previous test runs and CaptureDeploymentLogsAndThrow(Exception, Type, string, int?) is called when tests fail, capturing the logs and then wraps the test exception in a NeonKubeException and throws that.
These methods use the NEONTEST_CLUSTERDEPLOYMENT_classname_testname environment variable to coordinate, where classname is the fully qualified name of the test class and testname identifies the test. This environment variable is scoped to the test runner process. The NEONTEST_CLUSTERDEPLOYMENT_* environment variable won't exist the first time this method is called for a specific test class/test. This method removes any logs captured by previous runs of these tests when the variable isn't present and then sets the environment variable so subsequent calls in the context of the current test runner won't clear logs.
TempFolder(string, string)
Creates and populates a temporary test folder with a test file.
Declaration
public static TempFolder TempFolder(string filename, string data)
Parameters
Type | Name | Description |
---|---|---|
string | filename | The file data. |
string | data | The file name |
Returns
Type | Description |
---|---|
TempFolder |
Remarks
note
Ensure that the TempFolder(string, string) returned is disposed so it and any files within will be deleted.