diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2014-03-26 15:38:27 +0000 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2014-03-26 15:38:27 +0000 |
commit | 2f9a0bf27a7b14c86f9c91488ab67239cdda4d74 (patch) | |
tree | 03e56817fa870fe96ad4cc415405a5143e013764 | |
parent | 49d4a51b62b305d282061ff1f2cb80ad3ede12d2 (diff) | |
download | lorry-controller-2f9a0bf27a7b14c86f9c91488ab67239cdda4d74.tar.gz |
Start CONFGIT validation yarns
-rw-r--r-- | yarns.webapp/060-validation.yarn | 84 | ||||
-rw-r--r-- | yarns.webapp/900-implementations.yarn | 19 | ||||
-rw-r--r-- | yarns.webapp/yarn.sh | 12 |
3 files changed, 115 insertions, 0 deletions
diff --git a/yarns.webapp/060-validation.yarn b/yarns.webapp/060-validation.yarn new file mode 100644 index 0000000..82c957d --- /dev/null +++ b/yarns.webapp/060-validation.yarn @@ -0,0 +1,84 @@ +Validation of CONFGIT +===================== + +The CONFGIT repository contains two types of files we should validate: +the `lorry-controller.conf` file, and the local Lorry files (specified +by the former file in `lorries` sections). + +Validate `lorry-controller.conf` +-------------------------------- + +We'll start by validating the `lorry-controller.conf` file. There's +several aspects here that need to be tested: + +* JSON syntax correctness: if the file doesn't parse as JSON, the + WEBAPP should cope and shouldn't change STATEDB in any way. +* Semantic correctness: the file should contain a list of dicts, and + each dict should have the right fields with the right kind of + values. See the `README` for details. Other fields are also allowed, + though ignored. Again, if there's an error, WEBAPP should cope, and + probably shouldn't update STATEDB if there are any problems. + +The approach for testing this is to set up an empty STATEDB, then get +WEBAPP to read a `lorry-controller.conf` with various kinds of +brokenness, and after each read verify that STATEDB is still empty. +This doesn't test that if the STATEDB wasn't empty it doesn't change +existing data, but it seems like a reasonable assumption that an +update happens regardless of previous contents of STATEDB, given how +SQL transactions work. + +In summary: + +* Start WEBAPP without a STATEDB, and have it read its config. Verify + STATEDB is empty. +* Add a `lorry-controller.conf` that is broken in some specific way. +* Tell WEBAPP to re-read its config. +* Verify that WEBAPP gives an error message. +* Verify that STATEDB is still empty. + +Repeat this for each type of brokenness we want to ensure WEBAPP +validates for. + + SCENARIO validate lorry-controller.conf + GIVEN a new git repository in CONFGIT + AND WEBAPP uses CONFGIT as its configuration directory + AND a running WEBAPP + +First of all, have WEBAPP read CONFGIT. This should succeed even if +the `lorry-controller.conf` file doesn't actually exist. + + WHEN admin makes request POST /1.0/read-configuration with dummy=value + THEN response matches "Configuration has been updated" + AND STATEDB is empty + +Add an empty configuration file. This should still work. + + GIVEN an empty lorry-controller.conf in CONFGIT + WHEN admin makes request POST /1.0/read-configuration with dummy=value + THEN response matches "Configuration has been updated" + AND STATEDB is empty + +Clean up at the end. + + FINALLY WEBAPP terminates + + +Validate local Lorry files +-------------------------- + +Lorry files (`.lorry`) are consumed by the Lorry program itself, but +also by Lorry Controller. In fact, the ones that are in CONFGIT are +only consumed by Lorry Controller: it reads them in, parses them, +extracts the relevant information, puts that into STATEDB, and then +generates a whole new (temporary) file for each Lorry run. + +Lorry Controller doesn't validate the Lorry files much, only +enough that it can extract each separate Lorry specification and feed +them to Lorry one by one. In other words: + +* The `.lorry` file must be valid JSON. +* It must be a dict. +* Each key must map to another dict. +* Each inner dict must have a key "type", which maps to a string. + +Everything else is left for Lorry itself. diff --git a/yarns.webapp/900-implementations.yarn b/yarns.webapp/900-implementations.yarn index f719942..29ebef7 100644 --- a/yarns.webapp/900-implementations.yarn +++ b/yarns.webapp/900-implementations.yarn @@ -381,6 +381,12 @@ value, but we do care that it is there. sys.exit(1) ' < "$DATADIR/response.body" +Some responses are just plain text, so we match them with a regexp. + + IMPLEMENTS THEN response matches "(.*)"$ + cat "$DATADIR/response.body" + grep "$MATCH_1" "$DATADIR/response.body" + Status web page --------------- @@ -403,3 +409,16 @@ purpose. status=$(stat -c %y "$DATADIR/lc-status.html") request=$(stat -c %y "$DATADIR/request.timestamp") test "$request" = "$status" || test "$request" '<' "$status" + + +STATEDB +------- + +Check that the STATEDB is empty. This means it should exist, and +should be initialised, but none of the important tables should have +any rows in them. + + IMPLEMENTS THEN STATEDB is empty + test -s "$DATADIR/webapp.db" + sqlite3 "$DATADIR/webapp.db" 'SELECT * FROM troves;' | stdin_is_empty + sqlite3 "$DATADIR/webapp.db" 'SELECT * FROM lorries;' | stdin_is_empty diff --git a/yarns.webapp/yarn.sh b/yarns.webapp/yarn.sh index a5f22b5..3c617e3 100644 --- a/yarns.webapp/yarn.sh +++ b/yarns.webapp/yarn.sh @@ -42,3 +42,15 @@ add_to_config_file() fi printf '%s = %s\n' "$2" "$3" >> "$1" } + + +# Ensure the standard input is empty. If not, exit with an error. + +stdin_is_empty() +{ + if grep . > /dev/null + then + echo "ERROR: stdin was NOT empty" 1>&2 + exit 1 + fi +} |