Files
Febe/tests/Febe.Tests/Export/MountInfoTests.cs
T
Alby96andClaude Opus 5.5 736d241a38 E2: prove del motore, dell'archivio e del servizio delle copie
Le prove della tappa E2 (WP5a) coprono il montaggio di /esporta, la
radice, il controllo delle cartelle, le destinazioni, i percorsi, la
copia, gli stati «Tolto» e «Superato», lo stesso post in due account,
il lavoro in sottofondo (interrompi, riprendi, annulla, riavvio, porta
condivisa con importazione e ricostruzione, sessione del motore,
interruttore dell'account, Docker senza montaggio) e il filtro «Copie».
Si appoggiano a un banco comune con falsi per disco, sessione, montaggi
e file system, senza permessi dei file, così girano anche da root.

Le prove hanno trovato due difetti, corretti:
- MarkCopiesRemovedAsync riusava il comando in cache del primo blocco
  di 900 id: «Controlla le copie» falliva con più di 900 file mancanti
  in una pagina.
- ReplacedStatesSql senza statistiche leggeva tutte le copie tolte o
  superate della destinazione: «+state» la tiene sul suo indice.

Il controllo delle cartelle accetta una scrittura di prova sostituibile,
per provare il guasto della sonda senza permessi.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 13:28:20 +01:00

92 lines
4.2 KiB
C#

using Febe.Core.Export;
using Febe.Core.Library;
namespace Febe.Tests.Export;
/// <summary>
/// <c>/proc/self/mountinfo</c> as the export reads it (spec §4.10 «Docker e Windows», decision D14 of tappa E2). The
/// content is always given by the test: nothing reads the mounts of the machine that runs the tests.
/// </summary>
[TestClass]
public sealed class MountInfoTests
{
[TestMethod]
public void ParsesMountPointRootTypeAndOptionsWithOptionalFields()
{
const string content = """
22 1 8:1 / / rw,relatime shared:1 - ext4 /dev/sda1 rw,errors=remount-ro
40 22 8:17 /backup/foto /esporta/usb rw,noatime master:3 propagate_from:2 - vfat /dev/sdb1 rw,fmask=0022
41 22 0:50 / /esporta/nas ro,relatime - cifs //nas/copie rw,vers=3.0
""";
var mounts = MountInfoTable.Parse(content);
Assert.HasCount(3, mounts);
var usb = mounts[1];
Assert.AreEqual((40, 22), (usb.Id, usb.ParentId));
Assert.AreEqual("/backup/foto", usb.Root);
Assert.AreEqual("/esporta/usb", usb.MountPoint);
CollectionAssert.AreEqual(new[] { "rw", "noatime" }, usb.Options.ToArray());
Assert.AreEqual("vfat", usb.FileSystemType); // after the optional fields and their separator «-»
Assert.AreEqual("/dev/sdb1", usb.Source);
Assert.IsFalse(usb.ReadOnly);
Assert.AreEqual("ext4", mounts[0].FileSystemType);
Assert.AreEqual("//nas/copie", mounts[2].Source);
Assert.IsTrue(mounts[2].ReadOnly); // the per-mount options say ro, the super options say rw
}
[TestMethod]
public void UnescapesSpacesAndTabsInPaths()
{
var mounts = MountInfoTable.Parse(@"50 22 8:33 /foto\040di\011Marta /esporta/disco\040usb rw - ext4 /dev/sdc\0401 rw");
Assert.AreEqual("/foto di\tMarta", mounts.Single().Root);
Assert.AreEqual("/esporta/disco usb", mounts[0].MountPoint);
Assert.AreEqual("/dev/sdc 1", mounts[0].Source);
Assert.AreEqual("/esporta/disco usb", MountInfoTable.FindContaining(mounts, "/esporta/disco usb/Febe")!.MountPoint);
}
[TestMethod]
public void SkipsMalformedLines()
{
const string content = """
riga senza senso
22 1 8:1 / / rw - ext4 /dev/sda1 rw
x 1 8:1 / /a rw - ext4 /dev/sda2 rw
23 y 8:1 / /b rw - ext4 /dev/sda3 rw
24 1 8:1 / /c rw shared:1 ext4 /dev/sda4 rw extra
25 1 8:1 / /d rw -
26 1 8:1 relativa /e rw - ext4 /dev/sda6 rw
27 1 8:1 / relativo rw - ext4 /dev/sda7 rw
28 1 8:1 / /f rw
""";
var mounts = MountInfoTable.Parse(content.Replace("\n", "\r\n", StringComparison.Ordinal));
Assert.AreEqual("/", mounts.Single().MountPoint);
Assert.IsEmpty(MountInfoTable.Parse(string.Empty));
Assert.IsEmpty(new ProcMountInfo(() => null).All());
Assert.IsNull(new ProcMountInfo(() => throw new IOException("letto male")).FindContaining("/esporta/usb"));
}
[TestMethod]
public void FindsTheLongestMountContainingAPath()
{
const string content = """
22 1 8:1 / / rw - ext4 /dev/sda1 rw
40 22 8:17 / /esporta rw - ext4 /dev/sdb1 rw
41 40 8:33 / /esporta/usb rw - vfat /dev/sdc1 rw
42 40 8:49 / /esporta/usb rw - exfat /dev/sdd1 rw
""";
var mounts = MountInfoTable.Parse(content);
Assert.AreEqual("exfat", MountInfoTable.FindContaining(mounts, "/esporta/usb/Febe/marta.demo")!.FileSystemType); // the last mount over a point wins
Assert.AreEqual("exfat", MountInfoTable.FindContaining(mounts, "/esporta/usb/")!.FileSystemType);
Assert.AreEqual("/esporta", MountInfoTable.FindContaining(mounts, "/esporta/usbx")!.MountPoint); // not a prefix of a segment
Assert.AreEqual("/esporta", MountInfoTable.FindContaining(mounts, "/esporta")!.MountPoint);
Assert.AreEqual("/", MountInfoTable.FindContaining(mounts, "/dati")!.MountPoint);
Assert.IsNull(MountInfoTable.FindContaining([], "/esporta"));
var proc = new ProcMountInfo(() => content);
Assert.AreEqual(new ExportMount("/esporta/usb", "/", "exfat", false), proc.FindContaining("/esporta/usb/a"));
Assert.HasCount(4, proc.All());
}
}