test(slug): test 'slug_ref' function

This commit is contained in:
Antoine Méausoone
2019-11-06 16:42:22 +01:00
committed by Romain Lespinasse
parent e461860662
commit 11ea6379cd
6 changed files with 62 additions and 1 deletions

5
.github/actions/bats/Dockerfile vendored Normal file
View File

@@ -0,0 +1,5 @@
FROM dduportal/bats:latest
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

3
.github/actions/bats/entrypoint.sh vendored Executable file
View File

@@ -0,0 +1,3 @@
#!/usr/bin/env sh
/sbin/bats ./

17
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,17 @@
name: ci
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v1
- name: Tests
uses: ./.github/actions/bats

9
Makefile Normal file
View File

@@ -0,0 +1,9 @@
help: ## print this message
@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
docker run -w /workdir -v $(shell pwd):/workdir dduportal/bats:latest ./

View File

@@ -26,4 +26,4 @@ This action slug and expose some github variables.
echo ${{ env.GITHUB_REF_SLUG }}
echo ${{ env.GITHUB_HEAD_REF_SLUG }}
echo ${{ env.GITHUB_BASE_REF_SLUG }}
```
```

27
entrypoint-test.bats Normal file
View File

@@ -0,0 +1,27 @@
#!/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
}