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

[in-proc backport] Rename project.assets.json to test.assets.json (#10060) #10074

Merged
merged 1 commit into from
May 4, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.IO;
using Microsoft.Azure.WebJobs.Script.Config;
using Microsoft.Azure.WebJobs.Script.Description;
using WebJobs.Script.Tests;
using Xunit;

namespace Microsoft.Azure.WebJobs.Script.Tests
{
public class PackageManagerTests
{
private static readonly ScriptSettingsManager SettingsManager = ScriptSettingsManager.Instance;

[Theory]
[InlineData(@"ProjectWithLockMatch", false)]
[InlineData(@"FunctionWithNoProject", false)]
Expand All @@ -23,20 +19,51 @@ public class PackageManagerTests
public void RequirePackageRestore_ReturnsExpectedResult(string projectPath, bool shouldRequireRestore)
{
projectPath = Path.Combine(Directory.GetCurrentDirectory(), "Description", "DotNet", "TestFiles", "PackageReferences", projectPath);
bool result = PackageManager.RequiresPackageRestore(projectPath);
try
{
CopyLockFile(projectPath);
bool result = PackageManager.RequiresPackageRestore(projectPath);

Assert.True(Directory.Exists(projectPath));

Assert.True(Directory.Exists(projectPath));
string message = $"Project in '{projectPath}' did not return expected result.";

// Using .True or .False (instead of .Equal) to trace additional information.
if (shouldRequireRestore)
{
Assert.True(result, message);
}
else
{
Assert.False(result, message);
}
}
finally
{
DeleteLockFile(projectPath);
}
}

string message = $"Project in '{projectPath}' did not return expected result.";
private static void CopyLockFile(string projectPath)
{
// We save the lock file as something other than 'project.assets.json' so it is not flagged by component governance.
// Only renaming to project.assets.json for the duration of the test.
string lockFile = Path.Combine(projectPath, DotNetConstants.ProjectLockFileName);
string sourceFile = Path.Combine(projectPath, "test.assets.json");

// Using .True or .False (instead of .Equal) to trace additional information.
if (shouldRequireRestore)
if (File.Exists(sourceFile))
{
Assert.True(result, message);
File.Copy(sourceFile, lockFile, true);
}
else
}

private static void DeleteLockFile(string projectPath)
{
// Clean up the 'project.assets.json' file so component governance does not flag it.
string lockFile = Path.Combine(projectPath, DotNetConstants.ProjectLockFileName);
if (File.Exists(lockFile))
{
Assert.False(result, message);
File.Delete(lockFile);
}
}
}
Expand Down
103 changes: 11 additions & 92 deletions test/WebJobs.Script.Tests/WebJobs.Script.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,9 @@
</ItemGroup>

<ItemGroup>
<None Include="..\WebJobs.Script.Tests.Integration\TestScripts\**\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>TestScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
</None>
</ItemGroup>

<ItemGroup>
<None Include="Description\DotNet\TestFiles\PackageReferences\ProjectWithLockMatch\function.proj">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Description\DotNet\TestFiles\PackageReferences\ProjectWithMismatchedLock\MismatchedPackageVersions\function.proj">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Description\DotNet\TestFiles\PackageReferences\ProjectWithMismatchedLock\MismatchedProjectDependencies\function.proj">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Description\DotNet\TestFiles\PackageReferences\ProjectWithoutLock\function.proj">
<None Include="..\WebJobs.Script.Tests.Integration\TestScripts\**">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<LinkBase>TestScripts</LinkBase>
</None>
</ItemGroup>

Expand Down Expand Up @@ -86,84 +71,18 @@
</ItemGroup>

<ItemGroup>
<None Update="Description\DotNet\TestFiles\DepsFiles\function.deps.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Description\DotNet\TestFiles\DepsFiles\function2.deps.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Description\DotNet\TestFiles\DepsFiles\RidNativeDeps\function.deps.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Description\DotNet\TestFiles\PackageReferences\FunctionWithNoProject\function.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Description\DotNet\TestFiles\PackageReferences\ProjectWithLockMatch\project.assets.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Description\DotNet\TestFiles\PackageReferences\ProjectWithMismatchedLock\MismatchedPackageVersions\project.lock.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Description\DotNet\TestFiles\PackageReferences\ProjectWithMismatchedLock\MismatchedProjectDependencies\project.assets.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Managment\Payloads\ExpectedConcurrencyPayload.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Managment\Payloads\ExpectedHostJsonPayload.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Managment\Payloads\ExpectedHttpExtensionsPayload.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Microsoft.Azure.WebJobs.Script.WebHost.deps.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestFixture\HostOptionsProviderTests\TestBasicBindings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestFixture\HostOptionsProviderTests\TestBasicConcurrency.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestFixture\HostOptionsProviderTests\TestDefaultConcurrency.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestFixture\HostOptionsProviderTests\TestIrregularNamingBindings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestFixture\HostOptionsProviderTests\TestMultipleBindings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestFixture\HostOptionsProviderTests\TestWihtoutExtensionsAttributeBindings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestFixture\HostOptionsProviderTests\TestWihtoutIOptionsFormatter.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Workers\Rpc\Resources\functions.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<None Remove="Resources\FileProvisioning\PowerShell\PSGalleryEmptyFeed.xml" />
<None Remove="Resources\FileProvisioning\PowerShell\PSGallerySampleFeed.xml" />
<None Remove="Resources\FileProvisioning\PowerShell\requirements_PSGalleryOffline.psd1" />
<None Remove="Resources\FileProvisioning\PowerShell\requirements_PSGalleryOnline.psd1" />
<None Remove="Resources\FileProvisioning\PowerShell\profile.ps1" />
<None Include="Description\DotNet\TestFiles\**\*.proj" />
<None Update="Description\DotNet\TestFiles\**" CopyToOutputDirectory="PreserveNewest" />
<None Update="Microsoft.Azure.WebJobs.Script.WebHost.deps.json" CopyToOutputDirectory="PreserveNewest" />
<None Update="TestFixture\HostOptionsProviderTests\*.json" CopyToOutputDirectory="PreserveNewest" />
<None Update="Workers\Rpc\Resources\**" CopyToOutputDirectory="PreserveNewest" />
<None Update="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
<None Remove="Resources\FileProvisioning\PowerShell\*" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Resources\FileProvisioning\PowerShell\PSGallerySampleFeed.xml" />
<EmbeddedResource Include="Resources\FileProvisioning\PowerShell\PSGalleryEmptyFeed.xml" />
<EmbeddedResource Include="Resources\FileProvisioning\PowerShell\requirements_PSGalleryOffline.psd1" />
<EmbeddedResource Include="Resources\FileProvisioning\PowerShell\requirements_PSGalleryOnline.psd1" />
<EmbeddedResource Include="Resources\FileProvisioning\PowerShell\profile.ps1">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Resources\FileProvisioning\PowerShell\*" />
<EmbeddedResource Update="Resources\FileProvisioning\PowerShell\profile.ps1" CopyToOutputDirectory="Never" />
</ItemGroup>

<Import Project="..\..\build\GrpcTestFix.targets" />
Expand Down