mirror of
https://github.com/rlespinasse/github-slug-action.git
synced 2026-06-11 17:13:04 +00:00
tests: improve tests on slug_ref function
This commit is contained in:
committed by
Romain Lespinasse
parent
11ea6379cd
commit
d89dc9cf15
2
.github/actions/bats/entrypoint.sh
vendored
2
.github/actions/bats/entrypoint.sh
vendored
@@ -1,3 +1,3 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
/sbin/bats ./
|
/sbin/bats ./tests
|
||||||
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -1,6 +1,6 @@
|
|||||||
name: ci
|
name: ci
|
||||||
|
|
||||||
on: [push, pull_request]
|
on: push
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|||||||
6
Makefile
6
Makefile
@@ -1,9 +1,7 @@
|
|||||||
|
.PHONY: help tests
|
||||||
|
|
||||||
|
|
||||||
help: ## print this message
|
help: ## print this message
|
||||||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-10s\033[0m %s\n", $$1, $$2}'
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-10s\033[0m %s\n", $$1, $$2}'
|
||||||
|
|
||||||
.PHONY: tests
|
|
||||||
tests: ## Run tests locally
|
tests: ## Run tests locally
|
||||||
docker run -w /workdir -v $(shell pwd):/workdir dduportal/bats:latest ./
|
docker run -w /workdir -v $(shell pwd):/workdir dduportal/bats:latest ./tests
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
#!/usr/bin/env bats
|
|
||||||
|
|
||||||
@test "slug_ref" {
|
|
||||||
source entrypoint.sh
|
|
||||||
|
|
||||||
i=0
|
|
||||||
j=0
|
|
||||||
|
|
||||||
given[++i]="refs/head/master"
|
|
||||||
expected[++j]="master"
|
|
||||||
|
|
||||||
given[++i]="refs/head/feat/newFeature"
|
|
||||||
expected[++j]="newfeature"
|
|
||||||
|
|
||||||
given[++i]="refs/tags/v1.0"
|
|
||||||
expected[++j]="v1-0"
|
|
||||||
|
|
||||||
given[++i]="refs/head/awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters"
|
|
||||||
expected[++j]="awesome-feature-very-very-very-very-very-very-very-long-moretha"
|
|
||||||
|
|
||||||
for i in "${!given[@]}"
|
|
||||||
do
|
|
||||||
actual="$(slug_ref \"${given[i]}\")"
|
|
||||||
echo "expected : [${expected[i]}], actual : [${actual}]"
|
|
||||||
[ "$actual" == "${expected[i]}" ]
|
|
||||||
done
|
|
||||||
}
|
|
||||||
55
tests/slug_ref.bats
Normal file
55
tests/slug_ref.bats
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
@test "Slug master branch" {
|
||||||
|
test_sluf_ref \
|
||||||
|
"refs/heads/master" \
|
||||||
|
"master"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "Slug a feature branch" {
|
||||||
|
test_sluf_ref \
|
||||||
|
"refs/heads/feat/new_feature" \
|
||||||
|
"new-feature"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "Slug a fix branch" {
|
||||||
|
test_sluf_ref \
|
||||||
|
"refs/heads/fix/issue_number" \
|
||||||
|
"issue-number"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "Slug a simple tag" {
|
||||||
|
test_sluf_ref \
|
||||||
|
"refs/tags/v1.0.0" \
|
||||||
|
"v1-0-0"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "Slug a complex tag" {
|
||||||
|
test_sluf_ref \
|
||||||
|
"refs/tags/product@1.0.0-rc.2" \
|
||||||
|
"product-1-0-0-rc-2"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "Slug a reference with upper case letters" {
|
||||||
|
test_sluf_ref \
|
||||||
|
"refs/heads/New_Awesome_Product" \
|
||||||
|
"new-awesome-product"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "Slug a very long name" {
|
||||||
|
test_sluf_ref \
|
||||||
|
"refs/heads/an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters" \
|
||||||
|
"an-awesome-feature-very-very-very-very-very-very-very-long-more"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Load sluf_ref function
|
||||||
|
source entrypoint.sh > /dev/null 2>&1
|
||||||
|
|
||||||
|
test_sluf_ref() {
|
||||||
|
given="${1}"
|
||||||
|
expected="${2}"
|
||||||
|
|
||||||
|
actual="$(slug_ref \"${given}\")"
|
||||||
|
echo "expected : [${expected}], actual : [${actual}]"
|
||||||
|
[ "${actual}" == "${expected}" ]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user