Skip to content

Commit

Permalink
Add integration tests for symbol downloads (loic-sharma#665)
Browse files Browse the repository at this point in the history
  • Loading branch information
loic-sharma authored Jul 12, 2021
1 parent 6d391b3 commit 4379105
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 117 deletions.
110 changes: 77 additions & 33 deletions tests/BaGet.Tests/ApiIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ public class ApiIntegrationTests : IClassFixture<BaGetWebApplicationFactory>
private readonly WebApplicationFactory<Startup> _factory;
private readonly HttpClient _client;

private readonly Stream _packageStream;
private readonly Stream _symbolPackageStream;

public ApiIntegrationTests(BaGetWebApplicationFactory factory, ITestOutputHelper output)
{
_factory = factory.WithOutput(output);
_client = _factory.CreateClient();

_packageStream = TestResources.GetResourceStream(TestResources.Package);
_symbolPackageStream = TestResources.GetResourceStream(TestResources.SymbolPackage);
}

[Fact]
Expand All @@ -33,7 +39,7 @@ public async Task IndexReturnsOk()
[Fact]
public async Task SearchReturnsOk()
{
await _factory.AddPackageAsync(PackageData.Default);
await _factory.AddPackageAsync(_packageStream);

using var response = await _client.GetAsync("v3/search");
var content = await response.Content.ReadAsStreamAsync();
Expand All @@ -48,23 +54,23 @@ public async Task SearchReturnsOk()
""totalHits"": 1,
""data"": [
{
""id"": ""DefaultPackage"",
""id"": ""TestData"",
""version"": ""1.2.3"",
""description"": ""Default package description"",
""description"": ""Test description"",
""authors"": [
""Default package author""
""Test author""
],
""iconUrl"": """",
""licenseUrl"": """",
""projectUrl"": """",
""registration"": ""http://localhost/v3/registration/defaultpackage/index.json"",
""registration"": ""http://localhost/v3/registration/testdata/index.json"",
""summary"": """",
""tags"": [],
""title"": """",
""totalDownloads"": 0,
""versions"": [
{
""@id"": ""http://localhost/v3/registration/defaultpackage/1.2.3.json"",
""@id"": ""http://localhost/v3/registration/testdata/1.2.3.json"",
""version"": ""1.2.3"",
""downloads"": 0
}
Expand Down Expand Up @@ -95,7 +101,7 @@ public async Task SearchReturnsEmpty()
[Fact]
public async Task AutocompleteReturnsOk()
{
await _factory.AddPackageAsync(PackageData.Default);
await _factory.AddPackageAsync(_packageStream);

using var response = await _client.GetAsync("v3/autocomplete");
var content = await response.Content.ReadAsStreamAsync();
Expand All @@ -108,7 +114,7 @@ public async Task AutocompleteReturnsOk()
},
""totalHits"": 1,
""data"": [
""DefaultPackage""
""TestData""
]
}", json);
}
Expand All @@ -133,9 +139,9 @@ public async Task AutocompleteReturnsEmpty()
[Fact]
public async Task AutocompleteVersionsReturnsOk()
{
await _factory.AddPackageAsync(PackageData.Default);
await _factory.AddPackageAsync(_packageStream);

using var response = await _client.GetAsync("v3/autocomplete?id=DefaultPackage");
using var response = await _client.GetAsync("v3/autocomplete?id=TestData");
var content = await response.Content.ReadAsStreamAsync();
var json = PrettifyJson(content);

Expand Down Expand Up @@ -171,9 +177,9 @@ public async Task AutocompleteVersionsReturnsEmpty()
[Fact]
public async Task VersionListReturnsOk()
{
await _factory.AddPackageAsync(PackageData.Default);
await _factory.AddPackageAsync(_packageStream);

var response = await _client.GetAsync("v3/package/DefaultPackage/index.json");
var response = await _client.GetAsync("v3/package/TestData/index.json");
var content = await response.Content.ReadAsStringAsync();

Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Expand All @@ -191,9 +197,9 @@ public async Task VersionListReturnsNotFound()
[Fact]
public async Task PackageDownloadReturnsOk()
{
await _factory.AddPackageAsync(PackageData.Default);
await _factory.AddPackageAsync(_packageStream);

using var response = await _client.GetAsync("v3/package/DefaultPackage/1.2.3/DefaultPackage.1.2.3.nupkg");
using var response = await _client.GetAsync("v3/package/TestData/1.2.3/TestData.1.2.3.nupkg");

Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
Expand All @@ -210,10 +216,10 @@ public async Task PackageDownloadReturnsNotFound()
[Fact]
public async Task NuspecDownloadReturnsOk()
{
await _factory.AddPackageAsync(PackageData.Default);
await _factory.AddPackageAsync(_packageStream);

using var response = await _client.GetAsync(
"v3/package/DefaultPackage/1.2.3/DefaultPackage.1.2.3.nuspec");
"v3/package/TestData/1.2.3/TestData.1.2.3.nuspec");

Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
Expand All @@ -230,15 +236,15 @@ public async Task NuspecDownloadReturnsNotFound()
[Fact]
public async Task PackageMetadataReturnsOk()
{
await _factory.AddPackageAsync(PackageData.Default);
await _factory.AddPackageAsync(_packageStream);

using var response = await _client.GetAsync("v3/registration/DefaultPackage/index.json");
using var response = await _client.GetAsync("v3/registration/TestData/index.json");
var content = await response.Content.ReadAsStreamAsync();
var json = PrettifyJson(content);

Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(@"{
""@id"": ""http://localhost/v3/registration/defaultpackage/index.json"",
""@id"": ""http://localhost/v3/registration/testdata/index.json"",
""@type"": [
""catalog:CatalogRoot"",
""PackageRegistration"",
Expand All @@ -247,14 +253,14 @@ public async Task PackageMetadataReturnsOk()
""count"": 1,
""items"": [
{
""@id"": ""http://localhost/v3/registration/defaultpackage/index.json"",
""@id"": ""http://localhost/v3/registration/testdata/index.json"",
""count"": 1,
""lower"": ""1.2.3"",
""upper"": ""1.2.3"",
""items"": [
{
""@id"": ""http://localhost/v3/registration/defaultpackage/1.2.3.json"",
""packageContent"": ""http://localhost/v3/package/defaultpackage/1.2.3/defaultpackage.1.2.3.nupkg"",
""@id"": ""http://localhost/v3/registration/testdata/1.2.3.json"",
""packageContent"": ""http://localhost/v3/package/testdata/1.2.3/testdata.1.2.3.nupkg"",
""catalogEntry"": {
""downloads"": 0,
""hasReadme"": false,
Expand All @@ -263,17 +269,22 @@ public async Task PackageMetadataReturnsOk()
],
""releaseNotes"": """",
""repositoryUrl"": """",
""id"": ""DefaultPackage"",
""id"": ""TestData"",
""version"": ""1.2.3"",
""authors"": ""Default package author"",
""dependencyGroups"": [],
""description"": ""Default package description"",
""authors"": ""Test author"",
""dependencyGroups"": [
{
""targetFramework"": ""net50"",
""dependencies"": []
}
],
""description"": ""Test description"",
""iconUrl"": """",
""language"": """",
""licenseUrl"": """",
""listed"": true,
""minClientVersion"": """",
""packageContent"": ""http://localhost/v3/package/defaultpackage/1.2.3/defaultpackage.1.2.3.nupkg"",
""packageContent"": ""http://localhost/v3/package/testdata/1.2.3/testdata.1.2.3.nupkg"",
""projectUrl"": """",
""published"": ""2020-01-01T00:00:00Z"",
""requireLicenseAcceptance"": false,
Expand All @@ -300,23 +311,23 @@ public async Task PackageMetadataReturnsNotFound()
[Fact]
public async Task PackageMetadataLeafReturnsOk()
{
await _factory.AddPackageAsync(PackageData.Default);
await _factory.AddPackageAsync(_packageStream);

using var response = await _client.GetAsync("v3/registration/DefaultPackage/1.2.3.json");
using var response = await _client.GetAsync("v3/registration/TestData/1.2.3.json");
var content = await response.Content.ReadAsStreamAsync();
var json = PrettifyJson(content);

Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(@"{
""@id"": ""http://localhost/v3/registration/defaultpackage/1.2.3.json"",
""@id"": ""http://localhost/v3/registration/testdata/1.2.3.json"",
""@type"": [
""Package"",
""http://schema.nuget.org/catalog#Permalink""
],
""listed"": true,
""packageContent"": ""http://localhost/v3/package/defaultpackage/1.2.3/defaultpackage.1.2.3.nupkg"",
""packageContent"": ""http://localhost/v3/package/testdata/1.2.3/testdata.1.2.3.nupkg"",
""published"": ""2020-01-01T00:00:00Z"",
""registration"": ""http://localhost/v3/registration/defaultpackage/index.json""
""registration"": ""http://localhost/v3/registration/testdata/index.json""
}", json);
}

Expand All @@ -331,7 +342,7 @@ public async Task PackageMetadataLeafReturnsNotFound()
[Fact]
public async Task PackageDependentsReturnsOk()
{
using var response = await _client.GetAsync("v3/dependents?packageId=DefaultPackage");
using var response = await _client.GetAsync("v3/dependents?packageId=TestData");

var content = await response.Content.ReadAsStreamAsync();
var json = PrettifyJson(content);
Expand All @@ -351,6 +362,39 @@ public async Task PackageDependentsReturnsBadRequest()
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
}

[Fact]
public async Task SymbolDownloadReturnsOk()
{
await _factory.AddPackageAsync(_packageStream);
await _factory.AddSymbolPackageAsync(_symbolPackageStream);

using var response = await _client.GetAsync(
"api/download/symbols/testdata.pdb/16F71ED8DD574AA2AD4A22D29E9C981Bffffffff/testdata.pdb");

Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

[Fact]
public async Task PrefixedSymbolDownloadReturnsOk()
{
await _factory.AddPackageAsync(_packageStream);
await _factory.AddSymbolPackageAsync(_symbolPackageStream);

using var response = await _client.GetAsync(
"api/download/symbols/testprefix/testdata.pdb/16F71ED8DD574AA2AD4A22D29E9C981Bffffffff/testdata.pdb");

Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

[Fact]
public async Task SymbolDownloadReturnsNotFound()
{
using var response = await _client.GetAsync(
"api/download/symbols/doesnotexist.pdb/16F71ED8DD574AA2AD4A22D29E9C981Bffffffff/doesnotexist.pdb");

Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
}

private string PrettifyJson(Stream jsonStream)
{
using var writer = new StringWriter();
Expand Down
15 changes: 11 additions & 4 deletions tests/BaGet.Tests/BaGet.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
Expand All @@ -20,17 +20,24 @@
</ItemGroup>

<ItemGroup>
<Compile Update="TestData.Designer.cs">
<DependentUpon>TestData.resx</DependentUpon>
<Compile Update="TestData\TestData.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>TestData.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="TestData.resx">
<EmbeddedResource Update="TestData\TestData.resx">
<LastGenOutput>TestData.Designer.cs</LastGenOutput>
<Generator>ResXFileCodeGenerator</Generator>
<CustomToolNamespace>BaGet.Tests</CustomToolNamespace>
</EmbeddedResource>
<EmbeddedResource Include="TestData\TestData.1.2.3.nupkg">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="TestData\TestData.1.2.3.snupkg">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>

Expand Down
Loading

0 comments on commit 4379105

Please sign in to comment.