Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: validate --Output #808

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Commands;

using System;
using System.ComponentModel;
using System.IO;
using Serilog.Events;
using Spectre.Console;
using Spectre.Console.Cli;
Expand Down Expand Up @@ -44,6 +45,11 @@ public override ValidationResult Validate()
return ValidationResult.Error($"{nameof(this.Timeout)} must be a positive integer");
}

if (!string.IsNullOrEmpty(this.Output) && !Directory.Exists(this.Output))
{
return ValidationResult.Error($"{nameof(this.Output)} must be a valid path");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description probably needs to be updated

Output path for log files. Defaults to %TMP%

}

return base.Validate();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
namespace Microsoft.ComponentDetection.Orchestrator.Tests.Commands;

using System.IO;
using FluentAssertions;
using Microsoft.ComponentDetection.Orchestrator.Commands;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
[TestCategory("Governance/All")]
[TestCategory("Governance/ComponentDetection")]
public class BaseSettingsTests
{
[TestMethod]
public void Validate_FailsNegativeTimeout()
{
var settings = new TestBaseSettings
{
Timeout = -1,
};

var result = settings.Validate();

result.Successful.Should().BeFalse();
}

[TestMethod]
public void Validate_Success_Empty_Output()
{
var settings = new TestBaseSettings
{
Output = string.Empty,
};

var result = settings.Validate();

result.Successful.Should().BeTrue();
}

[TestMethod]
public void Validate_Fails_Output_NotExists()
{
var setting = new TestBaseSettings
{
Output = Path.Combine(Path.GetTempPath(), Path.GetTempFileName()),
};

var result = setting.Validate();

result.Successful.Should().BeFalse();
}

private class TestBaseSettings : BaseSettings
{
}
}