Skip to content

Commit 65c5b92

Browse files
authored
fix: profile export, full config, add cli test (#4179)
* 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
1 parent 49447a5 commit 65c5b92

5 files changed

Lines changed: 58 additions & 17 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ env:
2727
CARGO_TERM_COLOR: always
2828
VERBOSE: ${{ github.events.input.verbose }}
2929
K3D_VERSION: v5.4.9
30-
BATS_VERSION: 1.9.0
30+
BATS_VERSION: 1.11.0
3131
MINIKUBE_VERSION: v1.30.1
3232
K8_VERSION: v1.26.3
3333
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
@@ -1410,7 +1410,7 @@ jobs:
14101410

14111411
- name: Start edge cluster remote 2
14121412
timeout-minutes: 10
1413-
run: |
1413+
run: |
14141414
fluvio profile add local2 ${REMOTE_2_SC_PUB_ADDR} local
14151415
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}
14161416
fluvio cluster spu register --id ${REMOTE_2_SPU_ID} -p ${REMOTE_2_SPU_PUB_ADDR} -v ${REMOTE_2_SPU_PRIV_ADDR}

crates/fluvio-cli/src/profile/export.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ impl ExportOpt {
6565
return Err(CliError::ClusterNotFoundInConfig(cluster_name.to_owned()).into());
6666
};
6767

68-
Ok(out.render_serde(&profile_export, output_format.into())?)
68+
if output_format == OutputType::toml {
69+
use fluvio::config::{Config, Profile};
70+
71+
// add cluster to a new config export
72+
let profile_name = cluster_name.clone();
73+
let mut config_export = Config::new();
74+
75+
config_export.add_cluster(profile_export.to_owned(), cluster_name.clone());
76+
let profile = Profile::new(cluster_name.clone());
77+
config_export.add_profile(profile, profile_name.clone());
78+
config_export.set_current_profile(&profile_name);
79+
Ok(out.render_serde(&config_export, output_format.into())?)
80+
} else {
81+
Ok(out.render_serde(&profile_export, output_format.into())?)
82+
}
6983
}
7084
}

makefiles/test.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ cli-partition-test-multiple-partitions:
221221
bats ./tests/cli/partition_test/multiple_partitions.bats
222222

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

tests/cli/fluvio_smoke_tests/profile-export.bats

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,40 @@ load "$TEST_HELPER_DIR"/fluvio_dev.bash
88
load "$TEST_HELPER_DIR"/bats-support/load.bash
99
load "$TEST_HELPER_DIR"/bats-assert/load.bash
1010

11-
# Create topic
12-
@test "Export current profile" {
11+
12+
@test "Export current profile json" {
1313
debug_msg "Export current profile"
14-
run timeout 15s "$FLUVIO_BIN" profile export
14+
run timeout 15s "$FLUVIO_BIN" profile export -O json
1515
debug_msg "status: $status"
1616
debug_msg "output: ${lines[@]}"
1717
assert_success
1818
assert_output --partial 'endpoint'
1919
assert_output --partial 'tls'
2020
}
21+
22+
@test "Export current profile for use with FLV_PROFILE_PATH" {
23+
# the stable version of cli 0.11.11 or older does not support this type of profile export
24+
if [ "$FLUVIO_CLI_RELEASE_CHANNEL" == "stable" ]; then
25+
skip "don't run on fluvio cli stable version"
26+
fi
27+
if [ "$FLUVIO_CLUSTER_RELEASE_CHANNEL" == "stable" ]; then
28+
skip "don't run on cluster stable version"
29+
fi
30+
31+
run timeout 15s "$FLUVIO_BIN" profile export
32+
debug_msg "status: $status"
33+
debug_msg "output: ${lines[@]}"
34+
assert_success
35+
36+
# rerun the export cmd because bats eats the output
37+
export TMPFILE=$(mktemp -t fluvio_profile_test.XXXXXX)
38+
debug_msg "Export current profile to $TMPFILE"
39+
"$FLUVIO_BIN" profile export > $TMPFILE
40+
export FLV_PROFILE_PATH=$TMPFILE
41+
run timeout 15s "$FLUVIO_BIN" topic list
42+
EXP_PROFILE=$(cat $TMPFILE)
43+
debug_msg "# FLV_PROFILE_PATH: ${FLV_PROFILE_PATH}"
44+
debug_msg "# exported profile:\n$(cat $TMPFILE)"
45+
assert_success
46+
}
47+

tests/cli/test_helper/tools_check.bash

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ function check_fluvio_bin_path() {
1818

1919
if [[ -n $FLUVIO_BIN ]]; then
2020
if [[ -n $DEBUG ]]; then
21-
echo "# DEBUG: found: FLUVIO_BIN was defined" >&3
21+
echo "# DEBUG: found: FLUVIO_BIN was defined"
2222
fi
2323
_set_fluvio_bin_path_then_exit "$FLUVIO_BIN";
2424
elif which fluvio; then
2525
if [[ -n $DEBUG ]]; then
26-
echo "# DEBUG: found: fluvio in PATH" >&3
26+
echo "# DEBUG: found: fluvio in PATH"
2727
fi
2828
_set_fluvio_bin_path_then_exit "$(which fluvio)";
2929
elif test -f "$(pwd)/fluvio"; then
3030
if [[ -n $DEBUG ]]; then
31-
echo "# DEBUG: found: fluvio in current directory" >&3
31+
echo "# DEBUG: found: fluvio in current directory"
3232
fi
3333
_set_fluvio_bin_path_then_exit "$(pwd)/fluvio";
3434
elif test -f "$HOME/.fluvio/bin/fluvio"; then
3535
if [[ -n $DEBUG ]]; then
36-
echo "# DEBUG: found: fluvio in home directory" >&3
36+
echo "# DEBUG: found: fluvio in home directory"
3737
fi
3838
_set_fluvio_bin_path_then_exit "$HOME/.fluvio/bin/fluvio";
3939
fi
@@ -43,7 +43,7 @@ function _set_fluvio_bin_path_then_exit() {
4343
FLUVIO_BIN=$1
4444
export FLUVIO_BIN
4545
if [[ -n $DEBUG ]]; then
46-
echo "# DEBUG: Fluvio binary path: $FLUVIO_BIN" >&3
46+
echo "# DEBUG: Fluvio binary path: $FLUVIO_BIN"
4747
fi
4848

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

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

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

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

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

9191
echo "Waiting for file $FILE containing $LINE"
92-
92+
9393
ELAPSED=0;
9494
until grep -q "$LINE" "$FILE"
9595
do
@@ -99,7 +99,7 @@ function wait_for_line_in_file() {
9999
then
100100
echo "timeout $MAX_SECONDS seconds elapsed"
101101
exit 1
102-
fi
102+
fi
103103
done
104104
echo "Done waiting for file $FILE containing $LINE"
105105
}

0 commit comments

Comments
 (0)