diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 67ab67dd..d9a5b261 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,6 +5,17 @@ on: [push, pull_request] jobs: build: runs-on: ubuntu-latest + container: mcr.microsoft.com/dotnet/sdk:5.0 + services: + postgres: + image: postgres + env: + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 steps: - uses: actions/checkout@v2 - name: Setup .NET @@ -17,3 +28,7 @@ jobs: run: dotnet build --no-restore '-p:SkipWebApp=true;SkipTranscoder=true' - name: Test run: dotnet test --no-build + env: + POSTGRES_HOST: postgres + POSTGRES_USERNAME: postgres + POSTGRES_PASSWORD: postgres diff --git a/Kyoo.Common/Models/Resources/Episode.cs b/Kyoo.Common/Models/Resources/Episode.cs index 594763be..cdb7fb8f 100644 --- a/Kyoo.Common/Models/Resources/Episode.cs +++ b/Kyoo.Common/Models/Resources/Episode.cs @@ -29,7 +29,6 @@ namespace Kyoo.Models if (value == null) throw new ArgumentNullException(nameof(value)); - Console.WriteLine(value); Match match = Regex.Match(value, @"(?.+)-s(?\d+)e(?\d+)"); if (match.Success) diff --git a/Kyoo.Tests/Dockerfile b/Kyoo.Tests/Dockerfile deleted file mode 100644 index 423bfe57..00000000 --- a/Kyoo.Tests/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM mcr.microsoft.com/dotnet/sdk:5.0 -COPY ../ . -RUN dotnet tests '-p:SkipWebApp=true;SkipTranscoder=true' diff --git a/Kyoo.Tests/Kyoo.Tests.csproj b/Kyoo.Tests/Kyoo.Tests.csproj index 265ccb98..93873bc7 100644 --- a/Kyoo.Tests/Kyoo.Tests.csproj +++ b/Kyoo.Tests/Kyoo.Tests.csproj @@ -14,6 +14,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all + diff --git a/Kyoo.Tests/Library/RepositoryActivator.cs b/Kyoo.Tests/Library/RepositoryActivator.cs index 9f7f78fb..e7249e3a 100644 --- a/Kyoo.Tests/Library/RepositoryActivator.cs +++ b/Kyoo.Tests/Library/RepositoryActivator.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using Kyoo.Controllers; +using Xunit.Abstractions; namespace Kyoo.Tests { @@ -12,11 +13,11 @@ namespace Kyoo.Tests private readonly DatabaseContext _database; - public RepositoryActivator(PostgresFixture postgres = null) + public RepositoryActivator(ITestOutputHelper output, PostgresFixture postgres = null) { Context = postgres == null - ? new SqLiteTestContext() - : new PostgresTestContext(postgres); + ? new SqLiteTestContext(output) + : new PostgresTestContext(postgres, output); _database = Context.New(); ProviderRepository provider = new(_database); diff --git a/Kyoo.Tests/Library/SpecificTests/EpisodeTest.cs b/Kyoo.Tests/Library/SpecificTests/EpisodeTest.cs index 1433860e..7a617fdb 100644 --- a/Kyoo.Tests/Library/SpecificTests/EpisodeTest.cs +++ b/Kyoo.Tests/Library/SpecificTests/EpisodeTest.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Kyoo.Controllers; using Kyoo.Models; using Xunit; +using Xunit.Abstractions; namespace Kyoo.Tests.Library { @@ -9,8 +10,8 @@ namespace Kyoo.Tests.Library { public class EpisodeTests : AEpisodeTests { - public EpisodeTests() - : base(new RepositoryActivator()) { } + public EpisodeTests(ITestOutputHelper output) + : base(new RepositoryActivator(output)) { } } } @@ -20,8 +21,8 @@ namespace Kyoo.Tests.Library [Collection(nameof(Postgresql))] public class EpisodeTests : AEpisodeTests { - public EpisodeTests(PostgresFixture postgres) - : base(new RepositoryActivator(postgres)) { } + public EpisodeTests(PostgresFixture postgres, ITestOutputHelper output) + : base(new RepositoryActivator(output, postgres)) { } } } @@ -165,5 +166,7 @@ namespace Kyoo.Tests.Library episode = await _repository.Get(1); Assert.Equal($"{TestSample.Get().Slug}-12", episode.Slug); } + + // TODO add movies tests. } } \ No newline at end of file diff --git a/Kyoo.Tests/Library/SpecificTests/SanityTests.cs b/Kyoo.Tests/Library/SpecificTests/SanityTests.cs index 098c4677..78637d35 100644 --- a/Kyoo.Tests/Library/SpecificTests/SanityTests.cs +++ b/Kyoo.Tests/Library/SpecificTests/SanityTests.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; using Kyoo.Models; using Xunit; +using Xunit.Abstractions; namespace Kyoo.Tests.Library { @@ -10,9 +11,9 @@ namespace Kyoo.Tests.Library { private readonly RepositoryActivator _repositories; - public GlobalTests() + public GlobalTests(ITestOutputHelper output) { - _repositories = new RepositoryActivator(); + _repositories = new RepositoryActivator(output); } [Fact] diff --git a/Kyoo.Tests/Library/SpecificTests/SeasonTests.cs b/Kyoo.Tests/Library/SpecificTests/SeasonTests.cs index 0c912d07..39be8b82 100644 --- a/Kyoo.Tests/Library/SpecificTests/SeasonTests.cs +++ b/Kyoo.Tests/Library/SpecificTests/SeasonTests.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Kyoo.Controllers; using Kyoo.Models; using Xunit; +using Xunit.Abstractions; namespace Kyoo.Tests.Library { @@ -9,8 +10,8 @@ namespace Kyoo.Tests.Library { public class SeasonTests : ASeasonTests { - public SeasonTests() - : base(new RepositoryActivator()) { } + public SeasonTests(ITestOutputHelper output) + : base(new RepositoryActivator(output)) { } } } @@ -20,8 +21,8 @@ namespace Kyoo.Tests.Library [Collection(nameof(Postgresql))] public class SeasonTests : ASeasonTests { - public SeasonTests(PostgresFixture postgres) - : base(new RepositoryActivator(postgres)) { } + public SeasonTests(PostgresFixture postgres, ITestOutputHelper output) + : base(new RepositoryActivator(output, postgres)) { } } } diff --git a/Kyoo.Tests/Library/SpecificTests/ShowTests.cs b/Kyoo.Tests/Library/SpecificTests/ShowTests.cs index facb8e81..8940f0c3 100644 --- a/Kyoo.Tests/Library/SpecificTests/ShowTests.cs +++ b/Kyoo.Tests/Library/SpecificTests/ShowTests.cs @@ -6,6 +6,7 @@ using Kyoo.Controllers; using Kyoo.Models; using Microsoft.EntityFrameworkCore; using Xunit; +using Xunit.Abstractions; namespace Kyoo.Tests.Library { @@ -13,8 +14,8 @@ namespace Kyoo.Tests.Library { public class ShowTests : AShowTests { - public ShowTests() - : base(new RepositoryActivator()) { } + public ShowTests(ITestOutputHelper output) + : base(new RepositoryActivator(output)) { } } } @@ -23,8 +24,8 @@ namespace Kyoo.Tests.Library [Collection(nameof(Postgresql))] public class ShowTests : AShowTests { - public ShowTests(PostgresFixture postgres) - : base(new RepositoryActivator(postgres)) { } + public ShowTests(PostgresFixture postgres, ITestOutputHelper output) + : base(new RepositoryActivator(output, postgres)) { } } } diff --git a/Kyoo.Tests/Library/TestContext.cs b/Kyoo.Tests/Library/TestContext.cs index 68f27012..fa2935b8 100644 --- a/Kyoo.Tests/Library/TestContext.cs +++ b/Kyoo.Tests/Library/TestContext.cs @@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Npgsql; using Xunit; +using Xunit.Abstractions; namespace Kyoo.Tests { @@ -22,14 +23,18 @@ namespace Kyoo.Tests /// private readonly DbContextOptions _context; - public SqLiteTestContext() + public SqLiteTestContext(ITestOutputHelper output) { _connection = new SqliteConnection("DataSource=:memory:"); _connection.Open(); _context = new DbContextOptionsBuilder() .UseSqlite(_connection) - .UseLoggerFactory(LoggerFactory.Create(x => x.AddConsole())) + .UseLoggerFactory(LoggerFactory.Create(x => + { + x.ClearProviders(); + x.AddXunit(output); + })) .EnableSensitiveDataLogging() .EnableDetailedErrors() .Options; @@ -101,7 +106,7 @@ namespace Kyoo.Tests private readonly NpgsqlConnection _connection; private readonly DbContextOptions _context; - public PostgresTestContext(PostgresFixture template) + public PostgresTestContext(PostgresFixture template, ITestOutputHelper output) { string id = Guid.NewGuid().ToString().Replace('-', '_'); string database = $"kyoo_test_{id}"; @@ -118,7 +123,11 @@ namespace Kyoo.Tests _context = new DbContextOptionsBuilder() .UseNpgsql(_connection) - .UseLoggerFactory(LoggerFactory.Create(x => x.AddConsole())) + .UseLoggerFactory(LoggerFactory.Create(x => + { + x.ClearProviders(); + x.AddXunit(output); + })) .EnableSensitiveDataLogging() .EnableDetailedErrors() .Options; @@ -126,10 +135,10 @@ namespace Kyoo.Tests public static string GetConnectionString(string database) { - string server = Environment.GetEnvironmentVariable("SERVER") ?? "127.0.0.1"; - string port = Environment.GetEnvironmentVariable("PORT") ?? "5432"; - string username = Environment.GetEnvironmentVariable("USERNAME") ?? "kyoo"; - string password = Environment.GetEnvironmentVariable("PASSWORD") ?? "kyooPassword"; + string server = Environment.GetEnvironmentVariable("POSTGRES_HOST") ?? "127.0.0.1"; + string port = Environment.GetEnvironmentVariable("POSTGRES_PORT") ?? "5432"; + string username = Environment.GetEnvironmentVariable("POSTGRES_USERNAME") ?? "kyoo"; + string password = Environment.GetEnvironmentVariable("POSTGRES_PASSWORD") ?? "kyooPassword"; return $"Server={server};Port={port};Database={database};User ID={username};Password={password};Include Error Detail=true"; }