From 3ff42af9c729025e05411b95c61fadf9e2e24723 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 31 Jan 2015 18:34:25 -0500 Subject: [PATCH] Unit Tests - Added sample hooks that behave/misbehave in various ways. --- test/test_hooks/on-add-accept | 19 +++++++++++++++++++ test/test_hooks/on-add-misbehave1 | 17 +++++++++++++++++ test/test_hooks/on-add-misbehave2 | 17 +++++++++++++++++ test/test_hooks/on-add-misbehave3 | 20 ++++++++++++++++++++ test/test_hooks/on-add-misbehave4 | 19 +++++++++++++++++++ test/test_hooks/on-add-misbehave5 | 19 +++++++++++++++++++ test/test_hooks/on-add-misbehave6 | 19 +++++++++++++++++++ test/test_hooks/on-add-reject | 19 +++++++++++++++++++ test/test_hooks/on-exit-bad | 20 ++++++++++++++++++++ test/test_hooks/on-exit-good | 20 ++++++++++++++++++++ test/test_hooks/on-exit-misbehave1 | 16 ++++++++++++++++ test/test_hooks/on-launch-bad | 17 +++++++++++++++++ test/test_hooks/on-launch-good | 17 +++++++++++++++++ test/test_hooks/on-launch-misbehave1 | 18 ++++++++++++++++++ test/test_hooks/on-modify-accept | 21 +++++++++++++++++++++ test/test_hooks/on-modify-misbehave1 | 18 ++++++++++++++++++ test/test_hooks/on-modify-misbehave2 | 19 +++++++++++++++++++ test/test_hooks/on-modify-misbehave3 | 22 ++++++++++++++++++++++ test/test_hooks/on-modify-misbehave4 | 21 +++++++++++++++++++++ test/test_hooks/on-modify-misbehave5 | 21 +++++++++++++++++++++ test/test_hooks/on-modify-misbehave6 | 21 +++++++++++++++++++++ test/test_hooks/on-modify-reject | 21 +++++++++++++++++++++ 22 files changed, 421 insertions(+) create mode 100644 test/test_hooks/on-add-accept create mode 100644 test/test_hooks/on-add-misbehave1 create mode 100644 test/test_hooks/on-add-misbehave2 create mode 100644 test/test_hooks/on-add-misbehave3 create mode 100644 test/test_hooks/on-add-misbehave4 create mode 100644 test/test_hooks/on-add-misbehave5 create mode 100644 test/test_hooks/on-add-misbehave6 create mode 100644 test/test_hooks/on-add-reject create mode 100644 test/test_hooks/on-exit-bad create mode 100644 test/test_hooks/on-exit-good create mode 100644 test/test_hooks/on-exit-misbehave1 create mode 100644 test/test_hooks/on-launch-bad create mode 100644 test/test_hooks/on-launch-good create mode 100644 test/test_hooks/on-launch-misbehave1 create mode 100644 test/test_hooks/on-modify-accept create mode 100644 test/test_hooks/on-modify-misbehave1 create mode 100644 test/test_hooks/on-modify-misbehave2 create mode 100644 test/test_hooks/on-modify-misbehave3 create mode 100644 test/test_hooks/on-modify-misbehave4 create mode 100644 test/test_hooks/on-modify-misbehave5 create mode 100644 test/test_hooks/on-modify-misbehave6 create mode 100644 test/test_hooks/on-modify-reject diff --git a/test/test_hooks/on-add-accept b/test/test_hooks/on-add-accept new file mode 100644 index 000000000..71bf12a43 --- /dev/null +++ b/test/test_hooks/on-add-accept @@ -0,0 +1,19 @@ +#!/bin/bash + +# The on-add event is triggered separately for each task added. This hook +# script can accept/reject the addition. Processing will continue. + +# Input: +# - Line of JSON for proposed new task. +read new_task + +# Output: +# - JSON, modified or unmodified. +# - Optional feedback/error. +echo $new_task +echo 'FEEDBACK' + +# Status: +# - 0: JSON accepted, non-JSON is feedback. +# - non-0: JSON ignored, non-JSON is error. +exit 0 diff --git a/test/test_hooks/on-add-misbehave1 b/test/test_hooks/on-add-misbehave1 new file mode 100644 index 000000000..c465f0bfd --- /dev/null +++ b/test/test_hooks/on-add-misbehave1 @@ -0,0 +1,17 @@ +#!/bin/bash + +# The on-add event is triggered separately for each task added. This hook +# script can accept/reject the addition. Processing will continue. + +# Input: +# - Line of JSON for proposed new task. + +# Output: +# - JSON, modified or unmodified. +# - Optional feedback/error. +echo 'FEEDBACK' + +# Status: +# - 0: JSON accepted, non-JSON is feedback. +# - non-0: JSON ignored, non-JSON is error. +exit 1 diff --git a/test/test_hooks/on-add-misbehave2 b/test/test_hooks/on-add-misbehave2 new file mode 100644 index 000000000..9f083af9e --- /dev/null +++ b/test/test_hooks/on-add-misbehave2 @@ -0,0 +1,17 @@ +#!/bin/bash + +# The on-add event is triggered separately for each task added. This hook +# script can accept/reject the addition. Processing will continue. + +# Input: +# - Line of JSON for proposed new task. +read new_task + +# Output: +# - JSON, modified or unmodified. +# - Optional feedback/error. + +# Status: +# - 0: JSON accepted, non-JSON is feedback. +# - non-0: JSON ignored, non-JSON is error. +exit 0 diff --git a/test/test_hooks/on-add-misbehave3 b/test/test_hooks/on-add-misbehave3 new file mode 100644 index 000000000..96a51a3dc --- /dev/null +++ b/test/test_hooks/on-add-misbehave3 @@ -0,0 +1,20 @@ +#!/bin/bash + +# The on-add event is triggered separately for each task added. This hook +# script can accept/reject the addition. Processing will continue. + +# Input: +# - Line of JSON for proposed new task. +read new_task + +# Output: +# - JSON, modified or unmodified. +# - Optional feedback/error. +echo $new_task +echo '{"description":"extra","status":"pending"}' +echo 'FEEDBACK' + +# Status: +# - 0: JSON accepted, non-JSON is feedback. +# - non-0: JSON ignored, non-JSON is error. +exit 0 diff --git a/test/test_hooks/on-add-misbehave4 b/test/test_hooks/on-add-misbehave4 new file mode 100644 index 000000000..efc369a9b --- /dev/null +++ b/test/test_hooks/on-add-misbehave4 @@ -0,0 +1,19 @@ +#!/bin/bash + +# The on-add event is triggered separately for each task added. This hook +# script can accept/reject the addition. Processing will continue. + +# Input: +# - Line of JSON for proposed new task. +read new_task + +# Output: +# - JSON, modified or unmodified. +# - Optional feedback/error. +echo '{"description":"different","status":"pending"}' +echo 'FEEDBACK' + +# Status: +# - 0: JSON accepted, non-JSON is feedback. +# - non-0: JSON ignored, non-JSON is error. +exit 0 diff --git a/test/test_hooks/on-add-misbehave5 b/test/test_hooks/on-add-misbehave5 new file mode 100644 index 000000000..f250634ca --- /dev/null +++ b/test/test_hooks/on-add-misbehave5 @@ -0,0 +1,19 @@ +#!/bin/bash + +# The on-add event is triggered separately for each task added. This hook +# script can accept/reject the addition. Processing will continue. + +# Input: +# - Line of JSON for proposed new task. +read new_task + +# Output: +# - JSON, modified or unmodified. +# - Optional feedback/error. +echo '{"}' +echo 'FEEDBACK' + +# Status: +# - 0: JSON accepted, non-JSON is feedback. +# - non-0: JSON ignored, non-JSON is error. +exit 0 diff --git a/test/test_hooks/on-add-misbehave6 b/test/test_hooks/on-add-misbehave6 new file mode 100644 index 000000000..ec49d0095 --- /dev/null +++ b/test/test_hooks/on-add-misbehave6 @@ -0,0 +1,19 @@ +#!/bin/bash + +# The on-add event is triggered separately for each task added. This hook +# script can accept/reject the addition. Processing will continue. + +# Input: +# - Line of JSON for proposed new task. +read new_task + +# Output: +# - JSON, modified or unmodified. +# - Optional feedback/error. +echo '{"description":"invalid"}' +echo 'FEEDBACK' + +# Status: +# - 0: JSON accepted, non-JSON is feedback. +# - non-0: JSON ignored, non-JSON is error. +exit 0 diff --git a/test/test_hooks/on-add-reject b/test/test_hooks/on-add-reject new file mode 100644 index 000000000..2da4e77eb --- /dev/null +++ b/test/test_hooks/on-add-reject @@ -0,0 +1,19 @@ +#!/bin/bash + +# The on-add event is triggered separately for each task added. This hook +# script can accept/reject the addition. Processing will continue. + +# Input: +# - Line of JSON for proposed new task. +read new_task + +# Output: +# - JSON, modified or unmodified. +# - Optional feedback/error. +echo $new_task +echo 'FEEDBACK' + +# Status: +# - 0: JSON accepted, non-JSON is feedback. +# - non-0: JSON ignored, non-JSON is error. +exit 1 diff --git a/test/test_hooks/on-exit-bad b/test/test_hooks/on-exit-bad new file mode 100644 index 000000000..a9f2a38dd --- /dev/null +++ b/test/test_hooks/on-exit-bad @@ -0,0 +1,20 @@ +#!/bin/bash + +# The on-exit event is triggered once, after all processing is complete. +# This hooks script has no effect on processing. + +# Input: +# - Read-only line of JSON for each task added/modified +while read modified_task +do + echo 'CHANGED TASK' +done + +# Output: +# - Optional feedback/error. +echo 'FEEDBACK' + +# Status: +# - 0: JSON ignored, non-JSON is feedback. +# - non-0: JSON ignored, non-JSON is error. +exit 1 diff --git a/test/test_hooks/on-exit-good b/test/test_hooks/on-exit-good new file mode 100644 index 000000000..76df2e8a9 --- /dev/null +++ b/test/test_hooks/on-exit-good @@ -0,0 +1,20 @@ +#!/bin/bash + +# The on-exit event is triggered once, after all processing is complete. +# This hooks script has no effect on processing. + +# Input: +# - Read-only line of JSON for each task added/modified +while read modified_task +do + echo 'CHANGED TASK' +done + +# Output: +# - Optional feedback/error. +echo 'FEEDBACK' + +# Status: +# - 0: JSON ignored, non-JSON is feedback. +# - non-0: JSON ignored, non-JSON is error. +exit 0 diff --git a/test/test_hooks/on-exit-misbehave1 b/test/test_hooks/on-exit-misbehave1 new file mode 100644 index 000000000..8bce6b091 --- /dev/null +++ b/test/test_hooks/on-exit-misbehave1 @@ -0,0 +1,16 @@ +#!/bin/bash + +# The on-exit event is triggered once, after all processing is complete. +# This hooks script has no effect on processing. + +# Input: +# - Read-only line of JSON for each task added/modified + +# Output: +# - Optional feedback/error. +echo 'FEEDBACK' + +# Status: +# - 0: JSON ignored, non-JSON is feedback. +# - non-0: JSON ignored, non-JSON is error. +exit 0 diff --git a/test/test_hooks/on-launch-bad b/test/test_hooks/on-launch-bad new file mode 100644 index 000000000..3a74046ba --- /dev/null +++ b/test/test_hooks/on-launch-bad @@ -0,0 +1,17 @@ +#!/bin/bash + +# The on-launch event is triggered once, after initialization, before any +# processing occurs. This hooks script has no effect on processing. + +# Input: +# - None + +# Output: +# - Optional feedback/error. +echo 'FEEDBACK' + +# Status: +# - 0: JSON ignored, non-JSON is feedback. +# - non-0: JSON ignored, non-JSON is error. +exit 1 + diff --git a/test/test_hooks/on-launch-good b/test/test_hooks/on-launch-good new file mode 100644 index 000000000..ee4db9aef --- /dev/null +++ b/test/test_hooks/on-launch-good @@ -0,0 +1,17 @@ +#!/bin/bash + +# The on-launch event is triggered once, after initialization, before any +# processing occurs. This hooks script has no effect on processing. + +# Input: +# - None + +# Output: +# - Optional feedback/error. +echo 'FEEDBACK' + +# Status: +# - 0: JSON ignored, non-JSON is feedback. +# - non-0: JSON ignored, non-JSON is error. +exit 0 + diff --git a/test/test_hooks/on-launch-misbehave1 b/test/test_hooks/on-launch-misbehave1 new file mode 100644 index 000000000..7830d1626 --- /dev/null +++ b/test/test_hooks/on-launch-misbehave1 @@ -0,0 +1,18 @@ +#!/bin/bash + +# The on-launch event is triggered once, after initialization, before any +# processing occurs. This hooks script has no effect on processing. + +# Input: +# - None + +# Output: +# - Optional feedback/error. +echo 'FEEDBACK' + +# Status: +# - 0: JSON ignored, non-JSON is feedback. +# - non-0: JSON ignored, non-JSON is error. +kill -9 $$ +exit 0 + diff --git a/test/test_hooks/on-modify-accept b/test/test_hooks/on-modify-accept new file mode 100644 index 000000000..649c33ad3 --- /dev/null +++ b/test/test_hooks/on-modify-accept @@ -0,0 +1,21 @@ +#!/bin/bash + +# The on-modify event is triggered separately for each task modified. This hook +# script can accept/reject the modification. Processing will continue. + +# Input: +# - line of JSON for the original task +# - line of JSON for the modified task, the diff being the modification +read original_task +read modified_task + +# Output: +# - JSON, modified or unmodified. +# - Optional feedback/error. +echo $modified_task +echo 'FEEDBACK' + +# Status: +# - 0: JSON accepted, non-JSON is feedback. +# - non-0: JSON ignored, non-JSON is error. +exit 0 diff --git a/test/test_hooks/on-modify-misbehave1 b/test/test_hooks/on-modify-misbehave1 new file mode 100644 index 000000000..15ac4a2f1 --- /dev/null +++ b/test/test_hooks/on-modify-misbehave1 @@ -0,0 +1,18 @@ +#!/bin/bash + +# The on-modify event is triggered separately for each task modified. This hook +# script can accept/reject the modification. Processing will continue. + +# Input: +# - line of JSON for the original task +# - line of JSON for the modified task, the diff being the modification + +# Output: +# - JSON, modified or unmodified. +# - Optional feedback/error. +echo 'FEEDBACK' + +# Status: +# - 0: JSON accepted, non-JSON is feedback. +# - non-0: JSON ignored, non-JSON is error. +exit 1 diff --git a/test/test_hooks/on-modify-misbehave2 b/test/test_hooks/on-modify-misbehave2 new file mode 100644 index 000000000..8a828b583 --- /dev/null +++ b/test/test_hooks/on-modify-misbehave2 @@ -0,0 +1,19 @@ +#!/bin/bash + +# The on-modify event is triggered separately for each task modified. This hook +# script can accept/reject the modification. Processing will continue. + +# Input: +# - line of JSON for the original task +# - line of JSON for the modified task, the diff being the modification +read original_task +read modified_task + +# Output: +# - JSON, modified or unmodified. +# - Optional feedback/error. + +# Status: +# - 0: JSON accepted, non-JSON is feedback. +# - non-0: JSON ignored, non-JSON is error. +exit 0 diff --git a/test/test_hooks/on-modify-misbehave3 b/test/test_hooks/on-modify-misbehave3 new file mode 100644 index 000000000..dc2c78e82 --- /dev/null +++ b/test/test_hooks/on-modify-misbehave3 @@ -0,0 +1,22 @@ +#!/bin/bash + +# The on-modify event is triggered separately for each task modified. This hook +# script can accept/reject the modification. Processing will continue. + +# Input: +# - line of JSON for the original task +# - line of JSON for the modified task, the diff being the modification +read original_task +read modified_task + +# Output: +# - JSON, modified or unmodified. +# - Optional feedback/error. +echo $modified_task +echo '{"description":"extra","status":"pending"}' +echo 'FEEDBACK' + +# Status: +# - 0: JSON accepted, non-JSON is feedback. +# - non-0: JSON ignored, non-JSON is error. +exit 0 diff --git a/test/test_hooks/on-modify-misbehave4 b/test/test_hooks/on-modify-misbehave4 new file mode 100644 index 000000000..b75bf864a --- /dev/null +++ b/test/test_hooks/on-modify-misbehave4 @@ -0,0 +1,21 @@ +#!/bin/bash + +# The on-modify event is triggered separately for each task modified. This hook +# script can accept/reject the modification. Processing will continue. + +# Input: +# - line of JSON for the original task +# - line of JSON for the modified task, the diff being the modification +read original_task +read modified_task + +# Output: +# - JSON, modified or unmodified. +# - Optional feedback/error. +echo '{"description":"different","status":"pending"}' +echo 'FEEDBACK' + +# Status: +# - 0: JSON accepted, non-JSON is feedback. +# - non-0: JSON ignored, non-JSON is error. +exit 0 diff --git a/test/test_hooks/on-modify-misbehave5 b/test/test_hooks/on-modify-misbehave5 new file mode 100644 index 000000000..d33f7d69a --- /dev/null +++ b/test/test_hooks/on-modify-misbehave5 @@ -0,0 +1,21 @@ +#!/bin/bash + +# The on-modify event is triggered separately for each task modified. This hook +# script can accept/reject the modification. Processing will continue. + +# Input: +# - line of JSON for the original task +# - line of JSON for the modified task, the diff being the modification +read original_task +read modified_task + +# Output: +# - JSON, modified or unmodified. +# - Optional feedback/error. +echo '{"}' +echo 'FEEDBACK' + +# Status: +# - 0: JSON accepted, non-JSON is feedback. +# - non-0: JSON ignored, non-JSON is error. +exit 0 diff --git a/test/test_hooks/on-modify-misbehave6 b/test/test_hooks/on-modify-misbehave6 new file mode 100644 index 000000000..6a0d2bc1e --- /dev/null +++ b/test/test_hooks/on-modify-misbehave6 @@ -0,0 +1,21 @@ +#!/bin/bash + +# The on-modify event is triggered separately for each task modified. This hook +# script can accept/reject the modification. Processing will continue. + +# Input: +# - line of JSON for the original task +# - line of JSON for the modified task, the diff being the modification +read original_task +read modified_task + +# Output: +# - JSON, modified or unmodified. +# - Optional feedback/error. +echo '{"description":"invalid"}' +echo 'FEEDBACK' + +# Status: +# - 0: JSON accepted, non-JSON is feedback. +# - non-0: JSON ignored, non-JSON is error. +exit 0 diff --git a/test/test_hooks/on-modify-reject b/test/test_hooks/on-modify-reject new file mode 100644 index 000000000..5a811a335 --- /dev/null +++ b/test/test_hooks/on-modify-reject @@ -0,0 +1,21 @@ +#!/bin/bash + +# The on-modify event is triggered separately for each task modified. This hook +# script can accept/reject the modification. Processing will continue. + +# Input: +# - line of JSON for the original task +# - line of JSON for the modified task, the diff being the modification +read original_task +read modified_task + +# Output: +# - JSON, modified or unmodified. +# - Optional feedback/error. +echo $modified_task +echo 'FEEDBACK' + +# Status: +# - 0: JSON accepted, non-JSON is feedback. +# - non-0: JSON ignored, non-JSON is error. +exit 1