Add InstallScriptBuilder + GET /install.sh + GET /client.tar.gz
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
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<string, string?>
|
||||
{
|
||||
["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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using backend.Install;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace backend.tests;
|
||||
|
||||
public class InstallScriptBuilderTests
|
||||
{
|
||||
[Fact]
|
||||
public void Build_inlines_the_backend_url_into_the_script()
|
||||
{
|
||||
var script = new InstallScriptBuilder().Build("https://example.test");
|
||||
script.Should().Contain("BACKEND_URL=\"https://example.test\"");
|
||||
script.Should().Contain("#!/usr/bin/env bash");
|
||||
script.Should().Contain("$BACKEND_URL/client.tar.gz");
|
||||
script.Should().Contain("client.pair");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user