|
1 | 1 | #!/usr/bin/env bash |
2 | | - |
3 | | -set -e |
| 2 | +set -euo pipefail |
4 | 3 |
|
5 | 4 | root=`dirname "$0"` |
6 | | -root=`realpath "$root/.."` |
7 | | -. "$root/test/local.sh" |
8 | | - |
9 | | -function begin { |
10 | | - test_dir="${1:?}" |
11 | | - echo; echo `basename "$test_dir"` |
12 | | - pushd "$test_dir" > /dev/null |
13 | | -} |
14 | | - |
15 | | -function end { |
16 | | - bundles_dir=${1:-"./dist"} |
17 | | - rm -r "$bundles_dir" |
18 | | - popd > /dev/null |
19 | | -} |
20 | | - |
21 | | -function assert_identical { |
22 | | - actual="${1:?}" |
23 | | - expected="${2:?}" |
24 | | - # NB: `git diff` provides colorization (dependent on configuration) |
25 | | - git diff --no-index "$expected" "$actual" || \ |
26 | | - fail "files \`$actual\` and \`$expected\` are not identical" |
27 | | -} |
28 | | - |
29 | | -function assert_identical_json { |
30 | | - actual="${1:?}" |
31 | | - expected="${2:?}" |
32 | | - json-diff "$expected" "$actual" || \ |
33 | | - fail "files \`$actual\` and \`$expected\` are not identical" |
34 | | -} |
| 5 | +root=`realpath "$root"` |
35 | 6 |
|
36 | | -function assert_manifest { |
37 | | - asset_path="${1:?}" |
38 | | - uri="${2:?}" |
39 | | - manifest_path=${3:-"./dist/manifest.json"} |
| 7 | +. "$root/../node_modules/faucet-pipeline/test/cli_harness.sh" |
40 | 8 |
|
41 | | - json="\"$asset_path\":\"$uri\"" |
42 | | - grep -q "$json" "$manifest_path" || \ |
43 | | - fail "manifest \`$manifest_path\` does not contain \`$json\`" |
44 | | -} |
45 | | - |
46 | | -function assert_missing { |
47 | | - filepath="${1:?}" |
48 | | - if [ -f "$filepath" ]; then |
49 | | - fail "file \`$filepath\` should not exist" |
50 | | - else |
51 | | - true |
52 | | - fi |
53 | | -} |
54 | | - |
55 | | -function fail { |
56 | | - msg="${1:?}" |
57 | | - echo; echo "FAILURE: $msg" |
58 | | - false |
59 | | -} |
60 | | - |
61 | | -cd "$root/test" |
62 | | - |
63 | | -begin "./test_basic" |
| 9 | +begin "$root/test_basic" |
64 | 10 | faucet |
65 | 11 | assert_identical "./dist/test.txt" "./src/test.txt" |
66 | 12 | assert_identical "./dist/inner/test2.txt" "./src/inner/test2.txt" |
67 | 13 | end |
68 | 14 |
|
69 | | -begin "./test_fingerprint" |
| 15 | +begin "$root/test_fingerprint" |
70 | 16 | faucet --fingerprint |
71 | 17 | assert_identical "./dist/test-e59ff97941044f85df5297e1c302d260.txt" "./src/test.txt" |
72 | | - assert_identical_json "./dist/manifest.json" "./expected.json" |
| 18 | + assert_json "./dist/manifest.json" "./expected.json" |
73 | 19 | end |
74 | 20 |
|
75 | | -begin "./test_manifest_base_uri" |
| 21 | +begin "$root/test_manifest_base_uri" |
76 | 22 | faucet --fingerprint |
77 | | - assert_identical_json "./dist/manifest.json" "./expected.json" |
| 23 | + assert_json "./dist/manifest.json" "./expected.json" |
78 | 24 | end |
79 | 25 |
|
80 | | -begin "./test_single" |
| 26 | +begin "$root/test_single" |
81 | 27 | faucet |
82 | 28 | assert_identical "./dist/dist.txt" "./src.txt" |
83 | 29 | end |
84 | 30 |
|
85 | | -begin "./test_key_config" |
| 31 | +begin "$root/test_key_config" |
86 | 32 | faucet --fingerprint |
87 | | - assert_identical_json "./dist/manifest.json" "./expected.json" |
| 33 | + assert_json "./dist/manifest.json" "./expected.json" |
88 | 34 | end |
| 35 | + |
| 36 | +echo; echo "SUCCESS: all tests passed" |
0 commit comments