mirror of
				https://github.com/zoriya/Kyoo.git
				synced 2025-11-03 19:17:16 -05:00 
			
		
		
		
	Handling tests logging and fixing tests CI
This commit is contained in:
		
							parent
							
								
									6f87139815
								
							
						
					
					
						commit
						b5f31eba02
					
				
							
								
								
									
										15
									
								
								.github/workflows/tests.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										15
									
								
								.github/workflows/tests.yml
									
									
									
									
										vendored
									
									
								
							@ -5,6 +5,17 @@ on: [push, pull_request]
 | 
				
			|||||||
jobs:
 | 
					jobs:
 | 
				
			||||||
  build:
 | 
					  build:
 | 
				
			||||||
    runs-on: ubuntu-latest
 | 
					    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:
 | 
					    steps:
 | 
				
			||||||
    - uses: actions/checkout@v2
 | 
					    - uses: actions/checkout@v2
 | 
				
			||||||
    - name: Setup .NET
 | 
					    - name: Setup .NET
 | 
				
			||||||
@ -17,3 +28,7 @@ jobs:
 | 
				
			|||||||
      run: dotnet build --no-restore '-p:SkipWebApp=true;SkipTranscoder=true'
 | 
					      run: dotnet build --no-restore '-p:SkipWebApp=true;SkipTranscoder=true'
 | 
				
			||||||
    - name: Test
 | 
					    - name: Test
 | 
				
			||||||
      run: dotnet test --no-build
 | 
					      run: dotnet test --no-build
 | 
				
			||||||
 | 
					      env:
 | 
				
			||||||
 | 
					        POSTGRES_HOST: postgres
 | 
				
			||||||
 | 
					        POSTGRES_USERNAME: postgres
 | 
				
			||||||
 | 
					        POSTGRES_PASSWORD: postgres
 | 
				
			||||||
 | 
				
			|||||||
@ -29,7 +29,6 @@ namespace Kyoo.Models
 | 
				
			|||||||
				if (value == null)
 | 
									if (value == null)
 | 
				
			||||||
					throw new ArgumentNullException(nameof(value));
 | 
										throw new ArgumentNullException(nameof(value));
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
				Console.WriteLine(value);
 | 
					 | 
				
			||||||
				Match match = Regex.Match(value, @"(?<show>.+)-s(?<season>\d+)e(?<episode>\d+)");
 | 
									Match match = Regex.Match(value, @"(?<show>.+)-s(?<season>\d+)e(?<episode>\d+)");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if (match.Success)
 | 
									if (match.Success)
 | 
				
			||||||
 | 
				
			|||||||
@ -1,3 +0,0 @@
 | 
				
			|||||||
FROM mcr.microsoft.com/dotnet/sdk:5.0
 | 
					 | 
				
			||||||
COPY ../ .
 | 
					 | 
				
			||||||
RUN dotnet tests '-p:SkipWebApp=true;SkipTranscoder=true' 
 | 
					 | 
				
			||||||
@ -14,6 +14,7 @@
 | 
				
			|||||||
			<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
 | 
								<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
 | 
				
			||||||
			<PrivateAssets>all</PrivateAssets>
 | 
								<PrivateAssets>all</PrivateAssets>
 | 
				
			||||||
		</PackageReference>
 | 
							</PackageReference>
 | 
				
			||||||
 | 
							<PackageReference Include="Divergic.Logging.Xunit" Version="3.6.0" />
 | 
				
			||||||
		<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
 | 
							<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
 | 
				
			||||||
		<PackageReference Include="xunit" Version="2.4.1" />
 | 
							<PackageReference Include="xunit" Version="2.4.1" />
 | 
				
			||||||
		<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
 | 
							<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,7 @@
 | 
				
			|||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Threading.Tasks;
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
using Kyoo.Controllers;
 | 
					using Kyoo.Controllers;
 | 
				
			||||||
 | 
					using Xunit.Abstractions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Kyoo.Tests
 | 
					namespace Kyoo.Tests
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -12,11 +13,11 @@ namespace Kyoo.Tests
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		private readonly DatabaseContext _database;
 | 
							private readonly DatabaseContext _database;
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
		public RepositoryActivator(PostgresFixture postgres = null)
 | 
							public RepositoryActivator(ITestOutputHelper output, PostgresFixture postgres = null)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Context = postgres == null 
 | 
								Context = postgres == null 
 | 
				
			||||||
				? new SqLiteTestContext() 
 | 
									? new SqLiteTestContext(output) 
 | 
				
			||||||
				: new PostgresTestContext(postgres);
 | 
									: new PostgresTestContext(postgres, output);
 | 
				
			||||||
			_database = Context.New();
 | 
								_database = Context.New();
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			ProviderRepository provider = new(_database);
 | 
								ProviderRepository provider = new(_database);
 | 
				
			||||||
 | 
				
			|||||||
