[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated: handle bogus continent selectio
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated: handle bogus continent selection case, improve test logic |
Date: |
Tue, 23 Feb 2021 08:37:57 +0100 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository anastasis.
The following commit(s) were added to refs/heads/master by this push:
new c7920a3 handle bogus continent selection case, improve test logic
c7920a3 is described below
commit c7920a31f39844a4e8fba4255df203d891493c52
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Tue Feb 23 08:37:55 2021 +0100
handle bogus continent selection case, improve test logic
---
src/cli/Makefile.am | 4 +-
src/cli/anastasis-cli-redux.c | 14 +++---
src/cli/resources/00-backup.json | 7 +++
src/cli/resources/00-recovery.json | 7 +++
src/cli/resources/01-backup.json | 37 ++++++++++++++++
src/cli/resources/01-recovery.json | 37 ++++++++++++++++
src/cli/test_anastasis_reducer_initialize_state.sh | 26 ++++++-----
src/cli/test_anastasis_reducer_select_continent.sh | 51 +++++++++++++++-------
src/reducer/anastasis_api_redux.c | 12 +++++
9 files changed, 158 insertions(+), 37 deletions(-)
diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am
index 1272192..701d290 100644
--- a/src/cli/Makefile.am
+++ b/src/cli/Makefile.am
@@ -32,8 +32,8 @@ EXTRA_DIST = \
test_anastasis_reducer.conf \
test_anastasis_reducer_1.conf \
test_anastasis_reducer_2.conf \
- test_anastasis_reducer_3.conf \
- test_reducer_home/resources
+ test_anastasis_reducer_3.conf
+# test_resources
anastasis_reducer_SOURCES = \
anastasis-cli-redux.c
diff --git a/src/cli/anastasis-cli-redux.c b/src/cli/anastasis-cli-redux.c
index b49b132..bd81d93 100644
--- a/src/cli/anastasis-cli-redux.c
+++ b/src/cli/anastasis-cli-redux.c
@@ -207,10 +207,6 @@ run (void *cls,
"Starting anastasis-reducer\n");
GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
NULL);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_log_setup ("anastasis-reducer",
- "DEBUG",
- NULL));
if (b_flag && r_flag)
{
GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
@@ -327,8 +323,6 @@ int
main (int argc,
char *const *argv)
{
- int ret;
-
/* the available command line options */
struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_option_flag ('b',
@@ -347,6 +341,7 @@ main (int argc,
GNUNET_GETOPT_OPTION_END
};
+ enum GNUNET_GenericReturnValue ret;
/* FIRST get the libtalerutil initialization out
of the way. Then throw that one away, and force
@@ -360,8 +355,11 @@ main (int argc,
options,
&run,
NULL);
-
- return (GNUNET_OK == ret) ? global_ret : 1;
+ if (GNUNET_SYSERR == ret)
+ return 3;
+ if (GNUNET_NO == ret)
+ return 0;
+ return global_ret;
}
diff --git a/src/cli/resources/00-backup.json b/src/cli/resources/00-backup.json
new file mode 100644
index 0000000..17f5932
--- /dev/null
+++ b/src/cli/resources/00-backup.json
@@ -0,0 +1,7 @@
+{
+ "continents": [
+ "Europe",
+ "North_America"
+ ],
+ "backup_state": "CONTINENT_SELECTING"
+}
\ No newline at end of file
diff --git a/src/cli/resources/00-recovery.json
b/src/cli/resources/00-recovery.json
new file mode 100644
index 0000000..1a13bb6
--- /dev/null
+++ b/src/cli/resources/00-recovery.json
@@ -0,0 +1,7 @@
+{
+ "continents": [
+ "Europe",
+ "North_America"
+ ],
+ "recovery_state": "CONTINENT_SELECTING"
+}
\ No newline at end of file
diff --git a/src/cli/resources/01-backup.json b/src/cli/resources/01-backup.json
new file mode 100644
index 0000000..356e1b9
--- /dev/null
+++ b/src/cli/resources/01-backup.json
@@ -0,0 +1,37 @@
+{
+ "continents": [
+ "Europe",
+ "North_America"
+ ],
+ "backup_state": "COUNTRY_SELECTING",
+ "selected_continent": "Europe",
+ "countries": [
+ {
+ "code": "ch",
+ "name": "Switzerland",
+ "continent": "Europe",
+ "name_i18n": {
+ "de_DE": "Schweiz",
+ "de_CH": "Schwiiz",
+ "fr": "Suisse",
+ "en": "Swiss"
+ },
+ "currency": "TESTKUDOS"
+ },
+ {
+ "code": "de",
+ "name": "Germany",
+ "continent": "Europe",
+ "continent_i18n": {
+ "de": "Europa"
+ },
+ "name_i18n": {
+ "de_DE": "Deutschland",
+ "de_CH": "Deutschland",
+ "fr": "Allemagne",
+ "en": "Germany"
+ },
+ "currency": "TESTKUDOS"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/cli/resources/01-recovery.json
b/src/cli/resources/01-recovery.json
new file mode 100644
index 0000000..877a98a
--- /dev/null
+++ b/src/cli/resources/01-recovery.json
@@ -0,0 +1,37 @@
+{
+ "continents": [
+ "Europe",
+ "North_America"
+ ],
+ "recovery_state": "COUNTRY_SELECTING",
+ "selected_continent": "Europe",
+ "countries": [
+ {
+ "code": "ch",
+ "name": "Switzerland",
+ "continent": "Europe",
+ "name_i18n": {
+ "de_DE": "Schweiz",
+ "de_CH": "Schwiiz",
+ "fr": "Suisse",
+ "en": "Swiss"
+ },
+ "currency": "TESTKUDOS"
+ },
+ {
+ "code": "de",
+ "name": "Germany",
+ "continent": "Europe",
+ "continent_i18n": {
+ "de": "Europa"
+ },
+ "name_i18n": {
+ "de_DE": "Deutschland",
+ "de_CH": "Deutschland",
+ "fr": "Allemagne",
+ "en": "Germany"
+ },
+ "currency": "TESTKUDOS"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/cli/test_anastasis_reducer_initialize_state.sh
b/src/cli/test_anastasis_reducer_initialize_state.sh
index 87f45e9..9dc0c59 100755
--- a/src/cli/test_anastasis_reducer_initialize_state.sh
+++ b/src/cli/test_anastasis_reducer_initialize_state.sh
@@ -4,13 +4,13 @@ set -eu
# Exit, with status code "skip" (no 'real' failure)
function exit_skip() {
- echo $1
+ echo " SKIP: $1"
exit 77
}
# Exit, with error message (hard failure)
function exit_fail() {
- echo $1
+ echo " FAIL: $1"
exit 1
}
@@ -32,31 +32,33 @@ TFILE=`mktemp test_reducer_stateXXXXXX`
trap cleanup EXIT
# Check we can actually run
-echo -n "Testing for jq"
+echo -n "Testing for jq ..."
jq -h > /dev/null || exit_skip "jq required"
echo " FOUND"
-
-echo " "
-echo "Beginning with actual reducer test"
-
-echo " "
-echo "Test initialization of a backup state"
-./anastasis-reducer -b $SFILE
+echo -n "Testing for anastasis-reducer ..."
+anastasis-reducer -h > /dev/null || exit_skip "anastasis-reducer required"
+echo " FOUND"
+echo -n "Test initialization of a backup state ..."
+anastasis-reducer -b $SFILE
STATE=`jq -r -e .backup_state < $SFILE`
if test "$STATE" != "CONTINENT_SELECTING"
then
exit_fail "Expected initial state to be CONTINENT_SELECTING, got $STATE"
fi
+jq -e .continents[0] < $SFILE > /dev/null || exit_fail "Expected initial state
to include continents"
+echo " OK"
-echo "Test initialization of a recovery state"
-./anastasis-reducer -r $TFILE
+echo -n "Test initialization of a recovery state ..."
+anastasis-reducer -r $TFILE
STATE=`jq -r -e .recovery_state < $TFILE`
if test "$STATE" != "CONTINENT_SELECTING"
then
exit_fail "Expected initial state to be CONTINENT_SELECTING, got $STATE"
fi
+jq -e .continents[0] < $TFILE > /dev/null || exit_fail "Expected initial state
to include continents"
+echo " OK"
exit 0
diff --git a/src/cli/test_anastasis_reducer_select_continent.sh
b/src/cli/test_anastasis_reducer_select_continent.sh
index 946686c..318d6b2 100755
--- a/src/cli/test_anastasis_reducer_select_continent.sh
+++ b/src/cli/test_anastasis_reducer_select_continent.sh
@@ -4,13 +4,13 @@ set -eu
# Exit, with status code "skip" (no 'real' failure)
function exit_skip() {
- echo $1
+ echo " SKIP: $1"
exit 77
}
# Exit, with error message (hard failure)
function exit_fail() {
- echo $1
+ echo " FAIL: $1"
exit 1
}
@@ -32,47 +32,48 @@ TFILE=`mktemp test_reducer_stateXXXXXX`
trap cleanup EXIT
# Check we can actually run
-echo -n "Testing for jq"
+echo -n "Testing for jq ..."
jq -h > /dev/null || exit_skip "jq required"
echo " FOUND"
-
-echo " "
-echo "Beginning with actual reducer test"
+echo -n "Testing for anastasis-reducer ..."
+anastasis-reducer -h > /dev/null || exit_skip "anastasis-reducer required"
+echo " FOUND"
# Test continent selection in a backup state
-echo " "
-echo "Test continent selection in a backup state"
-./anastasis-reducer -b $SFILE
-./anastasis-reducer -a '{"continent": "Europe"}' select_continent $SFILE $TFILE
+echo -n "Test continent selection in a backup state ..."
+anastasis-reducer -a '{"continent": "Europe"}' select_continent
resources/00-backup.json $TFILE
STATE=`jq -r -e .backup_state < $TFILE`
if test "$STATE" != "COUNTRY_SELECTING"
then
exit_fail "Expected new state to be COUNTRY_SELECTING, got $STATE"
fi
-
SELECTED_CONTINENT=`jq -r -e .selected_continent < $TFILE`
if test "$SELECTED_CONTINENT" != "Europe"
then
exit_fail "Expected selected continent to be Europe, got
$SELECTED_CONTINENT"
fi
-
COUNTRIES=`jq -r -e .countries < $TFILE`
if test "$COUNTRIES" == NULL
then
exit_fail "Expected country array (countries) not to be NULL"
fi
+echo " OK"
# Test continent selection in a recovery state
-echo "Test continent selection in a recovery state"
-./anastasis-reducer -r $SFILE
-./anastasis-reducer -a '{"continent": "Europe"}' select_continent $SFILE $TFILE
+echo -n "Test continent selection in a recovery state ..."
+anastasis-reducer -a '{"continent": "Europe"}' select_continent
resources/00-recovery.json $TFILE
STATE=`jq -r -e .recovery_state < $TFILE`
if test "$STATE" != "COUNTRY_SELECTING"
then
exit_fail "Expected new state to be COUNTRY_SELECTING, got $STATE"
fi
+jq -e .countries[0] < $TFILE > /dev/null || exit_fail "Expected new state to
include countries"
+jq -e .countries[0].code < $TFILE > /dev/null || exit_fail "Expected new state
to include countries with code"
+jq -e .countries[0].continent < $TFILE > /dev/null || exit_fail "Expected new
state to include countries with continent"
+jq -e .countries[0].name < $TFILE > /dev/null || exit_fail "Expected new state
to include countries with name"
+jq -e .countries[0].currency < $TFILE > /dev/null || exit_fail "Expected new
state to include countries with currency"
SELECTED_CONTINENT=`jq -r -e .selected_continent < $TFILE`
if test "$SELECTED_CONTINENT" != "Europe"
@@ -85,5 +86,25 @@ if test "$COUNTRIES" == NULL
then
exit_fail "Expected country array (countries) not to be NULL"
fi
+jq -e .countries[0] < $TFILE > /dev/null || exit_fail "Expected new state to
include countries"
+jq -e .countries[0].code < $TFILE > /dev/null || exit_fail "Expected new state
to include countries with code"
+jq -e .countries[0].continent < $TFILE > /dev/null || exit_fail "Expected new
state to include countries with continent"
+jq -e .countries[0].name < $TFILE > /dev/null || exit_fail "Expected new state
to include countries with name"
+jq -e .countries[0].currency < $TFILE > /dev/null || exit_fail "Expected new
state to include countries with currency"
+
+echo " OK"
+
+
+# Test missing arguments in a recovery state
+echo -n "Test bogus country selection in a recovery state ..."
+anastasis-reducer -a '{"country": "Germany"}' select_continent
resources/00-recovery.json $TFILE 2> /dev/null && exit_fail "Expected state
transition to fail, but it worked, check $TFILE"
+
+echo " OK"
+
+# Test continent selection in a recovery state
+echo -n "Test bogus continent selection in a recovery state ..."
+anastasis-reducer -a '{"continent": "Germany"}' select_continent
resources/00-recovery.json $TFILE 2> /dev/null && exit_fail "Expected state
transition to fail, but it worked, check $TFILE"
+
+echo " OK"
exit 0
diff --git a/src/reducer/anastasis_api_redux.c
b/src/reducer/anastasis_api_redux.c
index 09a7898..dba516f 100644
--- a/src/reducer/anastasis_api_redux.c
+++ b/src/reducer/anastasis_api_redux.c
@@ -890,6 +890,7 @@ select_continent (json_t *state,
{
size_t index;
json_t *country;
+ bool found = false;
json_array_foreach (root, index, country)
{
@@ -897,9 +898,20 @@ select_continent (json_t *state,
"continent");
if (1 == json_equal (continent,
temp_continent))
+ {
GNUNET_assert (0 ==
json_array_append_new (countries,
country));
+ found = true;
+ }
+ }
+ if (! found)
+ {
+ ANASTASIS_redux_fail_ (cb,
+ cb_cls,
+ TALER_EC_ANASTASIS_REDUCER_INPUT_INVALID,
+ "'continent' unknown");
+ return NULL;
}
}
redux_transition (state,
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-anastasis] branch master updated: handle bogus continent selection case, improve test logic,
gnunet <=