Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kickstart a CLI test suite #4

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ jobs:
- run: docker build --tag registry . --progress plain
- run: docker compose build
- run: docker compose up --detach --wait
- run: make test PRESET=Release
- run: make test-e2e PRESET=Release
- run: docker compose down
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ COPY schemas /source/schemas
COPY vendor /source/vendor
COPY CMakeLists.txt /source/CMakeLists.txt

# For testing
COPY Makefile /source/Makefile
COPY test/cli /source/test/cli

RUN cmake -S /source -B ./build \
-DCMAKE_BUILD_TYPE:STRING=Release \
-DREGISTRY_INDEX:BOOL=ON \
Expand All @@ -19,6 +23,8 @@ RUN cmake --build /build --config Release --parallel 2
RUN cmake --install ./build --prefix /usr --verbose \
--config Release --component sourcemeta_registry

RUN make -C /source test PREFIX=/usr

FROM debian:bookworm-slim
RUN apt-get --yes update && apt-get install --yes --no-install-recommends \
ca-certificates && apt-get clean && rm -rf /var/lib/apt/lists/*
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ lint:

.PHONY: test
test:
./test/cli/index/no-options.sh $(PREFIX)/bin/sourcemeta-registry-index

.PHONY: test-e2e
test-e2e:
$(HURL) --test \
--variable base=$(shell jq --raw-output '.url' < $(SANDBOX)/configuration.json) \
test/e2e/*.hurl
Expand Down
20 changes: 20 additions & 0 deletions test/cli/index/no-options.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

set -o errexit
set -o nounset

TMP="$(mktemp -d)"
clean() { rm -rf "$TMP"; }
trap clean EXIT

"$1" > "$TMP/output.txt" && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1

VERSION="$(grep '^project' < CMakeLists.txt | head -n 1 | cut -d ' ' -f 3)"

cat << EOF > "$TMP/expected.txt"
Sourcemeta Registry v$VERSION
Usage: sourcemeta-registry-index <configuration.json> <path/to/output/directory>
EOF

diff "$TMP/output.txt" "$TMP/expected.txt"