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

Add Scan functionality for assets-maintenance-tool #6269

Merged
merged 44 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9e44786
move existing automation to this folder
scbedd May 8, 2023
2fbcab2
add project structure for new stuff
scbedd May 8, 2023
55b6547
ensure the backup tool is added to the solution
scbedd May 8, 2023
7ce17fd
some detail for myself
scbedd May 9, 2023
d66d730
skinning out what this project will actually look like on disk
scbedd May 10, 2023
b6e0599
getting further notes written down
scbedd May 10, 2023
84b0a1b
adding tests for integration
scbedd May 10, 2023
1397311
clean out the various result types
scbedd May 11, 2023
f3b972d
further progress
scbedd May 11, 2023
e0ba8a4
additional boilerplate
scbedd May 11, 2023
badb0af
basic invocation is working!
scbedd May 11, 2023
a5a6a13
first successful test! need to understand why multi-clone isn't worki…
scbedd May 11, 2023
3341316
tests now passing!
scbedd May 12, 2023
eb6a507
commit test updates
scbedd May 12, 2023
a96faa6
ensure that all tests can pass
scbedd May 12, 2023
318ac5b
extensive testing complete!
scbedd May 12, 2023
059d6db
add failing tests for verifying output!
scbedd May 12, 2023
f9e571e
add initial ci build
scbedd May 12, 2023
3286a94
committing progress
scbedd May 13, 2023
c6ebcae
Merge remote-tracking branch 'upstream/main' into feature/add-assets-…
scbedd May 13, 2023
49c6a20
repair outstanding issues with the parser
scbedd May 16, 2023
c55051b
tests are emplaced. one last algo update to allow restoring cached re…
scbedd May 19, 2023
47ccdf7
tests now working. loading in previous results appropriately
scbedd May 19, 2023
005ca98
tests now all working. we successfully integration test all functiona…
scbedd May 19, 2023
464ac97
adding new skip attribute so that CI will pass. adding a tests.yml to…
scbedd May 19, 2023
0ee37f5
cleanup
scbedd May 19, 2023
9484399
adding sample configs
scbedd May 20, 2023
62cb106
move the asset-sync scrips into the assets-automation folder. update …
scbedd May 31, 2023
b92bb12
Merge remote-tracking branch 'upstream/main' into feature/add-assets-…
scbedd May 31, 2023
e5e0572
merge upstream. small test name update
scbedd May 31, 2023
e8ffd7a
add missing test case for previous load functionality.
scbedd May 31, 2023
2eeea05
name: -> displayName:
scbedd May 31, 2023
e16ac14
order the object before outputting.
scbedd Jun 5, 2023
2d3d182
Merge remote-tracking branch 'upstream/main' into feature/add-assets-…
scbedd Jun 5, 2023
86626f8
updates to handle feedback from PR
scbedd Jun 6, 2023
17634e6
ensuring that we always newline before the function definition bracket
scbedd Jun 6, 2023
9cc9673
Update tools/assets-automation/README.md
scbedd Jun 7, 2023
bc6841d
Update tools/assets-automation/assets-maintenance-tool/Azure.Sdk.Tool…
scbedd Jun 7, 2023
c4df955
Update tools/assets-automation/assets-maintenance-tool/Azure.Sdk.Tool…
scbedd Jun 7, 2023
acf40c0
broke the tests, but have most of the stuff where I want it
scbedd Jun 7, 2023
bdac49a
resolve issue with failing config load
scbedd Jun 7, 2023
edcddd7
address remaining feedback. time for update of disk operations and gl…
scbedd Jun 8, 2023
c23f40b
global file using!
scbedd Jun 8, 2023
5c7b573
cleanup usings
scbedd Jun 8, 2023
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
21 changes: 11 additions & 10 deletions doc/development/powershell.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ This page contains guidelines for developing or updating powershell scripts used
Table of Contents
=================

