using System.Net; using FluentAssertions; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Xunit; namespace backend.tests; public class InstallEndpointsTests { [Fact] public async Task Install_sh_returns_shell_script_with_request_host() { using var factory = new ApiFactory(); var client = factory.CreateClient(); var res = await client.GetAsync("/install.sh"); res.StatusCode.Should().Be(HttpStatusCode.OK); res.Content.Headers.ContentType!.MediaType.Should().Be("text/x-shellscript"); var body = await res.Content.ReadAsStringAsync(); body.Should().StartWith("#!/usr/bin/env bash"); body.Should().Contain("BACKEND_URL=\"http://localhost\""); } [Fact] public async Task Client_tarball_returns_octet_stream() { var tmp = Path.Combine(Path.GetTempPath(), $"client-test-{Guid.NewGuid():N}.tar.gz"); File.WriteAllBytes(tmp, new byte[] { 0x1f, 0x8b }); // tiny gzip-ish marker try { using var factory = new ApiFactory(); var client = factory.WithWebHostBuilder(b => { b.ConfigureAppConfiguration((_, cfg) => { cfg.AddInMemoryCollection(new Dictionary { ["Install:ClientTarballPath"] = tmp, }); }); }).CreateClient(); var res = await client.GetAsync("/client.tar.gz"); res.StatusCode.Should().Be(HttpStatusCode.OK); res.Content.Headers.ContentType!.MediaType.Should().Be("application/gzip"); (await res.Content.ReadAsByteArrayAsync()).Length.Should().Be(2); } finally { if (File.Exists(tmp)) File.Delete(tmp); } } }