Tre prove scrivevano i percorsi attesi alla Linux («/tmp/febe-profilo», «/importa», la radice seguita da «/») e fallivano su Windows, dove il prodotto dà giustamente il percorso completo sull'unità corrente o il percorso scritto con «/». Ora l'atteso si calcola come lo calcola il sistema: su Linux il testo resta identico a prima, su Windows le prove passano dove gira Febe per Windows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
4.3 KiB
C#
83 lines
4.3 KiB
C#
using Febe.Core.Import;
|
|
using Febe.Core.Library;
|
|
using Febe.Tests.Import.Support;
|
|
using Febe.Tests.Support;
|
|
|
|
namespace Febe.Tests.Import;
|
|
|
|
[TestClass]
|
|
public sealed class ImportSourcesTests
|
|
{
|
|
[TestMethod]
|
|
public void InDockerOnlyTheImportVolumeIsOffered()
|
|
{
|
|
using var temp = new TempFolder("sorgenti");
|
|
var root = temp.Combine("importa");
|
|
Directory.CreateDirectory(Path.Combine(root, "4K Stogram", "marta.demo"));
|
|
Directory.CreateDirectory(Path.Combine(root, "Telefono"));
|
|
Directory.CreateDirectory(temp.Combine("fuori"));
|
|
var sources = new ImportSources(ImportSourceOptions.Docker(root), probe: new FixedAccessProbe(false));
|
|
|
|
var choices = sources.Browse();
|
|
CollectionAssert.AreEqual(new[] { "4K Stogram", "Telefono" }, choices.Select(c => c.Name).ToArray());
|
|
Assert.IsTrue(choices[0].HasSubfolders);
|
|
Assert.AreEqual("4K Stogram/marta.demo", sources.Browse("4K Stogram").Single().Path);
|
|
|
|
var info = sources.Inspect("4K Stogram");
|
|
Assert.AreEqual(Path.Combine(root, "4K Stogram"), info.FullPath);
|
|
Assert.IsTrue(info.ReadOnly, "Il volume /importa è in sola lettura.");
|
|
Assert.IsFalse(info.CanMove);
|
|
// Shown as in the container, with «/»: the same text as the root on Linux; on Windows the separators change too.
|
|
Assert.AreEqual(LibraryLayout.ToStored(root) + "/4K Stogram", info.DisplayPath);
|
|
|
|
var outside = Assert.ThrowsExactly<ImportSourceException>(() => sources.Inspect(temp.Combine("fuori")));
|
|
StringAssert.Contains(outside.Message, "sottocartella");
|
|
Assert.ThrowsExactly<ImportSourceException>(() => sources.Inspect("../fuori"));
|
|
Assert.ThrowsExactly<ImportSourceException>(() => sources.Inspect("non-esiste"));
|
|
Assert.ThrowsExactly<ImportSourceException>(() => sources.Browse(".."));
|
|
Assert.ThrowsExactly<ImportSourceException>(() => sources.Inspect(" "));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TheLibraryAndTheDataFolderAreNotSources()
|
|
{
|
|
using var temp = new TempFolder("sorgenti");
|
|
var library = temp.Combine("libreria");
|
|
var data = temp.Combine("dati");
|
|
Directory.CreateDirectory(Path.Combine(library, "marta.demo"));
|
|
File.WriteAllText(Path.Combine(library, "marta.demo", AccountJournal.FileName), string.Empty);
|
|
Directory.CreateDirectory(Path.Combine(library, "vecchie foto"));
|
|
Directory.CreateDirectory(data);
|
|
var sources = new ImportSources(ImportSourceOptions.AnyFolder, library, data, new FixedAccessProbe(false));
|
|
|
|
Assert.ThrowsExactly<ImportSourceException>(() => sources.Inspect(temp.Path), "Contiene la libreria.");
|
|
Assert.ThrowsExactly<ImportSourceException>(() => sources.Inspect(library));
|
|
Assert.ThrowsExactly<ImportSourceException>(() => sources.Inspect(Path.Combine(library, "marta.demo")), "Cartella di un account.");
|
|
Assert.ThrowsExactly<ImportSourceException>(() => sources.Inspect(data));
|
|
Assert.AreEqual("vecchie foto", sources.Inspect(Path.Combine(library, "vecchie foto")).Name, "Una cartella della libreria senza _febe.jsonl si può importare.");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void AReadOnlyMountIsSeenInTheMountTable()
|
|
{
|
|
const string mounts = """
|
|
overlay / overlay rw,relatime,lowerdir=/x 0 0
|
|
/dev/sdb1 /importa ext4 ro,relatime 0 0
|
|
/dev/sdc1 /importa/scrivibile ext4 rw,relatime 0 0
|
|
/dev/sdd1 /mnt/foto\040di\040casa xfs ro 0 0
|
|
""";
|
|
Assert.IsTrue(SystemSourceAccessProbe.MountIsReadOnly(mounts, "/importa/4K Stogram"));
|
|
Assert.IsTrue(SystemSourceAccessProbe.MountIsReadOnly(mounts, "/importa"));
|
|
Assert.IsFalse(SystemSourceAccessProbe.MountIsReadOnly(mounts, "/importa/scrivibile/a"), "Vince il punto di montaggio più lungo.");
|
|
Assert.IsFalse(SystemSourceAccessProbe.MountIsReadOnly(mounts, "/home/alberto/Immagini"));
|
|
Assert.IsFalse(SystemSourceAccessProbe.MountIsReadOnly(mounts, "/importazione"), "/importa non contiene /importazione.");
|
|
Assert.IsTrue(SystemSourceAccessProbe.MountIsReadOnly(mounts, "/mnt/foto di casa/2019"));
|
|
|
|
if (OperatingSystem.IsLinux())
|
|
{
|
|
using var temp = new TempFolder("sorgenti");
|
|
Assert.IsFalse(new SystemSourceAccessProbe().IsReadOnly(temp.Path), "Una cartella temporanea si può scrivere.");
|
|
}
|
|
}
|
|
}
|