Skip to content

Commit

Permalink
Don't gen string that ends with hyphen (#1899)
Browse files Browse the repository at this point in the history
For CLI tests

fixes #1864
  • Loading branch information
tjtelan committed Nov 16, 2021
1 parent 493b88c commit aa4e061
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tests/cli/test_helper/fluvio_dev.bash
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ function debug_msg() {

# Note: We only generate strings w/ *lowercase* alphanum or '-'
# for topic naming compatibility
# We don't check for minimum length, but $DEFAULT_LEN >= 3
# or `shuf` will err when requested $BODY length less than zero
function random_string() {
DEFAULT_LEN=7
STRING_LEN=${1:-$DEFAULT_LEN}

# Ensure we don't end up with a string that starts with '-'
# Ensure we don't end up with a string that starts or ends with '-'
# https://github.com/infinyon/fluvio/issues/1864

STRING1=$(shuf -zer -n1 {a..z} {0..9})
STRING2=$(shuf -zer -n"$(($STRING_LEN-1))" {a..z} {0..9} "-")
HEAD=$(shuf -zer -n1 {a..z} {0..9})
BODY=$(shuf -zer -n"$(($STRING_LEN-2))" {a..z} {0..9} "-")
FOOT=$(shuf -zer -n1 {a..z} {0..9})

RANDOM_STRING=$STRING1$STRING2
RANDOM_STRING=$HEAD$BODY$FOOT

if [[ -n $DEBUG ]]; then
echo "# DEBUG: Random str (len: $STRING_LEN): $RANDOM_STRING" >&3
Expand Down

0 comments on commit aa4e061

Please sign in to comment.