Files
Febe/tests/Febe.Tests/Export/MountInfoTests.cs
T
Alby96andClaude Opus 5.5 36ad5c6f9d
verifica / controlli (push) Canceled after 0s
verifica / prove (push) Canceled after 0s
verifica / installatore (push) Canceled after 0s
verifica / immagine (push) Canceled after 0s
E2: correzioni della revisione delle copie esterne
- Nome libero scelto prima di scrivere, libero sul disco e nel database;
  una riga orfana sul nome diventa «Tolto» (guardando il suo percorso,
  anche se differisce solo per le maiuscole): prima la copia finiva
  «Non riuscito» con il file già scritto, o toglieva la copia buona.
- «Controlla le copie» rilegge la radice e riguarda i file mancanti;
  con il disco staccato si ferma e mette in pausa senza segnare nulla.
- Su Linux lo spostamento sul nome finale non sostituisce mai un file
  (renameat2 RENAME_NOREPLACE, poi link e unlink).
- Le copie in coda di un lavoro interrotto diventano «Interrotta» e si
  riprendono; il permesso dei lavori lunghi si tiene già nel piano.
- «Superato» con il file di nuovo in libreria: filtro, piano e «Copia di
  nuovo» d'accordo; l'adozione ravviva la riga invece di fallire.
- «Una copia sola» con una regola sola in filtro, piano, visualizzatore
  e copiatore (solo copie di un altro account in cartelle in uso).
- Controllo della cartella per identità vera (percorso finale, realpath,
  dispositivo di mountinfo): riconosce collegamenti e bind mount di una
  sottocartella della libreria.
- Sfoglia delle cartelle con tempi massimi; «Nessuna cartella» solo se
  non ce n'è; «In copia…» nel visualizzatore; numero e fuoco stabili in
  «Copia di nuovo anche…»; una sola lettura per volta nella Dashboard.
- Prove dell'interfaccia indipendenti dall'ora e dal file scelto; prove
  nuove in ExportReviewTests, ExportFolderCheckTests, ExportRootTests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 17:02:06 +01:00

93 lines
4.4 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, "8:49"), proc.FindContaining("/esporta/usb/a"));
Assert.AreEqual("8:17", MountInfoTable.FindContaining(mounts, "/esporta")!.Device); // the device, for the identity test
Assert.HasCount(4, proc.All());
}
}