Skip to content

Commit

Permalink
fix: profile export, full config, add cli test (#4179)
Browse files Browse the repository at this point in the history
* fix: profile export, full config, add cli test

* chore: disable export profile for stable

* chore: fix bats test

also, upgrade to bats 1.11.0

* chore: bats, fix bad file descriptor error messages
  • Loading branch information
digikata committed Sep 12, 2024
1 parent 49447a5 commit 65c5b92
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ env:
CARGO_TERM_COLOR: always
VERBOSE: ${{ github.events.input.verbose }}
K3D_VERSION: v5.4.9
BATS_VERSION: 1.9.0
BATS_VERSION: 1.11.0
MINIKUBE_VERSION: v1.30.1
K8_VERSION: v1.26.3
TLS_ARGS: --tls --domain fluvio.local --server-key ./tls/certs/server.key --server-cert ./tls/certs/server.crt --ca-cert ./tls/certs/ca.crt --client-cert ./tls/certs/client-root.crt --client-key ./tls/certs/client-root.key
Expand Down Expand Up @@ -1410,7 +1410,7 @@ jobs:

- name: Start edge cluster remote 2
timeout-minutes: 10
run: |
run: |
fluvio profile add local2 ${REMOTE_2_SC_PUB_ADDR} local
fluvio cluster start --skip-profile-creation --skip-checks --spu 0 --sc-pub-addr ${REMOTE_2_SC_PUB_ADDR} --sc-priv-addr ${REMOTE_2_SC_PRIV_ADDR} --data-dir ${REMOTE_2_BASE_DIR}
fluvio cluster spu register --id ${REMOTE_2_SPU_ID} -p ${REMOTE_2_SPU_PUB_ADDR} -v ${REMOTE_2_SPU_PRIV_ADDR}
Expand Down
16 changes: 15 additions & 1 deletion crates/fluvio-cli/src/profile/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ impl ExportOpt {
return Err(CliError::ClusterNotFoundInConfig(cluster_name.to_owned()).into());
};

Ok(out.render_serde(&profile_export, output_format.into())?)
if output_format == OutputType::toml {
use fluvio::config::{Config, Profile};

// add cluster to a new config export
let profile_name = cluster_name.clone();
let mut config_export = Config::new();

config_export.add_cluster(profile_export.to_owned(), cluster_name.clone());
let profile = Profile::new(cluster_name.clone());
config_export.add_profile(profile, profile_name.clone());
config_export.set_current_profile(&profile_name);
Ok(out.render_serde(&config_export, output_format.into())?)
} else {
Ok(out.render_serde(&profile_export, output_format.into())?)
}
}
}
2 changes: 1 addition & 1 deletion makefiles/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ cli-partition-test-multiple-partitions:
bats ./tests/cli/partition_test/multiple_partitions.bats

