Skip to content

Commit

Permalink
Handle Invalid Output Directory (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
landonmsft authored Aug 24, 2023
1 parent 2a91168 commit 42ffd31
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ class UserInputExceptionDataGenerator : TheoryData<string, string>
public UserInputExceptionDataGenerator()
{
Add(nameof(UserInputException.ErrorMapping.UserInputExceptionInvalidTestSettings), TestEngineEventHandler.UserInputExceptionInvalidTestSettingsMessage);
Add(nameof(UserInputException.ErrorMapping.UserInputExceptionInvalidOutputPath), TestEngineEventHandler.UserInputExceptionInvalidOutputPathMessage);
Add(nameof(UserInputException.ErrorMapping.UserInputExceptionInvalidFilePath), TestEngineEventHandler.UserInputExceptionInvalidFilePathMessage);
Add(nameof(UserInputException.ErrorMapping.UserInputExceptionLoginCredential), TestEngineEventHandler.UserInputExceptionLoginCredentialMessage);
Add(nameof(UserInputException.ErrorMapping.UserInputExceptionTestConfig), TestEngineEventHandler.UserInputExceptionTestConfigMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class UserInputException : Exception
public enum ErrorMapping
{
UserInputExceptionInvalidFilePath,
UserInputExceptionInvalidOutputPath,
UserInputExceptionInvalidTestSettings,
UserInputExceptionLoginCredential,
UserInputExceptionTestConfig,
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.PowerApps.TestEngine/TestEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ public async Task<string> RunTestAsync(FileInfo testConfigFile, string environme
_eventHandler.EncounteredException(e);
return testRunDirectory;
}
catch (DirectoryNotFoundException)
{
_eventHandler.EncounteredException(new UserInputException(UserInputException.ErrorMapping.UserInputExceptionInvalidOutputPath.ToString()));
return "InvalidOutputDirectory";
}
catch (Exception e)
{
Logger.LogError(e.Message);
Expand Down
9 changes: 6 additions & 3 deletions src/Microsoft.PowerApps.TestEngine/TestEngineEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public class TestEngineEventHandler : ITestEngineEvents

// NOTE: Any changes to these messages need to be handled in the consuming tool's console event handler, like in pac cli tool.
// These console messages need to be considered for localization.
public static string UserInputExceptionInvalidTestSettingsMessage = " Invalid test settings specified in testconfig. For more details, check the logs.";
public static string UserAppExceptionMessage = " [Critical Error] Could not access PowerApps. For more details, check the logs.";
public static string UserInputExceptionInvalidFilePathMessage = " Invalid file path. For more details, check the logs.";
public static string UserInputExceptionInvalidOutputPathMessage = " [Critical Error]: The output directory provided is invalid.";
public static string UserInputExceptionInvalidTestSettingsMessage = " Invalid test settings specified in testconfig. For more details, check the logs.";
public static string UserInputExceptionLoginCredentialMessage = " Invalid login credential(s). For more details, check the logs.";
public static string UserInputExceptionTestConfigMessage = " Invalid test config. For more details, check the logs.";
public static string UserInputExceptionYAMLFormatMessage = " Invalid YAML format. For more details, check the logs.";

public static string UserAppExceptionMessage = " [Critical Error] Could not access PowerApps. For more details, check the logs.";

public int CasesPassed { get => _casesPassed; set => _casesPassed = value; }
public int CasesTotal { get => _casesTotal; set => _casesTotal = value; }

Expand Down Expand Up @@ -64,6 +64,9 @@ public void EncounteredException(Exception ex)
case nameof(UserInputException.ErrorMapping.UserInputExceptionYAMLFormat):
Console.WriteLine(UserInputExceptionYAMLFormatMessage);
break;
case nameof(UserInputException.ErrorMapping.UserInputExceptionInvalidOutputPath):
Console.WriteLine(UserInputExceptionInvalidOutputPathMessage);
break;
default:
Console.WriteLine($" {ex.Message}");
break;
Expand Down
6 changes: 5 additions & 1 deletion src/PowerAppsTestEngine/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@

//setting defaults for optional parameters outside RunTestAsync
var testResult = await testEngine.RunTestAsync(testPlanFile, environmentId, tenantId, outputDirectory, domain, queryParams);
Console.WriteLine($"Test results can be found here: {testResult}");
if (testResult != "InvalidOutputDirectory")
{
Console.WriteLine($"Test results can be found here: {testResult}");
}

}
catch (Exception ex)
{
Expand Down

0 comments on commit 42ffd31

Please sign in to comment.