Skip to content

Commit

Permalink
ref(15): Start testing wild integration with Jenkins
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanjerome committed Aug 21, 2023
1 parent 6cfc7dc commit 5af0e6b
Show file tree
Hide file tree
Showing 6 changed files with 410 additions and 29 deletions.
16 changes: 9 additions & 7 deletions spec/lib/project_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,35 @@ Describe "Test that project.sh"
export WILD_CWD="${PWD}"
export LOG_PATH="${WILD_CWD}/tmp/log"
export LOG_LEVEL="${LOG_LEVEL_INFO}"
export CONFIG_PATH="${WILD_CWD}/config"
export CONFIG_PATH="${WILD_CWD}/test/config"
}

BeforeAll 'setup'

Describe "project::get_configuration_path"

It "returns the default configuration path if no path is specified"
export CONFIG_PATH="${WILD_CWD}/config"
When call project::get_configuration_path
The status should be success
The output should include "config/project.sh"
The output should include "config/workflow-default.json"
The error should include "No project configuration file specified, use default"
End

It "returns the specified configuration path if a path is specified"
When call project::get_configuration_path "${CONFIG_PATH}/project.sh"
export CONFIG_PATH="${WILD_CWD}/test/config"
When call project::get_configuration_path "${CONFIG_PATH}/workflow-action.json"
The status should be success
The output should include "${CONFIG_PATH}/project.sh"
The output should include "${CONFIG_PATH}/workflow-action.json"
The error should include "Read project configuration"
End

It "exits if the specified configuration path does not exist"
When run project::get_configuration_path "${CONFIG_PATH}/a_bad_project.sh"
When run project::get_configuration_path "${CONFIG_PATH}/a_bad_project.json"
The status should be failure
The status should eq 255
The status should eq 1
The output should eq ""
The error should include "Project configuration file does not exist: ${CONFIG_PATH}/a_bad_project.sh"
The error should include "Project configuration file does not exist: ${CONFIG_PATH}/a_bad_project.json"
End

End
Expand Down
219 changes: 219 additions & 0 deletions spec/lib/workflow_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
# shellcheck disable=SC2148
#
# Description: Unit tests for workflow.sh

Describe "Test that workflow.sh"

Include "./src/lib/log.sh"

setup() {
export WILD_CWD="${PWD}"
export LOG_PATH="${WILD_CWD}/tmp/log"
export LOG_LEVEL="${LOG_LEVEL_INFO}"
export CONFIG_PATH="${WILD_CWD}/config"
}
BeforeAll 'setup'

Include "./src/lib/workflow.sh"

Describe "workflow::_check_prerequisites"

It "returns a status success when all prerequisites are met"

BeforeRun 'JQ=FAKE_JQ'

When run workflow::_check_prerequisites

The status should be success
End

It "returns a status failure when WILD_CWD is not set"

BeforeRun 'unset WILD_CWD'
BeforeRun 'JQ=FAKE_JQ'

When run workflow::_check_prerequisites

The stderr should be present
The status should be failure
End

It "returns a status failure when JQ is not set"

When run workflow::_check_prerequisites

The stderr should be present
The status should be failure
End

End

Describe "workflow::_check_workflow_definition_path"

It "returns a status success when no workflow definition is specified and default one is present on filesystem"

When call workflow::_check_workflow_definition_path

The status should be success
The stdout should eq "config/workflow-default.json"
The stderr should be present # for logs redirected into stderr
End

It "returns a status success when a workflow definition is specified and is present on filesystem"

FAKE_DEFINITION_PATH="config/fake_definition.json"

BeforeRun "touch ${FAKE_DEFINITION_PATH}"
AfterRun "rm ${FAKE_DEFINITION_PATH}"

When run workflow::_check_workflow_definition_path "${FAKE_DEFINITION_PATH}"

The status should be success
The output should eq "${FAKE_DEFINITION_PATH}"
The stderr should be present # for logs redirected into stderr
End

It "returns a status failure when a workflow definition is specified but is not present on filesystem"

When run workflow::_check_workflow_definition_path "config/fake_definition.json"

The status should be failure
The stderr should be present # for logs redirected into stderr
End

End

Describe "workflow::_get_workflows_containers_names"

Include "./src/lib/tooling.sh"

It "returns all actions containers' names from a workflow definition file"

FAKE_DEFINITION_PATH="test/config/workflow-default.json"

BeforeRun "tooling::set_jq"
#BeforeRun "echo '{\"id\": \"fake_id\", \"name\": \"Fake name\", \"version\": \"1.0.0\", \"actions\": []}' > ${FAKE_DEFINITION_PATH}"
#AfterRun "rm ${FAKE_DEFINITION_PATH}"

When run workflow::_get_workflows_containers_names "${FAKE_DEFINITION_PATH}"

