Add unit tests
This commit is contained in:
parent
4b41a1f286
commit
d30b122c6f
|
@ -3,12 +3,15 @@
|
||||||
|
|
||||||
job_build_dotnet:
|
job_build_dotnet:
|
||||||
stage: build
|
stage: build
|
||||||
image: microsoft/dotnet:latest
|
image: archlinux/base:latest
|
||||||
variables:
|
variables:
|
||||||
GIT_SUBMODULE_STRATEGY: recursive
|
GIT_SUBMODULE_STRATEGY: recursive
|
||||||
script:
|
script:
|
||||||
|
- pacman -Syu --needed dotnet-sdk sudo base-devel --noconfirm
|
||||||
|
- 'useradd xunit && echo "xunit ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && mkdir /home/xunit && chown -R xunit:xunit /home/xunit'
|
||||||
|
- sudo -u xunit dotnet test tests/
|
||||||
- dotnet tool install --global dotnet-warp --version 1.0.9
|
- dotnet tool install --global dotnet-warp --version 1.0.9
|
||||||
- PATH="$PATH:/root/.dotnet/tools" dotnet warp -r linux-x64 --verbose
|
- PATH="$PATH:/root/.dotnet/tools" dotnet warp -r linux-x64 --verbose repomgr.csproj
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- repomgr
|
- repomgr
|
|
@ -11,6 +11,7 @@ namespace repomgr.Pages
|
||||||
{
|
{
|
||||||
public void OnGet()
|
public void OnGet()
|
||||||
{
|
{
|
||||||
|
Program.Repo.ReadIndex();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -116,7 +116,6 @@ namespace repomgr
|
||||||
|
|
||||||
private static void PrintHelp()
|
private static void PrintHelp()
|
||||||
{
|
{
|
||||||
//TODO: unit tests...
|
|
||||||
//TODO: add/remove <package> [...]
|
//TODO: add/remove <package> [...]
|
||||||
Console.WriteLine("Usage:");
|
Console.WriteLine("Usage:");
|
||||||
Console.WriteLine("repomgr <data-path> init <repo-path> <reponame>");
|
Console.WriteLine("repomgr <data-path> init <repo-path> <reponame>");
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{
|
{
|
||||||
|
|
||||||
"profiles": {
|
"profiles": {
|
||||||
"repomgr": {
|
"repomgr": {
|
||||||
|
@ -6,7 +6,7 @@
|
||||||
"launchBrowser": false,
|
"launchBrowser": false,
|
||||||
"applicationUrl": "http://localhost:5000",
|
"applicationUrl": "http://localhost:5000",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Production"
|
||||||
},
|
},
|
||||||
"commandLineArgs": "/opt/repomgr daemon"
|
"commandLineArgs": "/opt/repomgr daemon"
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace repomgr
|
||||||
_pkgpath = Path.Combine(_buildpath, "pkg");
|
_pkgpath = Path.Combine(_buildpath, "pkg");
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly string _buildpath;
|
public readonly string _buildpath;
|
||||||
public readonly string _pkgpath;
|
public readonly string _pkgpath;
|
||||||
public Repository _repo;
|
public Repository _repo;
|
||||||
public void Init(string repopath, string reponame)
|
public void Init(string repopath, string reponame)
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
{
|
{
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Debug",
|
"Default": "Warning",
|
||||||
"System": "Information",
|
"System": "Warning",
|
||||||
"Microsoft": "Information"
|
"Microsoft": "Warning"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
{
|
{
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Warning"
|
"Default": "Warning",
|
||||||
|
"System": "Warning",
|
||||||
|
"Microsoft": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*"
|
||||||
|
|
|
@ -18,4 +18,30 @@
|
||||||
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
|
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Remove="tests\**" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Remove="tests\**" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="tests\**" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Remove="tests\**" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<_ContentIncludedByDefault Remove="tests\obj\project.assets.json" />
|
||||||
|
<_ContentIncludedByDefault Remove="tests\obj\project.packagespec.json" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
#
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "repomgr", "repomgr.csproj", "{86A2FA88-E7F3-44AD-9279-CBE5318F792F}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "repomgr", "repomgr.csproj", "{86A2FA88-E7F3-44AD-9279-CBE5318F792F}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tests", "tests\tests.csproj", "{816F57C2-E9F8-4E5F-9B11-9FF383AF61D6}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
@ -12,5 +15,9 @@ Global
|
||||||
{86A2FA88-E7F3-44AD-9279-CBE5318F792F}.Release|Any CPU.Build.0 = Release|Any CPU
|
{86A2FA88-E7F3-44AD-9279-CBE5318F792F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{86A2FA88-E7F3-44AD-9279-CBE5318F792F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{86A2FA88-E7F3-44AD-9279-CBE5318F792F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{86A2FA88-E7F3-44AD-9279-CBE5318F792F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{86A2FA88-E7F3-44AD-9279-CBE5318F792F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{816F57C2-E9F8-4E5F-9B11-9FF383AF61D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{816F57C2-E9F8-4E5F-9B11-9FF383AF61D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{816F57C2-E9F8-4E5F-9B11-9FF383AF61D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{816F57C2-E9F8-4E5F-9B11-9FF383AF61D6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|
|
@ -0,0 +1,104 @@
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using repomgr;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace tests
|
||||||
|
{
|
||||||
|
public class RepomgrTest
|
||||||
|
{
|
||||||
|
private static RepoMgr Init(string folder)
|
||||||
|
{
|
||||||
|
var repo = new RepoMgr(folder);
|
||||||
|
repo.Init(Path.Combine(folder, "repo"), "xunit");
|
||||||
|
return repo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Add(RepoMgr repo, string package)
|
||||||
|
{
|
||||||
|
repo.ReadIndex();
|
||||||
|
repo.Add(package);
|
||||||
|
Assert.Contains(repo._repo.Packages, p => p.Name == package);
|
||||||
|
Assert.Contains(package, File.ReadAllText(Path.Combine(repo._buildpath, "repomgr.index.json")));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Build(RepoMgr repo, string package)
|
||||||
|
{
|
||||||
|
repo.ReadIndex();
|
||||||
|
repo.Build(package);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Remove(RepoMgr repo, string package)
|
||||||
|
{
|
||||||
|
repo.ReadIndex();
|
||||||
|
repo.Remove(package);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetTestFolder()
|
||||||
|
{
|
||||||
|
return "xunit-" + Guid.NewGuid();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestInit()
|
||||||
|
{
|
||||||
|
var folder = GetTestFolder();
|
||||||
|
Init(folder);
|
||||||
|
Assert.True(Directory.Exists(Path.Combine(folder, "repo")));
|
||||||
|
Assert.True(File.Exists(Path.Combine(folder, "repomgr.index.json")));
|
||||||
|
Directory.Delete(folder, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("adduser")]
|
||||||
|
[InlineData("yay")]
|
||||||
|
[InlineData("goimports-git")]
|
||||||
|
public void TestAdd(string package)
|
||||||
|
{
|
||||||
|
var folder = GetTestFolder();
|
||||||
|
var repo = Init(folder);
|
||||||
|
Add(repo, package);
|
||||||
|
Assert.True(File.Exists(Path.Combine(folder, "pkg", package, "PKGBUILD")));
|
||||||
|
var pkg = repo._repo.Packages.FirstOrDefault(p => p.Name.Equals(package));
|
||||||
|
Assert.NotNull(pkg);
|
||||||
|
Assert.Equal("never-updated", pkg.CurrentVersion);
|
||||||
|
Assert.Equal("nA", pkg.RepoVersion);
|
||||||
|
Assert.Empty(pkg.PkgFiles);
|
||||||
|
Assert.True(pkg.LastBuildSucceeded);
|
||||||
|
Directory.Delete(folder, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("adduser")]
|
||||||
|
[InlineData("yay")]
|
||||||
|
[InlineData("goimports-git")]
|
||||||
|
public void TestBuild(string package)
|
||||||
|
{
|
||||||
|
var folder = GetTestFolder();
|
||||||
|
var repo = Init(folder);
|
||||||
|
Add(repo, package);
|
||||||
|
Build(repo, package);
|
||||||
|
Assert.True(Directory.Exists(Path.Combine(folder, "pkg", package)));
|
||||||
|
Assert.True(File.Exists(Path.Combine(folder, "repo", "xunit.db.tar.gz")));
|
||||||
|
Directory.Delete(folder, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("adduser")]
|
||||||
|
[InlineData("yay")]
|
||||||
|
[InlineData("goimports-git")]
|
||||||
|
public void TestRemove(string package)
|
||||||
|
{
|
||||||
|
var folder = GetTestFolder();
|
||||||
|
var repo = Init(folder);
|
||||||
|
Add(repo, package);
|
||||||
|
Build(repo, package);
|
||||||
|
Remove(repo, package);
|
||||||
|
Assert.False(File.Exists(Path.Combine(folder, "pkg", package, "PKGBUILD")));
|
||||||
|
var pkg = repo._repo.Packages.FirstOrDefault(p => p.Name.Equals(package));
|
||||||
|
Assert.Null(pkg);
|
||||||
|
Directory.Delete(folder, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
|
||||||
|
<PackageReference Include="xunit" Version="2.4.1" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\repomgr.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
Reference in New Issue