@ -2,6 +2,7 @@ using System.Threading.Tasks;
 | 
				
			|||||||
using Kyoo.Controllers;
 | 
					using Kyoo.Controllers;
 | 
				
			||||||
using Kyoo.Models;
 | 
					using Kyoo.Models;
 | 
				
			||||||
using Xunit;
 | 
					using Xunit;
 | 
				
			||||||
 | 
					using Xunit.Abstractions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Kyoo.Tests.Library
 | 
					namespace Kyoo.Tests.Library
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -9,8 +10,8 @@ namespace Kyoo.Tests.Library
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		public class EpisodeTests : AEpisodeTests
 | 
							public class EpisodeTests : AEpisodeTests
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			public EpisodeTests()
 | 
								public EpisodeTests(ITestOutputHelper output)
 | 
				
			||||||
				: base(new RepositoryActivator()) { }
 | 
									: base(new RepositoryActivator(output)) { }
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -20,8 +21,8 @@ namespace Kyoo.Tests.Library
 | 
				
			|||||||
		[Collection(nameof(Postgresql))]
 | 
							[Collection(nameof(Postgresql))]
 | 
				
			||||||
		public class EpisodeTests : AEpisodeTests
 | 
							public class EpisodeTests : AEpisodeTests
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			public EpisodeTests(PostgresFixture postgres)
 | 
								public EpisodeTests(PostgresFixture postgres, ITestOutputHelper output)
 | 
				
			||||||
				: base(new RepositoryActivator(postgres)) { }
 | 
									: base(new RepositoryActivator(output, postgres)) { }
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -165,5 +166,7 @@ namespace Kyoo.Tests.Library
 | 
				
			|||||||
			episode = await _repository.Get(1);
 | 
								episode = await _repository.Get(1);
 | 
				
			||||||
			Assert.Equal($"{TestSample.Get<Show>().Slug}-12", episode.Slug);
 | 
								Assert.Equal($"{TestSample.Get<Show>().Slug}-12", episode.Slug);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// TODO add movies tests.
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis;
 | 
				
			|||||||
using System.Threading.Tasks;
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
using Kyoo.Models;
 | 
					using Kyoo.Models;
 | 
				
			||||||
using Xunit;
 | 
					using Xunit;
 | 
				
			||||||
 | 
					using Xunit.Abstractions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Kyoo.Tests.Library
 | 
					namespace Kyoo.Tests.Library
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -10,9 +11,9 @@ namespace Kyoo.Tests.Library
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		private readonly RepositoryActivator _repositories;
 | 
							private readonly RepositoryActivator _repositories;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		public GlobalTests()
 | 
							public GlobalTests(ITestOutputHelper output)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			 _repositories = new RepositoryActivator();
 | 
								 _repositories = new RepositoryActivator(output);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		[Fact]
 | 
							[Fact]
 | 
				
			||||||
 | 
				
			|||||||
@ -2,6 +2,7 @@ using System.Threading.Tasks;
 | 
				
			|||||||
using Kyoo.Controllers;
 | 
					using Kyoo.Controllers;
 | 
				
			||||||
using Kyoo.Models;
 | 
					using Kyoo.Models;
 | 
				
			||||||
