Skip to content

Commit

Permalink
(#508) Add unit tests for NuGet source parsing
Browse files Browse the repository at this point in the history
This adds tests to ensure that NuGet is able to parse various types of NuGet
sources correctly. This includes http, https, and local paths, where local
paths include absolute, different types of relative paths, and UNC.
  • Loading branch information
TheCakeIsNaOH committed Jan 6, 2023
1 parent 69cc81f commit 0598097
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions src/chocolatey.tests/infrastructure.app/nuget/NugetCommonSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public override void Context()
configuration = new ChocolateyConfiguration();
nugetLogger.ResetCalls();
packageDownloader.ResetCalls();
filesystem.ResetCalls();

filesystem.Setup(f => f.get_full_path(It.IsAny<string>())).Returns((string a) =>
{
return "C:\\packages\\" + a;
});
}

public override void Because()
Expand All @@ -62,6 +68,99 @@ public void should_create_repository_when_source_is_null()

packageRepositories.Count().ShouldEqual(0);
}

[Fact]
public void should_parse_http_source()
{
Context();
var source = "http://nexus.example.com:8081/repository/choco";
configuration.Sources = source;
configuration.CacheLocation = "C:\\temp";

because();

packageRepositories.First().PackageSource.TrySourceAsUri.ShouldNotBeNull();
packageRepositories.First().PackageSource.SourceUri.to_string().ShouldEqual(source);
packageRepositories.First().PackageSource.IsHttp.ShouldBeTrue();
}

[Fact]
public void should_parse_https_source()
{
Context();
var source = "https://nexus.example.com/repository/choco";
configuration.Sources = source;
configuration.CacheLocation = "C:\\temp";

because();

packageRepositories.First().PackageSource.TrySourceAsUri.ShouldNotBeNull();
packageRepositories.First().PackageSource.SourceUri.to_string().ShouldEqual(source);
packageRepositories.First().PackageSource.IsHttps.ShouldBeTrue();
}

[Fact]
public void should_parse_absolute_path_source()
{
Context();
var source = "C:\\packages";
configuration.Sources = source;

because();

packageRepositories.First().PackageSource.TrySourceAsUri.ShouldNotBeNull();
packageRepositories.First().PackageSource.SourceUri.to_string()
.ShouldEqual(("file:///" + source).Replace("\\","/"));
packageRepositories.First().PackageSource.IsLocal.ShouldBeTrue();
}

[Fact]
public void should_parse_relative_path_source()
{
Context();
var source = "choco";
var fullsource = "C:\\packages\\choco";
configuration.Sources = source;

because();

packageRepositories.First().PackageSource.TrySourceAsUri.ShouldNotBeNull();
packageRepositories.First().PackageSource.SourceUri.to_string()
.ShouldEqual(("file:///" + fullsource).Replace("\\", "/"));
packageRepositories.First().PackageSource.IsLocal.ShouldBeTrue();
}

[Fact]
public void should_parse_dot_relative_path_source()
{
Context();
var source = ".";
var fullsource = "C:\\packages";
configuration.Sources = source;

because();

packageRepositories.First().PackageSource.TrySourceAsUri.ShouldNotBeNull();
packageRepositories.First().PackageSource.SourceUri.to_string()
.ShouldEqual(("file:///" + fullsource + "/").Replace("\\", "/"));
packageRepositories.First().PackageSource.IsLocal.ShouldBeTrue();
}

[Fact]
public void should_parse_unc_source()
{
Context();
var source = "\\\\samba-server\\choco-share";
configuration.Sources = source;

because();

packageRepositories.First().PackageSource.TrySourceAsUri.ShouldNotBeNull();
packageRepositories.First().PackageSource.SourceUri.to_string()
.ShouldEqual(("file:" + source).Replace("\\", "/"));
packageRepositories.First().PackageSource.IsLocal.ShouldBeTrue();
packageRepositories.First().PackageSource.SourceUri.IsUnc.ShouldBeTrue();
}
}
}
}

0 comments on commit 0598097

Please sign in to comment.