aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEvgenii Kliuchnikov <eustas@google.com>2024-01-11 02:03:59 -0800
committerCopybara-Service <copybara-worker@google.com>2024-01-11 02:04:37 -0800
commit033940f97cfa5e708c46961de7e85d5e4976ee40 (patch)
tree014a59b581b8109495a5da5eaeafa9fbcd7e22c9 /tests
parent2ad58d8603294f5ee33d23bb725e0e6a17c1de50 (diff)
downloadbrotli-033940f97cfa5e708c46961de7e85d5e4976ee40.zip
brotli-033940f97cfa5e708c46961de7e85d5e4976ee40.tar.gz
brotli-033940f97cfa5e708c46961de7e85d5e4976ee40.tar.bz2
add comment (fingerprint) CLI feature
PiperOrigin-RevId: 597489910
Diffstat (limited to 'tests')
-rwxr-xr-xtests/cli_test.sh84
1 files changed, 84 insertions, 0 deletions
diff --git a/tests/cli_test.sh b/tests/cli_test.sh
new file mode 100755
index 0000000..b6c563e
--- /dev/null
+++ b/tests/cli_test.sh
@@ -0,0 +1,84 @@
+#!/bin/bash
+
+source gbash.sh || exit
+source module gbash_unit.sh
+
+readonly MKTEMP='/bin/mktemp'
+readonly RM='/bin/rm'
+
+function test::brotli_cli::setup() {
+ TEMP_DIR=$(${MKTEMP} -d)
+ LOG INFO ${TEMP_DIR}
+ BROTLI_PKG="${RUNFILES}/google3/third_party/brotli"
+ BROTLI="${BROTLI_PKG}/tools/brotli"
+ cd ${TEMP_DIR}
+ echo "Kot lomom kolol slona" > text.orig
+}
+
+function test::brotli_cli::teardown() {
+ unset BROTLI
+ unset BROTLI_PKG
+ ${RM} -rf ${TEMP_DIR}
+ unset TEMP_DIR
+}
+
+function test::brotli_cli::roundtrip() {
+ ${BROTLI} -Zfk text.orig -o text.br
+ ${BROTLI} -d text.br -o text.unbr
+ EXPECT_FILE_CONTENT_EQ text.orig text.unbr
+}
+
+# 'SGVsbG8=' == $(echo -n "Hello" | base64)
+
+function test::brotli_cli::comment_ok() {
+ ${BROTLI} -Zfk -C SGVsbG8= text.orig -o text.br
+ ${BROTLI} -d --comment=SGVsbG8= text.br -o text.unbr
+ EXPECT_FILE_CONTENT_EQ text.orig text.unbr
+}
+
+function test::brotli_cli::comment_no_padding() {
+ ${BROTLI} -Zfk -C SGVsbG8 text.orig -o text.br
+ ${BROTLI} -d --comment=SGVsbG8= text.br -o text.unbr
+ EXPECT_FILE_CONTENT_EQ text.orig text.unbr
+}
+
+function test::brotli_cli::comment_extra_padding() {
+ ${BROTLI} -Zfk -C SGVsbG8 text.orig -o text.br
+ ${BROTLI} -d --comment=SGVsbG8== text.br -o text.unbr
+ EXPECT_FILE_CONTENT_EQ text.orig text.unbr
+}
+
+function test::brotli_cli::comment_ignored() {
+ ${BROTLI} -Zfk -C SGVsbG8= text.orig -o text.br
+ EXPECT_SUCCEED "${BROTLI} -d text.br -o text.unbr"
+}
+
+function test::brotli_cli::comment_mismatch_content() {
+ ${BROTLI} -Zfk --comment=SGVsbG8= text.orig -o text.br
+ EXPECT_FAIL "${BROTLI} -dC SGVsbG7= text.br -o text.unbr"
+ EXPECT_FAIL "${BROTLI} -tC SGVsbG7= text.br"
+}
+
+function test::brotli_cli::comment_mismatch_length() {
+ ${BROTLI} -Zfk --comment=SGVsbG8= text.orig -o text.br
+ EXPECT_FAIL "${BROTLI} -tC SGVsbA== text.br"
+}
+
+function test::brotli_cli::comment_too_much_padding() {
+ EXPECT_FAIL "${BROTLI} -Zfk -C SGVsbG8=== text.orig -o text.br"
+}
+
+function test::brotli_cli::comment_padding_in_the_middle() {
+ EXPECT_FAIL "${BROTLI} -Zfk -C SGVsbG=8 text.orig -o text.br"
+}
+
+function test::brotli_cli::comment_ignore_tab_cr_lf_sp() {
+ COMMENT=$'S\tG\rV\ns bG8='
+ EXPECT_SUCCEED "${BROTLI} -Zfk -C \"${COMMENT}\" text.orig -o text.br"
+}
+
+function test::brotli_cli::comment_invalid_chars() {
+ EXPECT_FAIL "${BROTLI} -Zfk -C S.GVsbG8= text.orig -o text.br"
+}
+
+gbash::unit::main "$@"