Browse Source

Add unit tests

master
Laura 3 years ago
committed by Laura Hausmann
parent
commit
d30b122c6f
No known key found for this signature in database GPG Key ID: 85E256B4B0D8AE9B
  1. 7
      .gitlab-ci.yml
  2. 1
      Pages/Index.cshtml.cs
  3. 1
      Program.cs
  4. 4
      Properties/launchSettings.json
  5. 2
      RepoMgr.cs
  6. 6
      appsettings.Development.json
  7. 4
      appsettings.json
  8. 26
      repomgr.csproj
  9. 7
      repomgr.sln
  10. 104
      tests/repomgr_test.cs
  11. 19
      tests/tests.csproj

7
.gitlab-ci.yml

@ -3,12 +3,15 @@
job_build_dotnet:
stage: build
image: microsoft/dotnet:latest
image: archlinux/base:latest
variables:
GIT_SUBMODULE_STRATEGY: recursive
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
- 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:
paths:
- repomgr

1
Pages/Index.cshtml.cs

@ -11,6 +11,7 @@ namespace repomgr.Pages
{
public void OnGet()
{
Program.Repo.ReadIndex();
}
}
}

1
Program.cs

@ -116,7 +116,6 @@ namespace repomgr
private static void PrintHelp()
{
//TODO: unit tests...
//TODO: add/remove <package> [...]
Console.WriteLine("Usage:");
Console.WriteLine("repomgr <data-path> init <repo-path> <reponame>");

4
Properties/launchSettings.json

@ -1,4 +1,4 @@
{
{
"profiles": {
"repomgr": {
@ -6,7 +6,7 @@
"launchBrowser": false,
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
"ASPNETCORE_ENVIRONMENT": "Production"
},
"commandLineArgs": "/opt/repomgr daemon"
}

2
RepoMgr.cs

@ -16,7 +16,7 @@ namespace repomgr
_pkgpath = Path.Combine(_buildpath, "pkg");
}
private readonly string _buildpath;
public readonly string _buildpath;
public readonly string _pkgpath;
public Repository _repo;
public void Init(string repopath, string reponame)

6
appsettings.Development.json

@ -1,9 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
"Default": "Warning",
"System": "Warning",
"Microsoft": "Warning"
}
}
}

4
appsettings.json

@ -1,7 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Warning"
"Default": "Warning",
"System": "Warning",
"Microsoft": "Warning"
}
},
"AllowedHosts": "*"

26
repomgr.csproj

@ -18,4 +18,30 @@
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
</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>

7
repomgr.sln

@ -1,7 +1,10 @@

Microsoft Visual Studio Solution File, Format Version 12.00
#
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "repomgr", "repomgr.csproj", "{86A2FA88-E7F3-44AD-9279-CBE5318F792F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tests", "tests\tests.csproj", "{816F57C2-E9F8-4E5F-9B11-9FF383AF61D6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
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}.Debug|Any CPU.ActiveCfg = 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
EndGlobal

104
tests/repomgr_test.cs

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

19
tests/tests.csproj

@ -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…
Cancel
Save