using Xunit;
 | 
					using Xunit;
 | 
				
			||||||
 | 
					using Xunit.Abstractions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Kyoo.Tests.Library
 | 
					namespace Kyoo.Tests.Library
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -9,8 +10,8 @@ namespace Kyoo.Tests.Library
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		public class SeasonTests : ASeasonTests
 | 
							public class SeasonTests : ASeasonTests
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			public SeasonTests()
 | 
								public SeasonTests(ITestOutputHelper output)
 | 
				
			||||||
				: base(new RepositoryActivator()) { }
 | 
									: base(new RepositoryActivator(output)) { }
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -20,8 +21,8 @@ namespace Kyoo.Tests.Library
 | 
				
			|||||||
		[Collection(nameof(Postgresql))]
 | 
							[Collection(nameof(Postgresql))]
 | 
				
			||||||
		public class SeasonTests : ASeasonTests
 | 
							public class SeasonTests : ASeasonTests
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			public SeasonTests(PostgresFixture postgres)
 | 
								public SeasonTests(PostgresFixture postgres, ITestOutputHelper output)
 | 
				
			||||||
				: base(new RepositoryActivator(postgres)) { }
 | 
									: base(new RepositoryActivator(output, postgres)) { }
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -6,6 +6,7 @@ using Kyoo.Controllers;
 | 
				
			|||||||
using Kyoo.Models;
 | 
					using Kyoo.Models;
 | 
				
			||||||
using Microsoft.EntityFrameworkCore;
 | 
					using Microsoft.EntityFrameworkCore;
 | 
				
			||||||
using Xunit;
 | 
					using Xunit;
 | 
				
			||||||
 | 
					using Xunit.Abstractions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Kyoo.Tests.Library
 | 
					namespace Kyoo.Tests.Library
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -13,8 +14,8 @@ namespace Kyoo.Tests.Library
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		public class ShowTests : AShowTests
 | 
							public class ShowTests : AShowTests
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			public ShowTests()
 | 
								public ShowTests(ITestOutputHelper output)
 | 
				
			||||||
				: base(new RepositoryActivator()) { }
 | 
									: base(new RepositoryActivator(output)) { }
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -23,8 +24,8 @@ namespace Kyoo.Tests.Library
 | 
				
			|||||||
		[Collection(nameof(Postgresql))]
 | 
							[Collection(nameof(Postgresql))]
 | 
				
			||||||
		public class ShowTests : AShowTests
 | 
							public class ShowTests : AShowTests
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			public ShowTests(PostgresFixture postgres)
 | 
								public ShowTests(PostgresFixture postgres, ITestOutputHelper output)
 | 
				
			||||||
				: base(new RepositoryActivator(postgres)) { }
 | 
									: base(new RepositoryActivator(output, postgres)) { }
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore;
 | 
				
			|||||||
using Microsoft.Extensions.Logging;
 | 
					using Microsoft.Extensions.Logging;
 | 
				
			||||||
using Npgsql;
 | 
					using Npgsql;
 | 
				
			||||||
using Xunit;
 | 
					using Xunit;
 | 
				
			||||||
 | 
					using Xunit.Abstractions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Kyoo.Tests
 | 
					namespace Kyoo.Tests
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -22,14 +23,18 @@ namespace Kyoo.Tests
 | 
				
			|||||||
		/// </summary>
 | 
							/// </summary>
 | 
				
			||||||
		private readonly DbContextOptions<DatabaseContext> _context;
 | 
							private readonly DbContextOptions<DatabaseContext> _context;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public SqLiteTestContext()
 | 
							public SqLiteTestContext(ITestOutputHelper output)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			_connection = new SqliteConnection("DataSource=:memory:");
 | 
								_connection = new SqliteConnection("DataSource=:memory:");
 | 
				
			||||||
			_connection.Open();
 | 
								_connection.Open();
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			_context = new DbContextOptionsBuilder<DatabaseContext>()
 | 
								_context = new DbContextOptionsBuilder<DatabaseContext>()
 | 
				
			||||||
				.UseSqlite(_connection)
 | 
									.UseSqlite(_connection)
 | 
				
			||||||
				.UseLoggerFactory(LoggerFactory.Create(x => x.AddConsole()))
 | 
									.UseLoggerFactory(LoggerFactory.Create(x =>
 | 
				
			||||||
 | 
									{
 | 
				
			||||||
 | 
										x.ClearProviders();
 | 
				
			||||||
 | 
										x.AddXunit(output);
 | 
				
			||||||
 | 
									}))
 | 
				
			||||||
				.EnableSensitiveDataLogging()
 | 
									.EnableSensitiveDataLogging()
 | 
				
			||||||
				.EnableDetailedErrors()
 | 
									.EnableDetailedErrors()
 | 
				
			||||||
				.Options;
 | 
									.Options;
 | 
				
			||||||
