From df1890ef7fc0691c0b940f00ddff14a1c395a52a Mon Sep 17 00:00:00 2001 From: Wen Hui Date: Wed, 17 May 2023 03:26:02 -0400 Subject: Allow SENTINEL CONFIG SET and SENTINEL CONFIG GET to handle multiple parameters. (#10362) Extend SENTINEL CONFIG SET and SENTINEL CONFIG GET to be compatible with variadic CONFIG SET and CONFIG GET and allow multiple parameters to be modified in a single call atomically. Co-authored-by: Oran Agra --- tests/sentinel/tests/15-config-set-config-get.tcl | 58 +++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tests/sentinel/tests/15-config-set-config-get.tcl (limited to 'tests/sentinel/tests/15-config-set-config-get.tcl') diff --git a/tests/sentinel/tests/15-config-set-config-get.tcl b/tests/sentinel/tests/15-config-set-config-get.tcl new file mode 100644 index 000000000..f9831f8e8 --- /dev/null +++ b/tests/sentinel/tests/15-config-set-config-get.tcl @@ -0,0 +1,58 @@ +source "../tests/includes/init-tests.tcl" + +test "SENTINEL CONFIG SET and SENTINEL CONFIG GET handles multiple variables" { + foreach_sentinel_id id { + assert_equal {OK} [S $id SENTINEL CONFIG SET resolve-hostnames yes announce-port 1234] + } + assert_match {*yes*1234*} [S 1 SENTINEL CONFIG GET resolve-hostnames announce-port] + assert_match {announce-port 1234} [S 1 SENTINEL CONFIG GET announce-port] +} + +test "SENTINEL CONFIG GET for duplicate and unknown variables" { + assert_equal {OK} [S 1 SENTINEL CONFIG SET resolve-hostnames yes announce-port 1234] + assert_match {resolve-hostnames yes} [S 1 SENTINEL CONFIG GET resolve-hostnames resolve-hostnames does-not-exist] +} + +test "SENTINEL CONFIG GET for patterns" { + assert_equal {OK} [S 1 SENTINEL CONFIG SET loglevel notice announce-port 1234 announce-hostnames yes ] + assert_match {loglevel notice} [S 1 SENTINEL CONFIG GET log* *level loglevel] + assert_match {announce-hostnames yes announce-ip*announce-port 1234} [S 1 SENTINEL CONFIG GET announce*] +} + +test "SENTINEL CONFIG SET duplicate variables" { + catch {[S 1 SENTINEL CONFIG SET resolve-hostnames yes announce-port 1234 announce-port 100]} e + if {![string match "*Duplicate argument*" $e]} { + fail "Should give wrong arity error" + } +} + +test "SENTINEL CONFIG SET, one option does not exist" { + foreach_sentinel_id id { + assert_equal {OK} [S $id SENTINEL CONFIG SET announce-port 111] + catch {[S $id SENTINEL CONFIG SET does-not-exist yes announce-port 1234]} e + if {![string match "*Invalid argument*" $e]} { + fail "Should give Invalid argument error" + } + } + # The announce-port should not be set to 1234 as it was called with a wrong argument + assert_match {*111*} [S 1 SENTINEL CONFIG GET announce-port] +} + +test "SENTINEL CONFIG SET, one option with wrong value" { + foreach_sentinel_id id { + assert_equal {OK} [S $id SENTINEL CONFIG SET resolve-hostnames no] + catch {[S $id SENTINEL CONFIG SET announce-port -1234 resolve-hostnames yes]} e + if {![string match "*Invalid value*" $e]} { + fail "Expected to return Invalid value error" + } + } + # The resolve-hostnames should not be set to yes as it was called after an argument with an invalid value + assert_match {*no*} [S 1 SENTINEL CONFIG GET resolve-hostnames] +} + +test "SENTINEL CONFIG SET, wrong number of arguments" { + catch {[S 1 SENTINEL CONFIG SET resolve-hostnames yes announce-port 1234 announce-ip]} e + if {![string match "*Missing argument*" $e]} { + fail "Expected to return Missing argument error" + } +} -- cgit v1.2.1