mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
fetch: remove test with mount and net dependencies
This commit is contained in:
parent
84fac2242c
commit
fc745fb05c
1 changed files with 0 additions and 116 deletions
|
|
@ -2121,119 +2121,3 @@ fn createTestTarball(dir: fs.Dir, tarball_name: []const u8, with_manifest: bool)
|
||||||
try file.writeAll(&[_]u8{0} ** (512 - build_zig_zon.len));
|
try file.writeAll(&[_]u8{0} ** (512 - build_zig_zon.len));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Using test cases from: https://github.com/ianprime0509/pathological-packages
|
|
||||||
// repository. Depends on existence of the FAT32 file system at /tmp/fat32.mnt
|
|
||||||
// (look at the fat32TmpDir function below how to create it). If that folder is
|
|
||||||
// not found test will be skipped. Folder is in FAT32 file system because it is
|
|
||||||
// case insensitive and and does not support symlinks.
|
|
||||||
test "pathological packages" {
|
|
||||||
const gpa = std.testing.allocator;
|
|
||||||
var buf: [128]u8 = undefined;
|
|
||||||
|
|
||||||
const urls: []const []const u8 = &.{
|
|
||||||
"https://github.com/ianprime0509/pathological-packages/archive/{s}.tar.gz",
|
|
||||||
"git+https://github.com/ianprime0509/pathological-packages#{s}",
|
|
||||||
};
|
|
||||||
const branches: []const []const u8 = &.{
|
|
||||||
"excluded-case-collisions",
|
|
||||||
"excluded-symlinks",
|
|
||||||
"included-case-collisions",
|
|
||||||
"included-symlinks",
|
|
||||||
};
|
|
||||||
|
|
||||||
// Expected fetched package files or error message for each combination of url/branch.
|
|
||||||
const expected = [_]struct {
|
|
||||||
files: []const []const u8 = &.{},
|
|
||||||
err_msg: []const u8 = "",
|
|
||||||
}{
|
|
||||||
// tar
|
|
||||||
.{ .files = &.{ "build.zig", "build.zig.zon" } },
|
|
||||||
.{ .files = &.{ "build.zig", "build.zig.zon", "main" } },
|
|
||||||
.{ .err_msg =
|
|
||||||
\\error: unable to unpack tarball
|
|
||||||
\\ note: unable to create file 'main': PathAlreadyExists
|
|
||||||
\\ note: unable to create file 'subdir/main': PathAlreadyExists
|
|
||||||
\\
|
|
||||||
},
|
|
||||||
.{ .err_msg =
|
|
||||||
\\error: unable to unpack tarball
|
|
||||||
\\ note: unable to create symlink from 'link' to 'main': AccessDenied
|
|
||||||
\\ note: unable to create symlink from 'subdir/link' to 'main': AccessDenied
|
|
||||||
\\
|
|
||||||
},
|
|
||||||
// git
|
|
||||||
.{ .files = &.{ "build.zig", "build.zig.zon" } },
|
|
||||||
.{ .files = &.{ "build.zig", "build.zig.zon", "main" } },
|
|
||||||
.{ .err_msg =
|
|
||||||
\\error: unable to unpack packfile
|
|
||||||
\\ note: unable to create file 'main': PathAlreadyExists
|
|
||||||
\\ note: unable to create file 'subdir/main': PathAlreadyExists
|
|
||||||
\\
|
|
||||||
},
|
|
||||||
.{ .err_msg =
|
|
||||||
\\error: unable to unpack packfile
|
|
||||||
\\ note: unable to create symlink from 'link' to 'main': AccessDenied
|
|
||||||
\\ note: unable to create symlink from 'subdir/link' to 'main': AccessDenied
|
|
||||||
\\
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
var expected_no: usize = 0;
|
|
||||||
inline for (urls) |url_fmt| {
|
|
||||||
var tmp = try fat32TmpDir();
|
|
||||||
defer tmp.cleanup();
|
|
||||||
|
|
||||||
for (branches) |branch| {
|
|
||||||
defer expected_no += 1;
|
|
||||||
const url = try std.fmt.bufPrint(&buf, url_fmt, .{branch});
|
|
||||||
// std.debug.print("fetching url: {s}\n", .{url});
|
|
||||||
|
|
||||||
var fb: TestFetchBuilder = undefined;
|
|
||||||
var fetch = try fb.build(gpa, tmp.dir, url);
|
|
||||||
defer fb.deinit();
|
|
||||||
|
|
||||||
const ex = expected[expected_no];
|
|
||||||
if (ex.err_msg.len > 0) {
|
|
||||||
try std.testing.expectError(error.FetchFailed, fetch.run());
|
|
||||||
try fb.expectFetchErrors(0, ex.err_msg);
|
|
||||||
} else {
|
|
||||||
try fetch.run();
|
|
||||||
try fb.expectPackageFiles(ex.files);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Using logic from std.testing.tmpDir() to make temporary directory at specific
|
|
||||||
// location.
|
|
||||||
//
|
|
||||||
// This assumes FAT32 file system in /tmp/fat32.mnt folder,
|
|
||||||
// created with something like this:
|
|
||||||
// $ cd /tmp && fallocate -l 1M fat32.fs && mkfs.fat -F32 fat32.fs && mkdir fat32.mnt && sudo mount -o rw,umask=0000 fat32.fs fat32.mnt
|
|
||||||
//
|
|
||||||
// To remove that folder:
|
|
||||||
// $ cd /tmp && sudo umount fat32.mnt && rm -rf fat32.mnt fat32.fs
|
|
||||||
//
|
|
||||||
pub fn fat32TmpDir() !std.testing.TmpDir {
|
|
||||||
const fat32fs_path = "/tmp/fat32.mnt/";
|
|
||||||
|
|
||||||
const random_bytes_count = 12;
|
|
||||||
var random_bytes: [random_bytes_count]u8 = undefined;
|
|
||||||
std.crypto.random.bytes(&random_bytes);
|
|
||||||
var sub_path: [std.fs.base64_encoder.calcSize(random_bytes_count)]u8 = undefined;
|
|
||||||
_ = std.fs.base64_encoder.encode(&sub_path, &random_bytes);
|
|
||||||
|
|
||||||
const parent_dir = std.fs.openDirAbsolute(fat32fs_path, .{}) catch |err| switch (err) {
|
|
||||||
error.FileNotFound => return error.SkipZigTest,
|
|
||||||
else => return err,
|
|
||||||
};
|
|
||||||
const dir = parent_dir.makeOpenPath(&sub_path, .{}) catch
|
|
||||||
@panic("unable to make tmp dir for testing: unable to make and open the tmp dir");
|
|
||||||
|
|
||||||
return .{
|
|
||||||
.dir = dir,
|
|
||||||
.parent_dir = parent_dir,
|
|
||||||
.sub_path = sub_path,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue