Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Langevin committed May 15, 2020
1 parent bd31a8e commit 8d54ecf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/get-tags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function getTags() {
RETRY_COUNT=${BUILDKITE_RETRY_COUNT:-0}
ADDITIONAL_TAGS=$(readAdditionalTags)

RESULT="is_master:${IS_MASTER},pipeline_slug:${PIPELINE_SLUG},step_command:${BK_COMMAND},step_label:${BK_LABEL},retry_count:${RETRY_COUNT},agent_queue=${BK_AGENT_QUEUE}"
RESULT="is_master:${IS_MASTER},pipeline_slug:${PIPELINE_SLUG},step_command:${BK_COMMAND},step_label:${BK_LABEL},retry_count:${RETRY_COUNT},agent_queue:${BK_AGENT_QUEUE}"

if [ -n "$ADDITIONAL_TAGS" ]; then
RESULT+=",${ADDITIONAL_TAGS}"
Expand Down
4 changes: 3 additions & 1 deletion tests/post-checkout.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ load "$BATS_PATH/load.bash"
export BUILDKITE_PIPELINE_SLUG=monorepo
export BUILDKITE_COMMAND="cd somewhere && make do-something"
export BUILDKITE_LABEL=":shipit: deploy-prod"
export BUILDKITE_AGENT_META_DATA_QUEUE="default"

run "$PWD/hooks/post-checkout"

assert_success
assert_output --partial "Reporting buildkite.steps.checkout.duration with value=90"
assert_output --partial "tags=is_master:true,pipeline_slug:monorepo,step_command:cd somewhere && make do-something,step_label::shipit: deploy-prod,retry_count:0"
assert_output --partial "tags=is_master:true,pipeline_slug:monorepo,step_command:cd somewhere && make do-something,step_label::shipit: deploy-prod,retry_count:0,agent_queue:default"

unset BUILDKITE_PLUGIN_DATADOG_STATS_COMMAND_START_TIME_MS
unset BUILDKITE_BRANCH
unset BUILDKITE_PIPELINE_SLUG
unset BUILDKITE_COMMAND
unset BUILDKITE_LABEL
unset BUILDKITE_AGENT_META_DATA_QUEUE
}
8 changes: 7 additions & 1 deletion tests/post-command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ load "$BATS_PATH/load.bash"
export BUILDKITE_PIPELINE_SLUG=monorepo
export BUILDKITE_COMMAND="cd somewhere && make do-something"
export BUILDKITE_LABEL=":shipit: deploy-prod"
export BUILDKITE_AGENT_META_DATA_QUEUE="default"

run "$PWD/hooks/post-command"

Expand All @@ -21,6 +22,7 @@ load "$BATS_PATH/load.bash"
unset BUILDKITE_PIPELINE_SLUG
unset BUILDKITE_COMMAND
unset BUILDKITE_LABEL
unset BUILDKITE_AGENT_META_DATA_QUEUE
}

@test "Sets the correct tags and runtime for a non-master branch" {
Expand All @@ -30,6 +32,7 @@ load "$BATS_PATH/load.bash"
export BUILDKITE_PIPELINE_SLUG=monorepo
export BUILDKITE_COMMAND="cd somewhere && make do-something"
export BUILDKITE_LABEL=":shipit: deploy-prod"
export BUILDKITE_AGENT_META_DATA_QUEUE="default"

run "$PWD/hooks/post-command"

Expand All @@ -42,6 +45,7 @@ load "$BATS_PATH/load.bash"
unset BUILDKITE_PIPELINE_SLUG
unset BUILDKITE_COMMAND
unset BUILDKITE_LABEL
unset BUILDKITE_AGENT_META_DATA_QUEUE
}

@test "It supports specifying additional tags by value and env var" {
Expand All @@ -56,12 +60,13 @@ load "$BATS_PATH/load.bash"
export MY_ENV_VAR="my-tag-value"
export BUILDKITE_PLUGIN_DATADOG_STATS_ADDITIONAL_TAGS_1_TAG="my-other-tag"
export BUILDKITE_PLUGIN_DATADOG_STATS_ADDITIONAL_TAGS_1_VALUE="my-other-tag-value"
export BUILDKITE_AGENT_META_DATA_QUEUE="default"

run "$PWD/hooks/post-command"

assert_success
assert_output --partial "Reporting buildkite.steps.command.duration with value=90"
assert_output --partial "tags=is_master:false,pipeline_slug:monorepo,step_command:cd somewhere && make do-something,step_label::shipit: deploy-prod,retry_count:0,my-tag:my-tag-value,my-other-tag:my-other-tag-value"
assert_output --partial "tags=is_master:false,pipeline_slug:monorepo,step_command:cd somewhere && make do-something,step_label::shipit: deploy-prod,retry_count:0,agent_queue:default,my-tag:my-tag-value,my-other-tag:my-other-tag-value"

unset BUILDKITE_PLUGIN_DATADOG_STATS_COMMAND_START_TIME_MS
unset BUILDKITE_BRANCH
Expand All @@ -73,4 +78,5 @@ load "$BATS_PATH/load.bash"
unset MY_ENV_VAR
unset BUILDKITE_PLUGIN_DATADOG_STATS_ADDITIONAL_TAGS_1_TAG
unset BUILDKITE_PLUGIN_DATADOG_STATS_ADDITIONAL_TAGS_1_VALUE
unset BUILDKITE_AGENT_META_DATA_QUEUE
}
2 changes: 2 additions & 0 deletions tests/pre-exit.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ load "$BATS_PATH/load.bash"
export BUILDKITE_PIPELINE_SLUG=monorepo
export BUILDKITE_COMMAND="cd somewhere && make do-something"
export BUILDKITE_LABEL=":shipit: deploy-prod"
export BUILDKITE_AGENT_META_DATA_QUEUE="default"

run "$PWD/hooks/pre-exit"

Expand All @@ -21,4 +22,5 @@ load "$BATS_PATH/load.bash"
unset BUILDKITE_PIPELINE_SLUG
unset BUILDKITE_COMMAND
unset BUILDKITE_LABEL
unset BUILDKITE_AGENT_META_DATA_QUEUE
}

0 comments on commit 8d54ecf

Please sign in to comment.