~dricottone/my-utils

ref: 1f09f68b7797319eddf938fd66de11d685e3c421 my-utils/archives/test_mktar_tarcat.sh -rwxr-xr-x 3.7 KiB
1f09f68bDominic Ricottone Changes to rebom and library 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/sh
# tests mktar and tarcat

# move to temp directory
cd test

test_compression() {

  #set internal variables based on selected compression
  case "$1" in
    NONE)
      arg_compression="none"
      fn_compressed="archive.tar"
      fn_compressed_gpg="archive.tar.gpg"
      fn_compressed_age="archive.tar.age"
      ;;
    GZIP)
      arg_compression="gzip"
      fn_compressed="archive.tar.gz"
      fn_compressed_gpg="archive.tar.gz.gpg"
      fn_compressed_age="archive.tar.gz.age"
      ;;
    XZ)
      arg_compression="xz"
      fn_compressed="archive.tar.xz"
      fn_compressed_gpg="archive.tar.xz.gpg"
      fn_compressed_age="archive.tar.xz.age"
      ;;
    ZSTD)
      arg_compression="zstd"
      fn_compressed="archive.tar.zst"
      fn_compressed_gpg="archive.tar.zst.gpg"
      fn_compressed_age="archive.tar.zst.age"
      ;;
    BZIP2)
      arg_compression="bzip2"
      fn_compressed="archive.tar.bz2"
      fn_compressed_gpg="archive.tar.bz2.gpg"
      fn_compressed_age="archive.tar.bz2.age"
      ;;
    *)
      printf "Failure in compression tests: not a valid scheme: '%s'\n" "$1"
      exit 1
      ;;
  esac

  #
  # mktar tests
  #

  test="implicit compression with short name flag using"
  ../mktar -n "$fn_compressed" compression_target.txt
  ../tarcat "$fn_compressed" > compression_result.txt
  if ! cmp compression_result.txt compression_target.txt >/dev/null 2>&1; then
    printf "Failure in compression tests: %s '%s'\n" "$test" "$1"
    exit 1
  fi
  rm -f compression_result.txt "$fn_compressed"

  test="implicit compression with long name flag using"
  ../mktar --name "$fn_compressed" compression_target.txt
  ../tarcat "$fn_compressed" > compression_result.txt
  if ! cmp compression_result.txt compression_target.txt >/dev/null 2>&1; then
    printf "Failure in compression tests: %s '%s'\n" "$test" "$1"
    exit 1
  fi
  rm -f compression_result.txt "$fn_compressed"

  #
  # mktar-batch tests
  #

  test="compression using"
  ../mktar-batch --compress="$arg_compression" --name "$fn_compressed" compression_target.txt
  ../tarcat "$fn_compressed" > compression_result.txt
  if ! cmp compression_result.txt compression_target.txt >/dev/null 2>&1; then
    printf "Failure in compression tests: %s '%s'\n" "$test" "$1"
    exit 1
  fi
  rm -f compression_result.txt "$fn_compressed"

  test="compression with misordered positional arguments using"
  ../mktar-batch compression_target.txt --compress="$arg_compression" --name "$fn_compressed"
  ../tarcat "$fn_compressed" > compression_result.txt
  if ! cmp compression_result.txt compression_target.txt >/dev/null 2>&1; then
    printf "Failure in compression tests: %s '%s'\n" "$test" "$1"
    exit 1
  fi
  rm -f compression_result.txt "$fn_compressed"

  test="compression using gpg and"
  ../mktar-batch --compress="$arg_compression" --encrypt="gpg" --passphrase test123 --name "$fn_compressed_gpg" compression_target.txt
  ../tarcat --passphrase test123 "$fn_compressed_gpg" > compression_result.txt
  if ! cmp compression_result.txt compression_target.txt >/dev/null 2>&1; then
    printf "Failure in compression tests: %s '%s'\n" "$test" "$1"
    exit 1
  fi
  rm -f compression_result.txt "$fn_compressed_gpg"

  test="compression using age and"
  ../mktar-batch --compress="$arg_compression" --encrypt="age" --passphrase test123 --name "$fn_compressed_age" compression_target.txt
  ../tarcat --passphrase test123 "$fn_compressed_age" > compression_result.txt
  if ! cmp compression_result.txt compression_target.txt >/dev/null 2>&1; then
    printf "Failure in compression tests: %s '%s'\n" "$test" "$1"
    exit 1
  fi
  rm -f compression_result.txt "$fn_compressed_age"
}

test_compression NONE
test_compression GZIP
test_compression XZ
test_compression ZSTD
test_compression BZIP2