aboutsummaryrefslogtreecommitdiff
path: root/tests/test_utils.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2026-06-23 11:00:55 -0400
committerGitHub <noreply@github.com>2026-06-23 11:00:55 -0400
commit5e0b3fbefebaeff1fa5bfb338c760b9b9e270f02 (patch)
tree14b22fc5b82a9db87720c820c54422c9b9c47a1c /tests/test_utils.c
parent70c1ba3962166853fc7a1e4f2bb1d637104312b1 (diff)
parent0f6a1c982c2f417e9f0de968bbb7ce58299a8e8d (diff)
downloadstasis-1.8.0.tar.gz
Merge pull request #147 from jhunkeler/conda-updates1.8.0
Support modern versions of conda/mamba
Diffstat (limited to 'tests/test_utils.c')
-rw-r--r--tests/test_utils.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/test_utils.c b/tests/test_utils.c
index fc53f53..e1689dd 100644
--- a/tests/test_utils.c
+++ b/tests/test_utils.c
@@ -456,6 +456,52 @@ void test_pushd_popd_suggested_workflow() {
}
}
+void test_is_file_compressed() {
+ const char *filenames[] = {
+ "zstd", "bz2", "gz", "xz", "zip",
+ };
+ char datadir[PATH_MAX] = {0};
+ snprintf(datadir, sizeof(datadir), "%s/compression", TEST_DATA_DIR);
+
+ char inputfile[PATH_MAX] = {0};
+ for (size_t i = 0; i < sizeof(filenames) / sizeof(*filenames); i++) {
+ snprintf(inputfile, sizeof(inputfile), "%s/%s", datadir, filenames[i]);
+ const int compressed = is_file_compressed(inputfile);
+ SYSDEBUG("[%zu] is %s compressed? => %s", i, inputfile, compressed ? "Yes" : "No");
+ STASIS_ASSERT(compressed == true, "compression should have been detected");
+ }
+
+ snprintf(inputfile, sizeof(inputfile), "%s/none", datadir);
+ STASIS_ASSERT(is_file_compressed(inputfile) == false, "'none' file should not be detected as compressed data");
+
+ for (size_t i = 0; i < sizeof(filenames) / sizeof(*filenames); i++) {
+ char bytes[128];
+ if (get_random_bytes(bytes, sizeof(bytes))) {
+ SYSERROR("get_random_bytes failed: %s, %s", bytes, strerror(errno));
+ STASIS_ASSERT_FATAL(false, "get_random_bytes failed");
+ return;
+ }
+
+ FILE *fp = fopen(filenames[i], "wb");
+ if (!fp) {
+ SYSERROR("fopen failed: %s, %s", filenames[i], strerror(errno));
+ STASIS_ASSERT_FATAL(false, "fopen failed");
+ return;
+ }
+
+ bytes[0] = 'J';
+ const size_t bytes_written = fwrite(bytes, 1, sizeof(bytes), fp);
+ if (bytes_written != sizeof(bytes)) {
+ SYSERROR("fwrite failed: %s, %s", bytes, strerror(errno));
+ STASIS_ASSERT_FATAL(false, "fwrite failed");
+ return;
+ }
+ fclose(fp);
+
+ STASIS_ASSERT(is_file_compressed(filenames[i]) == false, "random data should not be detected as compressed");
+ }
+}
+
int main(int argc, char *argv[]) {
STASIS_TEST_BEGIN_MAIN();
@@ -479,6 +525,7 @@ int main(int argc, char *argv[]) {
test_dirstack,
test_pushd_popd,
test_pushd_popd_suggested_workflow,
+ test_is_file_compressed,
};
const char *ws = "workspace";
getcwd(cwd_start, sizeof(cwd_start) - 1);