fetch: add executable bit test

This commit is contained in:
Igor Anić 2024-04-07 01:21:10 +02:00
parent 8c58b8fe01
commit f8dd2a1064
2 changed files with 52 additions and 0 deletions

View File

@ -2010,6 +2010,58 @@ test "tarball without root folder" {
try fb.expectPackageFiles(expected_files);
}
test "set executable bit based on file content" {
if (!std.fs.has_executable_bit) return error.SkipZigTest;
const gpa = std.testing.allocator;
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
const tarball_name = "executables.tar.gz";
try saveEmbedFile(tarball_name, tmp.dir);
const tarball_path = try std.fmt.allocPrint(gpa, "zig-cache/tmp/{s}/{s}", .{ tmp.sub_path, tarball_name });
defer gpa.free(tarball_path);
// $ tar -tvf executables.tar.gz
// drwxrwxr-x 0 executables/
// -rwxrwxr-x 170 executables/hello
// lrwxrwxrwx 0 executables/hello_ln -> hello
// -rw-rw-r-- 0 executables/file1
// -rw-rw-r-- 17 executables/script_with_shebang_without_exec_bit
// -rwxrwxr-x 7 executables/script_without_shebang
// -rwxrwxr-x 17 executables/script
var fb: TestFetchBuilder = undefined;
var fetch = try fb.build(gpa, tmp.dir, tarball_path);
defer fb.deinit();
try fetch.run();
try std.testing.expectEqualStrings(
"1220fecb4c06a9da8673c87fe8810e15785f1699212f01728eadce094d21effeeef3",
&Manifest.hexDigest(fetch.actual_hash),
);
var out = try fb.packageDir();
defer out.close();
const S = std.posix.S;
// expect executable bit not set
try std.testing.expect((try out.statFile("file1")).mode & S.IXUSR == 0);
try std.testing.expect((try out.statFile("script_without_shebang")).mode & S.IXUSR == 0);
// expect executable bit set
try std.testing.expect((try out.statFile("hello")).mode & S.IXUSR != 0);
try std.testing.expect((try out.statFile("script")).mode & S.IXUSR != 0);
try std.testing.expect((try out.statFile("script_with_shebang_without_exec_bit")).mode & S.IXUSR != 0);
try std.testing.expect((try out.statFile("hello_ln")).mode & S.IXUSR != 0);
//
// $ ls -al zig-cache/tmp/OCz9ovUcstDjTC_U/zig-global-cache/p/1220fecb4c06a9da8673c87fe8810e15785f1699212f01728eadce094d21effeeef3
// -rw-rw-r-- 1 0 Apr file1
// -rwxrwxr-x 1 170 Apr hello
// lrwxrwxrwx 1 5 Apr hello_ln -> hello
// -rwxrwxr-x 1 17 Apr script
// -rw-rw-r-- 1 7 Apr script_without_shebang
// -rwxrwxr-x 1 17 Apr script_with_shebang_without_exec_bit
}
fn saveEmbedFile(comptime tarball_name: []const u8, dir: fs.Dir) !void {
//const tarball_name = "duplicate_paths_excluded.tar.gz";
const tarball_content = @embedFile("Fetch/testdata/" ++ tarball_name);

Binary file not shown.