Skip to content

Commit

Permalink
Added tests and fixed shellcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
marcingrzejszczak committed Jun 8, 2018
1 parent 3ffea59 commit e513ecb
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 2 deletions.
2 changes: 1 addition & 1 deletion common/src/main/bash/pipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function findLatestProdTag() {
local latestProdTag
latestProdTag="$(latestProdTagFromGit)"
export LATEST_PROD_TAG PASSED_LATEST_PROD_TAG
LATEST_PROD_TAG="$(trimRefsTag ${latestProdTag})"
LATEST_PROD_TAG="$(trimRefsTag "${latestProdTag}")"
PASSED_LATEST_PROD_TAG="${LATEST_PROD_TAG}"
echo "${LATEST_PROD_TAG}"
fi
Expand Down
87 changes: 87 additions & 0 deletions common/src/test/bats/pipeline.bats
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,93 @@ teardown() {
assert_success
}

@test "should not set PROJECT_NAME to 'null' for SINGLE_REPO project setup and PROJECT_NAME initially set to 'null'" {
cd "${TEMP_DIR}/generic/single_repo_no_descriptor"
export PROJECT_NAME="null"

# to get the output
run "${SOURCE_DIR}/pipeline.sh"
# to get the env vars
source "${SOURCE_DIR}/pipeline.sh"

assert_equal "${PROJECT_SETUP}" "SINGLE_REPO"
assert_equal "${PROJECT_NAME}" "retrieveAppName"
assert_success
}

@test "should not set PROJECT_NAME to 'null' when PROJECT_NAME initially set to 'null' for SINGLE_REPO PROJECT_SETUP for a repo with descriptor without coordinates" {
cd "${TEMP_DIR}/generic/single_repo"
export PROJECT_NAME="null"

# to get the output
run "${SOURCE_DIR}/pipeline.sh"
# to get the env vars
source "${SOURCE_DIR}/pipeline.sh"

assert_equal "${PROJECT_SETUP}" "SINGLE_REPO"
assert_equal "${PROJECT_NAME}" "retrieveAppName"
assert_success
}

@test "should not set PROJECT_NAME to 'null' when PROJECT_NAME initially set to 'null' for MULTI_MODULE PROJECT_SETUP for a repo with descriptor with coordinates" {
cd "${TEMP_DIR}/generic/multi_module"
export PROJECT_NAME="null"

# to get the output
run "${SOURCE_DIR}/pipeline.sh"
# to get the env vars
source "${SOURCE_DIR}/pipeline.sh"

assert_equal "${PROJECT_SETUP}" "MULTI_MODULE"
assert_equal "${PROJECT_NAME}" "retrieveAppName"
assert_success
}

@test "should not set PROJECT_NAME to 'null' when PROJECT_NAME initially set to 'null' for MULTI_PROJECT PROJECT_SETUP for a repo with no descriptor at root but with ROOT_PROJECT_DIR existent with no descriptor" {
cd "${TEMP_DIR}/generic/multi_project"
export ROOT_PROJECT_DIR="foo"
export PROJECT_NAME="null"

# to get the output
run "${SOURCE_DIR}/pipeline.sh"
# to get the env vars
source "${SOURCE_DIR}/pipeline.sh"

assert_equal "${PROJECT_SETUP}" "MULTI_PROJECT"
assert_equal "${PROJECT_NAME}" "retrieveAppName"
assert_success
}

@test "should not set PROJECT_NAME to 'null' when PROJECT_NAME initially set to 'null' for MULTI_PROJECT PROJECT_SETUP for a repo with no descriptor at root but with ROOT_PROJECT_DIR existent with descriptor with no build coordinates" {
cd "${TEMP_DIR}/generic/multi_project"
export ROOT_PROJECT_DIR="bar"
export PROJECT_NAME="null"

# to get the output
run "${SOURCE_DIR}/pipeline.sh"
# to get the env vars
source "${SOURCE_DIR}/pipeline.sh"

assert_equal "${PROJECT_SETUP}" "MULTI_PROJECT"
assert_equal "${PROJECT_NAME}" "retrieveAppName"
assert_success
}

@test "should not set PROJECT_NAME to 'null' when PROJECT_NAME initially set to 'null' for MULTI_PROJECT_WITH_MODULES PROJECT_SETUP for a repo with no descriptor at root but with ROOT_PROJECT_DIR existent with descriptor with build coordinates" {
cd "${TEMP_DIR}/generic/multi_project_with_modules"
export ROOT_PROJECT_DIR="foo"
export PROJECT_NAME="null"

# to get the output
run "${SOURCE_DIR}/pipeline.sh"
# to get the env vars
source "${SOURCE_DIR}/pipeline.sh"

assert_equal "${PROJECT_SETUP}" "MULTI_PROJECT_WITH_MODULES"
assert_equal "${PROJECT_NAME}" "retrieveAppName"
assert_success
}

@test "should find the latest tag from git project for existant project name" {
cd "${TEMP_DIR}/generic/git_project"
mv git .git
Expand Down
2 changes: 1 addition & 1 deletion concourse/tasks/build-api-compatibility-check/task.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cd "${ROOT_FOLDER}/${REPO_RESOURCE}" || exit
# Find latest prod tag
latestProdTag="$(latestProdTagFromGit)"
export LATEST_PROD_TAG
LATEST_PROD_TAG="$(trimRefsTag ${latestProdTag})"
LATEST_PROD_TAG="$(trimRefsTag "${latestProdTag}")"
echo "Latest prod tag is [${LATEST_PROD_TAG}]"

export PASSED_LATEST_PROD_TAG
Expand Down

0 comments on commit e513ecb

Please sign in to comment.