-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
246 additions
and
27 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
...tomation/assets-maintenance-tool/Azure.Sdk.Tools.Assets.MaintenanceTool.Tests/CLITests.cs
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,59 @@ | ||
global using NUnit.Framework; | ||
using Azure.Sdk.Tools.Assets.MaintenanceTool.Model; | ||
using Azure.Sdk.Tools.Assets.MaintenanceTool.Scan; | ||
using Microsoft.AspNetCore.Http; | ||
using Newtonsoft.Json; | ||
|
||
namespace Azure.Sdk.Tools.Assets.MaintenanceTool.Tests | ||
{ | ||
public class CLITests | ||
{ | ||
public string TestDirectory { get; protected set; } | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
var workingDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); | ||
|
||
if (!Directory.Exists(workingDirectory)) | ||
{ | ||
Directory.CreateDirectory(workingDirectory); | ||
} | ||
|
||
// copy our static test files there | ||
var source = Path.Combine(Directory.GetCurrentDirectory(), "TestResources"); | ||
var target = Path.Combine(workingDirectory, "TestResources"); | ||
|
||
Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(source, target); | ||
|
||
TestDirectory = workingDirectory; | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
Directory.Delete(TestDirectory, true); | ||
} | ||
|
||
[Test] | ||
[TestCase("scan", "-c", "")] | ||
[TestCase("scan", "--config", "")] | ||
public void TestScanOptions(params string[] args) | ||
{ | ||
} | ||
|
||
[Test] | ||
[TestCase("scan")] | ||
[TestCase("scan", "--config")] | ||
public void TestInvalidScanOptions(params string[] args) | ||
{ | ||
var obj = new object(); | ||
|
||
var rootCommand = Program.InitializeCommandOptions((DefaultOptions) => | ||
{ | ||
obj = DefaultOptions; | ||
}); | ||
|
||
} | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
....Assets.MaintenanceTool.Tests/TestResources/configurations/sample-repo-configuration.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,17 @@ | ||
{ | ||
"Repos": [ | ||
{ | ||
"Repo": "azure/azure-sdk-tools", | ||
"Branches": [ | ||
"integration/assets-test-branch" | ||
] | ||
}, | ||
{ | ||
"Repo": "azure/azure-sdk-assets-integration", | ||
"Branches": [ | ||
"integration/assets-branch-1", | ||
"integration/assets-branch-2" | ||
] | ||
} | ||
] | ||
} |
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
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
46 changes: 46 additions & 0 deletions
46
...ion/assets-maintenance-tool/Azure.Sdk.Tools.Assets.MaintenanceTool/Options/BaseOptions.cs
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,46 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.CommandLine; | ||
using System.CommandLine.Binding; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Azure.Sdk.Tools.TestProxy.CommandOptions; | ||
|
||
namespace Azure.Sdk.Tools.Assets.MaintenanceTool.Options | ||
{ | ||
public class BaseOptions | ||
{ | ||
public string ConfigLocation { get; set; } = string.Empty; | ||
} | ||
|
||
public class BaseOptionsBinder : BinderBase<BaseOptions> | ||
{ | ||
private readonly Option<string> _configLocationOption; | ||
|
||
public BaseOptionsBinder(Option<string> configLocationOption) | ||
{ | ||
_configLocationOption = configLocationOption; | ||
} | ||
|
||
protected override BaseOptions GetBoundValue(BindingContext bindingContext) | ||
{ | ||
var result = bindingContext.ParseResult.GetValueForOption(_configLocationOption); | ||
|
||
if (result != null) | ||
{ | ||
return new BaseOptions | ||
{ | ||
ConfigLocation = result | ||
}; | ||
} | ||
else | ||
{ | ||
return new BaseOptions | ||
{ | ||
ConfigLocation = string.Empty | ||
}; | ||
} | ||
} | ||
} | ||
} |
92 changes: 68 additions & 24 deletions
92
...sets-automation/assets-maintenance-tool/Azure.Sdk.Tools.Assets.MaintenanceTool/Program.cs
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 |
---|---|---|
@@ -1,39 +1,83 @@ | ||
using System.CommandLine; | ||
using Azure.Sdk.Tools.Assets.MaintenanceTool.Model; | ||
using Azure.Sdk.Tools.Assets.MaintenanceTool.Options; | ||
using Azure.Sdk.Tools.Assets.MaintenanceTool.Scan; | ||
|
||
namespace Azure.Sdk.Tools.Assets.MaintenanceTool | ||
{ | ||
internal class Program | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
// working directory is where we will look for scan_results.json | ||
public static string[] StoredArgs = new string[] { }; | ||
|
||
// all should honor | ||
// --ScanData <-- results from previous scans | ||
// working directory is where we will look for previous results "output.json" | ||
|
||
// all should honor | ||
// --ScanData <-- results from previous scans (todo, currently checks working directory) | ||
|
||
// SCAN | ||
// --configuration: -> path to file | ||
// SCAN | ||
// --configuration: -> path to file | ||
|
||
// BACKUP | ||
// --configuration provided? | ||
// SCAN | ||
// BACKUP | ||
// as each tag is backed up, it is saved with suffix _backup | ||
|
||
// BACKUP | ||
// --configuration provided? | ||
// SCAN | ||
// BACKUP | ||
// as each tag is backed up, it is saved with suffix _backup | ||
// RESTORE | ||
// --input-tag <tag that has been stored away> | ||
|
||
// RESTORE | ||
// --input-tag <tag that has been stored away> | ||
// CLEANUP | ||
// --configuration provided? | ||
// SCAN | ||
// BACKUP | ||
// CLEANUP | ||
// each tag as found by configuration | ||
|
||
// CLEANUP | ||
// --configuration provided? | ||
// SCAN | ||
// BACKUP | ||
// CLEANUP | ||
// each tag as found by configuration | ||
// --input-tag <tag on repo>? | ||
// SCAN, BACKUP, and CLEANUP individual tag | ||
public static void Main(string[] args) | ||
{ | ||
StoredArgs = args; | ||
|
||
var rootCommand = InitializeCommandOptions(Run); | ||
var resultCode = rootCommand.Invoke(args); | ||
Environment.Exit(resultCode); | ||
} | ||
|
||
public static void Run(object commandObj) | ||
{ | ||
switch (commandObj) | ||
{ | ||
case BaseOptions configOptions: | ||
AssetsScanner scanner = new AssetsScanner(); | ||
var runConfig = new RunConfiguration(configOptions.ConfigLocation); | ||
scanner.Scan(runConfig); | ||
break; | ||
default: | ||
throw new ArgumentException($"Unable to parse the argument set: {string.Join(" ", StoredArgs)}"); | ||
} | ||
} | ||
|
||
public static RootCommand InitializeCommandOptions(Action<BaseOptions> action) | ||
{ | ||
var root = new RootCommand(); | ||
var configOption = new Option<string>( | ||
name: "--config", | ||
description: "The path to the json file containing the repo configuration. A sample repo configuration can be seen under <SolutionDirectory>/integration-test-repo-configuration.yml." | ||
) { | ||
IsRequired = true | ||
}; | ||
configOption.AddAlias("-c"); | ||
|
||
// --input-tag <tag on repo>? | ||
// SCAN, BACKUP, and CLEANUP individual tag | ||
var scanCommand = new Command("scan", "Scan the repositories as configured within the file provided to input argument --config <yml config file>."); | ||
scanCommand.AddOption(configOption); | ||
scanCommand.SetHandler( | ||
(configOpts) => action(configOpts), | ||
new BaseOptionsBinder(configOption) | ||
); | ||
root.Add(scanCommand); | ||
|
||
Console.WriteLine("Hello, World!"); | ||
return root; | ||
} | ||
} | ||
} |
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
Empty file.
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ stages: | |
displayName: "Integration Tests" | ||
jobs: | ||
- job: Solution_Integration_Test | ||
name: Run Solution Tests | ||
|
||
strategy: | ||
matrix: | ||
|
@@ -38,6 +39,38 @@ stages: | |
condition: succeededOrFailed() | ||
inputs: | ||
testResultsFiles: '**/*.trx' | ||
testRunTitle: '$(OS) AssetSync tests against .NET' | ||
testRunTitle: '$(OS) Maintenance tool tests against .NET' | ||
testResultsFormat: 'VSTest' | ||
mergeTestResults: true | ||
|
||
- job: CLI_Integration_Test | ||
name: Invoke CLI Tool | ||
strategy: | ||
matrix: | ||
Linux: | ||
Pool: azsdk-pool-mms-ubuntu-2204-general | ||
OS: 'Linux' | ||
|
||
pool: | ||
name: $(Pool) | ||
|
||
steps: | ||
- template: /eng/pipelines/templates/steps/install-dotnet.yml | ||
|
||
- script: 'dotnet test /p:ArtifactsPackagesDir=$(Build.ArtifactStagingDirectory) --logger trx $(Build.SourcesDirectory)/tools/assets-automation/assets-maintenance-tool/' | ||
displayName: 'Test' | ||
env: | ||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 | ||
DOTNET_CLI_TELEMETRY_OPTOUT: 1 | ||
DOTNET_MULTILEVEL_LOOKUP: 0 | ||
GIT_TOKEN: $(azuresdk-github-pat) | ||
GIT_COMMIT_OWNER: azure-sdk | ||
GIT_COMMIT_EMAIL: [email protected] | ||
|
||
- task: PublishTestResults@2 | ||
condition: succeededOrFailed() | ||
inputs: | ||
testResultsFiles: '**/*.trx' | ||
testRunTitle: '$(OS) Maintenance tool tests against .NET' | ||
testResultsFormat: 'VSTest' | ||
mergeTestResults: true |