[gnome-autoar/wip/oholy/various-fixes: 12/23] tests: Add test to check default action for conflicts




commit ad85961cc7cdb8d72d5d5746b1cea642f045769f
Author: Ondrej Holy <oholy redhat com>
Date:   Thu Mar 4 14:33:03 2021 +0100

    tests: Add test to check default action for conflicts
    
    From the code, it was not really clear what is the default action
    for conflicts. Let's add test which verifies that conflicting files
    are skipped by default.

 .../input/arextract.zip                            | Bin 0 -> 190 bytes
 .../reference/arextract.txt                        |   1 +
 tests/test-extract-unit.c                          |  60 +++++++++++++++++++++
 3 files changed, 61 insertions(+)
---
diff --git a/tests/files/extract/test-conflict-skip-file-default/input/arextract.zip 
b/tests/files/extract/test-conflict-skip-file-default/input/arextract.zip
new file mode 100644
index 0000000..8c2eeb6
Binary files /dev/null and b/tests/files/extract/test-conflict-skip-file-default/input/arextract.zip differ
diff --git a/tests/files/extract/test-conflict-skip-file-default/reference/arextract.txt 
b/tests/files/extract/test-conflict-skip-file-default/reference/arextract.txt
new file mode 100644
index 0000000..fe97d17
--- /dev/null
+++ b/tests/files/extract/test-conflict-skip-file-default/reference/arextract.txt
@@ -0,0 +1 @@
+this file should not be overwritten
diff --git a/tests/test-extract-unit.c b/tests/test-extract-unit.c
index c4e50b1..d8e8407 100644
--- a/tests/test-extract-unit.c
+++ b/tests/test-extract-unit.c
@@ -876,6 +876,64 @@ test_conflict_skip_file (void)
   assert_reference_and_output_match (extract_test);
 }
 
+/* Be sure that the default action is skip to prevent data-loss. */
+static void
+test_conflict_skip_file_default (void)
+{
+  /* arextract.zip
+   * └── arextract.txt
+   *
+   * 0 directories, 1 file
+   *
+   *
+   * ref
+   * └── arextract.txt
+   *
+   * 0 directories, 1 file
+   */
+
+  g_autoptr (ExtractTest) extract_test = NULL;
+  g_autoptr (ExtractTestData) data = NULL;
+  g_autoptr (GFile) archive = NULL;
+  g_autoptr (GFile) conflict_file = NULL;
+  g_autoptr (GFile) reference_file = NULL;
+  g_autoptr (AutoarExtractor) extractor = NULL;
+
+  extract_test = extract_test_new ("test-conflict-skip-file-default");
+
+  if (!extract_test) {
+    g_assert_nonnull (extract_test);
+    return;
+  }
+
+  reference_file = g_file_get_child (extract_test->reference,
+                                     "arextract.txt");
+  conflict_file = g_file_get_child (extract_test->output,
+                                    "arextract.txt");
+
+  g_file_copy (reference_file, conflict_file, G_FILE_COPY_NONE,
+               NULL, NULL, NULL, NULL);
+
+  archive = g_file_get_child (extract_test->input, "arextract.zip");
+
+  extractor = autoar_extractor_new (archive, extract_test->output);
+
+  data = extract_test_data_new_for_extract (extractor);
+
+  g_hash_table_insert (data->conflict_files_actions,
+                       g_object_ref (conflict_file),
+                       GUINT_TO_POINTER (AUTOAR_CONFLICT_UNHANDLED));
+
+  autoar_extractor_start (extractor, data->cancellable);
+
+  g_assert_cmpuint (data->number_of_files, ==, 1);
+  g_assert_true (g_hash_table_contains (data->conflict_files,
+                                        conflict_file));
+  g_assert_no_error (data->error);
+  g_assert_true (data->completed_signalled);
+  assert_reference_and_output_match (extract_test);
+}
+
 static void
 test_one_file_error_file_over_directory (void)
 {
@@ -1004,6 +1062,8 @@ setup_test_suite (void)
                    test_conflict_new_destination);
   g_test_add_func ("/autoar-extract/test-conflict-skip-file",
                    test_conflict_skip_file);
+  g_test_add_func ("/autoar-extract/test-conflict-skip-file-default",
+                   test_conflict_skip_file_default);
 
   g_test_add_func ("/autoar-extract/test-one-file-error-file-over-directory",
                    test_one_file_error_file_over_directory);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]