mirror of
https://github.com/tonistiigi/xx
synced 2025-12-24 12:47:51 +08:00
util: add bats-assert helper
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
38
.github/workflows/bats-assert.yml
vendored
Normal file
38
.github/workflows/bats-assert.yml
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
name: bats-assert
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'master'
|
||||
paths:
|
||||
- '.github/workflows/bats-assert.yml'
|
||||
- 'util/bats-assert/**'
|
||||
pull_request:
|
||||
branches:
|
||||
- 'master'
|
||||
paths:
|
||||
- '.github/workflows/bats-assert.yml'
|
||||
- 'util/bats-assert/**'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: docker/setup-qemu-action@v1
|
||||
- uses: docker/setup-buildx-action@v1
|
||||
-
|
||||
name: Test
|
||||
working-directory: ./util/bats-assert
|
||||
run: docker buildx bake test
|
||||
-
|
||||
name: Login to DockerHub
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@v1.6.0
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
-
|
||||
name: Publish
|
||||
working-directory: ./util/bats-assert
|
||||
run: docker buildx bake all --push
|
||||
33
util/bats-assert/Dockerfile
Normal file
33
util/bats-assert/Dockerfile
Normal file
@@ -0,0 +1,33 @@
|
||||
FROM --platform=$BUILDPLATFORM alpine AS build
|
||||
RUN apk add --no-cache git
|
||||
WORKDIR /work
|
||||
RUN git clone --bare git://github.com/ztombol/bats-support && \
|
||||
mkdir -p /out/bats-support && cd /out/bats-support && \
|
||||
git --git-dir=/work/bats-support.git --work-tree=. checkout 004e707638eedd62e0481e8cdc9223ad471f12ee -- src load.bash LICENSE
|
||||
|
||||
RUN git clone --bare git://github.com/ztombol/bats-assert && \
|
||||
mkdir -p /out/bats-assert && cd /out/bats-assert && \
|
||||
git --git-dir=/work/bats-assert.git --work-tree=. checkout 9f88b4207da750093baabc4e3f41bf68f0dd3630 -- src load.bash LICENSE
|
||||
|
||||
RUN echo 'source "$(dirname "${BASH_SOURCE[0]}")/bats-support/load.bash"' > /out/assert.bash && \
|
||||
echo 'source "$(dirname "${BASH_SOURCE[0]}")/bats-assert/load.bash"' >> /out/assert.bash
|
||||
|
||||
|
||||
FROM scratch AS release
|
||||
COPY --from=build /out /
|
||||
|
||||
FROM alpine AS test-gen
|
||||
RUN apk add --no-cache bats
|
||||
WORKDIR /work
|
||||
COPY --from=release . .
|
||||
COPY test.bats .
|
||||
RUN bats ./test.bats &> test.bats.output || true
|
||||
|
||||
FROM test-gen AS test
|
||||
COPY test.bats.golden .
|
||||
RUN diff test.bats.output test.bats.golden
|
||||
|
||||
FROM scratch AS golden
|
||||
COPY --from=test-gen /work/test.bats.output test.bats.golden
|
||||
|
||||
FROM release
|
||||
35
util/bats-assert/docker-bake.hcl
Normal file
35
util/bats-assert/docker-bake.hcl
Normal file
@@ -0,0 +1,35 @@
|
||||
variable "TARGET_REPO" {
|
||||
default = "tonistiigi/bats-assert"
|
||||
}
|
||||
|
||||
target "default" {
|
||||
tags = ["${TARGET_REPO}"]
|
||||
cache-to = ["type=inline"]
|
||||
cache-from = ["${TARGET_REPO}"]
|
||||
}
|
||||
|
||||
target "all" {
|
||||
inherits = ["default"]
|
||||
platforms = [
|
||||
"linux/amd64",
|
||||
"linux/arm64",
|
||||
"linux/arm/v7",
|
||||
"linux/arm/v6",
|
||||
"linux/arm/v5",
|
||||
"linux/386",
|
||||
"linux/riscv64",
|
||||
"linux/s390x",
|
||||
"linux/ppc64le"
|
||||
]
|
||||
}
|
||||
|
||||
target "test" {
|
||||
target = "test"
|
||||
}
|
||||
|
||||
target "generate-golden" {
|
||||
target = "golden"
|
||||
output = [
|
||||
"."
|
||||
]
|
||||
}
|
||||
29
util/bats-assert/test.bats
Executable file
29
util/bats-assert/test.bats
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load 'assert'
|
||||
|
||||
@test "failing" {
|
||||
assert_equal "foo" "bar"
|
||||
}
|
||||
|
||||
@test "run-no-success" {
|
||||
run echo "start" && false
|
||||
assert_failure
|
||||
}
|
||||
|
||||
@test "run foobar" {
|
||||
run ./foobar
|
||||
assert_failure
|
||||
}
|
||||
|
||||
@test "run" {
|
||||
run echo "abc"
|
||||
assert_success
|
||||
assert_output "abc"
|
||||
}
|
||||
|
||||
@test "run-fail" {
|
||||
run echo "abc"
|
||||
assert_success
|
||||
assert_output "bcd"
|
||||
}
|
||||
26
util/bats-assert/test.bats.golden
Normal file
26
util/bats-assert/test.bats.golden
Normal file
@@ -0,0 +1,26 @@
|
||||
1..5
|
||||
not ok 1 failing
|
||||
# (from function `assert_equal' in file bats-assert/src/assert.bash, line 91,
|
||||
# in test file test.bats, line 6)
|
||||
# `assert_equal "foo" "bar"' failed
|
||||
#
|
||||
# -- values do not equal --
|
||||
# expected : bar
|
||||
# actual : foo
|
||||
# --
|
||||
#
|
||||
not ok 2 run-no-success
|
||||
# (in test file test.bats, line 10)
|
||||
# `run echo "start" && false' failed
|
||||
ok 3 run foobar
|
||||
ok 4 run
|
||||
not ok 5 run-fail
|
||||
# (from function `assert_output' in file bats-assert/src/assert.bash, line 239,
|
||||
# in test file test.bats, line 28)
|
||||
# `assert_output "bcd"' failed
|
||||
#
|
||||
# -- output differs --
|
||||
# expected : bcd
|
||||
# actual : abc
|
||||
# --
|
||||
#
|
||||
Reference in New Issue
Block a user