@ -101,7 +106,7 @@ namespace Kyoo.Tests
 | 
				
			|||||||
		private readonly NpgsqlConnection _connection;
 | 
							private readonly NpgsqlConnection _connection;
 | 
				
			||||||
		private readonly DbContextOptions<DatabaseContext> _context;
 | 
							private readonly DbContextOptions<DatabaseContext> _context;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		public PostgresTestContext(PostgresFixture template)
 | 
							public PostgresTestContext(PostgresFixture template, ITestOutputHelper output)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			string id = Guid.NewGuid().ToString().Replace('-', '_');
 | 
								string id = Guid.NewGuid().ToString().Replace('-', '_');
 | 
				
			||||||
			string database = $"kyoo_test_{id}";
 | 
								string database = $"kyoo_test_{id}";
 | 
				
			||||||
@ -118,7 +123,11 @@ namespace Kyoo.Tests
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			_context = new DbContextOptionsBuilder<DatabaseContext>()
 | 
								_context = new DbContextOptionsBuilder<DatabaseContext>()
 | 
				
			||||||
				.UseNpgsql(_connection)
 | 
									.UseNpgsql(_connection)
 | 
				
			||||||
				.UseLoggerFactory(LoggerFactory.Create(x => x.AddConsole()))
 | 
									.UseLoggerFactory(LoggerFactory.Create(x =>
 | 
				
			||||||
 | 
									{
 | 
				
			||||||
 | 
										x.ClearProviders();
 | 
				
			||||||
 | 
										x.AddXunit(output);
 | 
				
			||||||
 | 
									}))
 | 
				
			||||||
				.EnableSensitiveDataLogging()
 | 
									.EnableSensitiveDataLogging()
 | 
				
			||||||
				.EnableDetailedErrors()
 | 
									.EnableDetailedErrors()
 | 
				
			||||||
				.Options;
 | 
									.Options;
 | 
				
			||||||
@ -126,10 +135,10 @@ namespace Kyoo.Tests
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		public static string GetConnectionString(string database)
 | 
							public static string GetConnectionString(string database)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			string server = Environment.GetEnvironmentVariable("SERVER") ?? "127.0.0.1";
 | 
								string server = Environment.GetEnvironmentVariable("POSTGRES_HOST") ?? "127.0.0.1";
 | 
				
			||||||
			string port = Environment.GetEnvironmentVariable("PORT") ?? "5432";
 | 
								string port = Environment.GetEnvironmentVariable("POSTGRES_PORT") ?? "5432";
 | 
				
			||||||
			string username = Environment.GetEnvironmentVariable("USERNAME") ?? "kyoo";
 | 
								string username = Environment.GetEnvironmentVariable("POSTGRES_USERNAME") ?? "kyoo";
 | 
				
			||||||
			string password = Environment.GetEnvironmentVariable("PASSWORD") ?? "kyooPassword";
 | 
								string password = Environment.GetEnvironmentVariable("POSTGRES_PASSWORD") ?? "kyooPassword";
 | 
				
			||||||
			return $"Server={server};Port={port};Database={database};User ID={username};Password={password};Include Error Detail=true";
 | 
								return $"Server={server};Port={port};Database={database};User ID={username};Password={password};Include Error Detail=true";
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user