The status should be success
The output should eq "bash maven"
The stderr should be present # for logs redirected into stderr
End

End

Describe "workflow::_load_workflow_definition"

Include "./src/lib/tooling.sh"

It "returns an action definition from a workflow definition file"

FAKE_DEFINITION_PATH="config/fake_definition.json"

BeforeRun "tooling::set_jq"
BeforeRun echo "'{\"id\": \"fake_id\", \"name\": \"Fake name\", \"version\": \"1.0.0\", \"actions\": [ ' \
'{
\"id\": \"action1\",
\"name\": \"Action 1\",
\"container\": \"bash\",
\"action\": \"test/action/test.sh\"
}' \
']}' > ${FAKE_DEFINITION_PATH}"
AfterRun "rm ${FAKE_DEFINITION_PATH}"

When run workflow::_load_workflow_definition "action1" "${FAKE_DEFINITION_PATH}"

The status should be success
The output should eq "{\"id\":\"action1\",\"name\":\"Action 1\",\"container\":\"bash\",\"action\":\"test/action/test.sh\"}"
The stderr should be present # for logs redirected into stderr
End

End

Describe "workflow::_load_step_values"

Include "./src/lib/tooling.sh"

It "returns step values from a workflow definition file"

FAKE_DEFINITION_PATH="config/fake_definition.json"

BeforeCall "tooling::set_jq"
step_definition="{\"id\":\"action1\",\"name\":\"Action 1\",\"container\":\"bash\",\"action\":\"test/action/test.sh\"}"

# shellcheck disable=SC2154
When call workflow::_load_step_values "${step_definition}"

The status should be success
The variable id should eq "action1"
The variable name should eq "Action 1"
The variable container should eq "bash"
The variable action should eq "test/action/test.sh"
The stderr should be present # for logs redirected into stderr
End

End

Describe "workflow::_iterate_over_workflow"

Include "./src/lib/tooling.sh"

It "returns a status success when all steps are executed"

FAKE_DEFINITION_PATH="config/fake_definition.json"

BeforeCall "tooling::set_jq"
BeforeCall "echo '{\"actions\": [ \
{\"id\": \"action1\", \"name\": \"Action 1\", \"container\": \"bash\", \"action\": \"test/action/test.sh\"}, \
{\"id\": \"action2\", \"name\": \"Action 2\", \"container\": \"maven\", \"action\": \"test/action/maven.sh\"} \
]}' > ${FAKE_DEFINITION_PATH}"
AfterCall "rm ${FAKE_DEFINITION_PATH}"

actions_id=("action1" "action2")

# shellcheck disable=SC2154
When call workflow::_iterate_over_workflow "${FAKE_DEFINITION_PATH}" "${actions_id[@]}"

The status should be success
The stderr should include "Loop over step action1"
The stderr should include "Loop over step action2"
The variable id should eq "action2"
The variable name should eq "Action 2"
The variable container should eq "maven"
The variable action should eq "test/action/maven.sh"
End

End

Describe "workflow::load"

Include "./src/lib/tooling.sh"

It "returns a status success when all steps are executed"

FAKE_DEFINITION_PATH="config/fake_definition.json"

BeforeCall "tooling::set_jq"
BeforeCall "echo '{\"actions\": [ \
{\"id\": \"action1\", \"name\": \"Action 1\", \"container\": \"bash\", \"action\": \"test/action/test.sh\"}, \
{\"id\": \"action2\", \"name\": \"Action 2\", \"container\": \"maven\", \"action\": \"test/action/maven.sh\"} \
]}' > ${FAKE_DEFINITION_PATH}"
AfterCall "rm ${FAKE_DEFINITION_PATH}"

# shellcheck disable=SC2154
When call workflow::load "${FAKE_DEFINITION_PATH}"

The status should be success
The stderr should include "Loop over step action1"
The stderr should include "Loop over step action2"
The variable id should eq "action2"
The variable name should eq "Action 2"
The variable container should eq "maven"
The variable action should eq "test/action/maven.sh"
End

End

End
10 changes: 4 additions & 6 deletions src/lib/project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@ set -euo pipefail
#@stdout path to the project configuration file (default: config/project.sh)
# shellcheck disable=SC2120
project::get_configuration_path() {
local path
local path="${1:-}"

log::info "Read project configuration"

if [ -z "${1:-}" ]; then
if [ -z "$path" ]; then
log::info "No project configuration file specified, use default"
path="${CONFIG_PATH}/project.sh"
else
path="$1"
path="${CONFIG_PATH}/workflow-default.json"
fi

if [ ! -f "$path" ]; then
log::fatal "Project configuration file does not exist: $path"
exit 255
exit 1
fi

echo "$path"
Expand Down
Loading

0 comments on commit 5af0e6b

Please sign in to comment.