cli-fluvio-smoke:
bats $(shell ls -1 ./tests/cli/fluvio_smoke_tests/*.bats | sort -R)
bats -x $(shell ls -1 ./tests/cli/fluvio_smoke_tests/*.bats | sort -R)
bats ./tests/cli/fluvio_smoke_tests/non-concurrent/local-resume.bats
bats ./tests/cli/fluvio_smoke_tests/non-concurrent/cluster-delete.bats

Expand Down
33 changes: 30 additions & 3 deletions tests/cli/fluvio_smoke_tests/profile-export.bats
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,40 @@ load "$TEST_HELPER_DIR"/fluvio_dev.bash
load "$TEST_HELPER_DIR"/bats-support/load.bash
load "$TEST_HELPER_DIR"/bats-assert/load.bash

# Create topic
@test "Export current profile" {

@test "Export current profile json" {
debug_msg "Export current profile"
run timeout 15s "$FLUVIO_BIN" profile export
run timeout 15s "$FLUVIO_BIN" profile export -O json
debug_msg "status: $status"
debug_msg "output: ${lines[@]}"
assert_success
assert_output --partial 'endpoint'
assert_output --partial 'tls'
}

@test "Export current profile for use with FLV_PROFILE_PATH" {
# the stable version of cli 0.11.11 or older does not support this type of profile export
if [ "$FLUVIO_CLI_RELEASE_CHANNEL" == "stable" ]; then
skip "don't run on fluvio cli stable version"
fi
if [ "$FLUVIO_CLUSTER_RELEASE_CHANNEL" == "stable" ]; then
skip "don't run on cluster stable version"
fi

run timeout 15s "$FLUVIO_BIN" profile export
debug_msg "status: $status"
debug_msg "output: ${lines[@]}"
assert_success

# rerun the export cmd because bats eats the output
export TMPFILE=$(mktemp -t fluvio_profile_test.XXXXXX)
debug_msg "Export current profile to $TMPFILE"
"$FLUVIO_BIN" profile export > $TMPFILE
export FLV_PROFILE_PATH=$TMPFILE
run timeout 15s "$FLUVIO_BIN" topic list
EXP_PROFILE=$(cat $TMPFILE)
debug_msg "# FLV_PROFILE_PATH: ${FLV_PROFILE_PATH}"
debug_msg "# exported profile:\n$(cat $TMPFILE)"
assert_success
}

20 changes: 10 additions & 10 deletions tests/cli/test_helper/tools_check.bash
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ function check_fluvio_bin_path() {

if [[ -n $FLUVIO_BIN ]]; then
if [[ -n $DEBUG ]]; then
echo "# DEBUG: found: FLUVIO_BIN was defined" >&3
echo "# DEBUG: found: FLUVIO_BIN was defined"
fi
_set_fluvio_bin_path_then_exit "$FLUVIO_BIN";
elif which fluvio; then
if [[ -n $DEBUG ]]; then
echo "# DEBUG: found: fluvio in PATH" >&3
echo "# DEBUG: found: fluvio in PATH"
fi
_set_fluvio_bin_path_then_exit "$(which fluvio)";
elif test -f "$(pwd)/fluvio"; then
if [[ -n $DEBUG ]]; then
echo "# DEBUG: found: fluvio in current directory" >&3
echo "# DEBUG: found: fluvio in current directory"
fi
_set_fluvio_bin_path_then_exit "$(pwd)/fluvio";
elif test -f "$HOME/.fluvio/bin/fluvio"; then
if [[ -n $DEBUG ]]; then
echo "# DEBUG: found: fluvio in home directory" >&3
echo "# DEBUG: found: fluvio in home directory"
fi
_set_fluvio_bin_path_then_exit "$HOME/.fluvio/bin/fluvio";
fi
Expand All @@ -43,7 +43,7 @@ function _set_fluvio_bin_path_then_exit() {
FLUVIO_BIN=$1
export FLUVIO_BIN
if [[ -n $DEBUG ]]; then
echo "# DEBUG: Fluvio binary path: $FLUVIO_BIN" >&3
echo "# DEBUG: Fluvio binary path: $FLUVIO_BIN"
fi

}
Expand All @@ -61,12 +61,12 @@ function check_load_bats_libraries() {
# If not there, try to clone it into place

if ! test -d "$TEST_HELPER_DIR/bats-support"; then
echo "# Installing bats-support in $TEST_HELPER_DIR" >&3
echo "# Installing bats-support in $TEST_HELPER_DIR"
git clone https://github.com/bats-core/bats-support "$TEST_HELPER_DIR/bats-support"
fi

if ! test -d "$TEST_HELPER_DIR/bats-assert"; then
echo "# Installing bats-assert in $TEST_HELPER_DIR" >&3
echo "# Installing bats-assert in $TEST_HELPER_DIR"
git clone https://github.com/bats-core/bats-assert "$TEST_HELPER_DIR/bats-assert"
fi
}
Expand All @@ -76,7 +76,7 @@ function check_timeout_bin() {
echo "# \`timeout\` not in PATH" >&3

if [[ $(uname) == "Darwin" ]]; then
echo "# run \`brew install coreutils\` to install" >&3
echo "# run \`brew install coreutils\` to install"
fi

false
Expand All @@ -89,7 +89,7 @@ function wait_for_line_in_file() {
MAX_SECONDS="${3:-30}" # 30 seconds default value

echo "Waiting for file $FILE containing $LINE"

ELAPSED=0;
until grep -q "$LINE" "$FILE"
do
Expand All @@ -99,7 +99,7 @@ function wait_for_line_in_file() {
then
echo "timeout $MAX_SECONDS seconds elapsed"
exit 1
fi
fi
done
echo "Done waiting for file $FILE containing $LINE"
}
Expand Down

0 comments on commit 65c5b92

Please sign in to comment.