summaryrefslogtreecommitdiffstats
path: root/tests/stateless-journey.sh
blob: 2557f3ada21b19c5360025fe439b9e03f572ebae (plain)
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
#!/usr/bin/env bash
set -eu

exe=${1:?First argument must be the executable to test}

root="$(cd "${0%/*}" && pwd)"
exe="$root/../$exe"
# shellcheck disable=1090
source "$root/utilities.sh"
snapshot="$root/snapshots"
fixtures="$root/fixtures"

SUCCESSFULLY=0
WITH_FAILURE=1

(with "a sample directory"
  (sandbox
    cp -R "$fixtures/sample-01/" .
    (with "no arguments"
      (with "no given path"
        (with "no subcommand"
          it "produces a human-readable (metric) aggregate of everything within the current directory, with total" && {
            WITH_SNAPSHOT="$snapshot/success-no-arguments" \
            expect_run ${SUCCESSFULLY} "$exe"
          }
        )
        (with "the aggregate sub-command"
          (with "no sorting option"
            it "produces a human-readable (metric) aggregate of everything within the current directory, with total" && {
              WITH_SNAPSHOT="$snapshot/success-no-arguments" \
              expect_run ${SUCCESSFULLY} "$exe" aggregate
            }
          )
          (with "a single file argument"
            it "produces a human-readable (metric) size display of that file" && {
              WITH_SNAPSHOT="$snapshot/success-single-file" \
              expect_run ${SUCCESSFULLY} "$exe" aggregate a
            }
          )
          (with "sorting disabled"
            it "produces a human-readable (metric) aggregate of everything within the current directory, alphabetically sorted, with total" && {
              WITH_SNAPSHOT="$snapshot/success-no-arguments-no-sort" \
              expect_run ${SUCCESSFULLY} "$exe" aggregate --no-sort
            }
          )
        )
      )
      (with "multiple given paths"
        (when "specifying the 'aggregate' subcommand"
          (with "no option to adjust the total"
            it "produces a human-readable aggregate, with total" && {
              WITH_SNAPSHOT="$snapshot/success-no-arguments-multiple-input-paths" \
              expect_run ${SUCCESSFULLY} "$exe" a . . dir ./dir/ ./dir/sub
            }
          )
          (with "the --no-total option set"
            it "produces a human-readable aggregate, without total" && {
              WITH_SNAPSHOT="$snapshot/success-no-arguments-multiple-input-paths-no-total" \
              expect_run ${SUCCESSFULLY} "$exe" aggregate --no-total . . dir ./dir/ ./dir/sub
            }
          )
          (with "the --no-sort option set"
            it "produces a human-readable aggregate, sorted in order specified on the command-line" && {
              WITH_SNAPSHOT="$snapshot/success-no-arguments-multiple-input-paths-no-sort" \
              expect_run ${SUCCESSFULLY} "$exe" aggregate --no-sort . . dir ./dir/ ./dir/sub
            }
          )
          (with "the --stats option set"
            it "produces a human-readable aggregate, and statistics about the iteration in RON" && {
              WITH_SNAPSHOT="$snapshot/success-no-arguments-multiple-input-paths-statistics" \
              expect_run ${SUCCESSFULLY} "$exe" aggregate --stats . . dir ./dir/ ./dir/sub
            }
          )
          (with "a broken link in multiple roots"
            ln -s not-present broken-link
            it "fails but lists valid paths" && {
              WITH_SNAPSHOT="$snapshot/success-no-arguments-multiple-input-paths-one-broken-link" \
              expect_run ${WITH_FAILURE} "$exe" aggregate --stats . dir broken-link ./dir/sub
            }
            rm broken-link
          )
        )
        (when "specifying no subcommand"
          it "produces a human-readable aggregate" && {
            WITH_SNAPSHOT="$snapshot/success-no-arguments-multiple-input-paths" \
            expect_run ${SUCCESSFULLY} "$exe" . . dir ./dir/ ./dir/sub
          }
        )
        (when "specifying no subcommand and some of the directories don't exist"
          it "produces a human-readable aggregate, with the number of errors per root" && {
            WITH_SNAPSHOT="$snapshot/failure-no-arguments-multiple-input-paths-some-not-existing" \
            expect_run ${WITH_FAILURE} "$exe" . . foo bar baz
          }
        )
      )
    )

    (with "the byte format set"
      for format in binary bytes metric gb gib mb mib; do
        (with $format
          it "produces a human-readable aggregate of the current directory, without total" && {
            WITH_SNAPSHOT="$snapshot/success-bytes-$format" \
            expect_run ${SUCCESSFULLY} "$exe" --format $format
          }
        )
      done
    )
  )
  (with "interactive mode"
    it "fails as there is no TTY connected" && {
      WITH_SNAPSHOT="$snapshot/failure-interactive-without-tty" \
      expect_run ${WITH_FAILURE} "$exe" i
    }
  )
)