* [TLDR](#tldr)
* [Structure](#structure)
* [Functionality](#functionality)
* [Style](#style)
* [Testing](#testing)
* [Unit Testing](#unit-testing)
* [Running Pester Tests](#running-pester-tests)
* [Local/Pipeline Functional Testing](#localpipeline-functional-testing)
- [Table of Contents](#table-of-contents)
- [TLDR](#tldr)
- [Structure](#structure)
- [Functionality](#functionality)
- [Style](#style)
- [Testing](#testing)
- [Unit Testing](#unit-testing)
- [Running Pester Tests](#running-pester-tests)
- [Local/Pipeline Functional Testing](#localpipeline-functional-testing)

## TLDR

Expand Down Expand Up @@ -110,13 +111,13 @@ Powershell scripts should be testable, via one or more methods:
Unit tests should be written for all scripts, and should utilize [Pester](https://pester.dev/).

- Tests can be located alongside scripts in a directory called `tests`.
- Example pester test suites: [job matrix tests](https://github.com/Azure/azure-sdk-tools/tree/main/eng/common/scripts/job-matrix/tests), [asset sync tests](https://github.com/Azure/azure-sdk-tools/blob/main/tools/asset-sync/assets.Tests.ps1)
- Example pester test suites: [job matrix tests](https://github.com/Azure/azure-sdk-tools/tree/main/eng/common/scripts/job-matrix/tests), [asset sync tests](https://github.com/Azure/azure-sdk-tools/blob/main/tools/assets-automation/asset-sync/assets.Tests.ps1)
- A CI pipeline should be defined to run scripts unit tests at the very least. See [archetype-sdk-tool-pwsh](https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/pipelines/templates/stages/archetype-sdk-tool-pwsh.yml) for how to do this.
- Script code should always be written so as much of the surface area as possible can be run via unit tests. Move code that calls out to external dependencies into modular functions, and simplify context/data structures passed to functions as much as possible to it can be easily mocked.

#### Running Pester Tests

(stolen from https://github.com/Azure/azure-sdk-tools/blob/main/tools/asset-sync/contributing.md).
(stolen from https://github.com/Azure/azure-sdk-tools/blob/main/tools/assets-automation/asset-sync/contributing.md).

> **First, ensure you have `pester` installed:**
>
Expand Down
9 changes: 9 additions & 0 deletions tools/assets-automation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Assets automation tooling

This directory contains tooling pertaining to the _support_ of externalized assets created by the [azure-sdk test-proxy](../test-proxy/Azure.Sdk.Tools.TestProxy/README.md).
scbedd marked this conversation as resolved.
Show resolved Hide resolved

| Directory | Description |
|---|---|
| [assets-maintenance-tool](./assets-maintenance-tool/README.md) | CLI tool used to scan, backup, and clean azure-sdk assets across all repositories. |
scbedd marked this conversation as resolved.
Show resolved Hide resolved
| [assets-reporting](./assets-reporting/README.md) | CLI tool used to audit current repositories and find status of test-proxy adoption on a per-package basis. Used to generate weekly reporting. |
| [asset-sync](./assets-reporting/README.md) | Deprecated initial version of `asset-sync` implementation. The current implementation ended up integrated directly into the `test-proxy` codebase, rather than existing as an external powershell script. |
scbedd marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

scbedd marked this conversation as resolved.
Show resolved Hide resolved
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>

<ItemGroup>
<Folder Include="TestResources\basic_output\" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Azure.Sdk.Tools.Assets.MaintenanceTool\Azure.Sdk.Tools.Assets.MaintenanceTool.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="TestResources\basic_output\output.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestResources\configurations\sample-repo-configuration.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
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
{
scbedd marked this conversation as resolved.
Show resolved Hide resolved
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);
scbedd marked this conversation as resolved.
Show resolved Hide resolved

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;
});

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;

namespace Azure.Sdk.Tools.Assets.MaintenanceTool.Tests
{
public class GitTokenSkipAttribute : NUnitAttribute, IApplyToTest
{
public GitTokenSkipAttribute() { }

public void ApplyToTest(Test test)
{
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TF_BUILD")) && string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GIT_TOKEN")))
{
new IgnoreAttribute("Skipping this test. Within a CI run, and GIT_TOKEN is not set.").ApplyToTest(test);
}
}
}
}
Loading