Skip to content

Commit 9b9a85d

Browse files
committed
feat: add integration tests
1 parent 849557e commit 9b9a85d

6 files changed

Lines changed: 171 additions & 0 deletions

File tree

.dockerignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Include any files or directories that you don't want to be copied to your
2+
# container here (e.g., local build artifacts, temporary files, etc.).
3+
#
4+
# For more help, visit the .dockerignore file reference guide at
5+
# https://docs.docker.com/go/build-context-dockerignore/
6+
7+
**/.DS_Store
8+
**/.classpath
9+
**/.dockerignore
10+
**/.env*
11+
**/.git
12+
**/.github
13+
**/.gitignore
14+
**/.project
15+
**/.settings
16+
**/.toolstarget
17+
**/.vs
18+
**/.vscode
19+
**/*.*proj.user
20+
**/*.dbmdl
21+
**/*.jfm
22+
**/bin
23+
**/charts
24+
**/docker-compose*
25+
**/*Dockerfile
26+
**/docs
27+
LICENSE
28+
README.md
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
name: Integration Test
3+
"on":
4+
workflow_dispatch:
5+
pull_request:
6+
branches:
7+
- main
8+
paths:
9+
- "integration/**"
10+
- "**/*.go"
11+
push:
12+
branches:
13+
- main
14+
15+
permissions:
16+
id-token: write
17+
contents: read
18+
19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.ref }}
21+
cancel-in-progress: true
22+
23+
jobs:
24+
integration-test:
25+
name: Run integration tests
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
31+
- name: Install Just
32+
uses: ./.github/actions/setup-workspace
33+
34+
- name: Set up Docker Buildx
35+
uses: docker/setup-buildx-action@v3
36+
37+
- name: Run integration tests
38+
working-directory: ./integration
39+
run: |
40+
just build
41+
just test-all

integration/Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# ========== CLI BUILD STAGE ==========
2+
ARG GO_VERSION=1.25
3+
FROM golang:${GO_VERSION}-alpine AS build
4+
5+
WORKDIR /src
6+
RUN --mount=type=cache,target=/go/pkg/mod/ \
7+
--mount=type=bind,source=go.mod,target=go.mod \
8+
go mod download -x
9+
COPY . .
10+
RUN --mount=type=cache,target=/go/pkg/mod/ \
11+
CGO_ENABLED=0 go build -o /bin/hackstack .
12+
13+
# ========== CLI RUN STAGE ==========
14+
FROM ubuntu:22.04 AS app
15+
16+
ENV DEBIAN_FRONTEND=noninteractive
17+
RUN apt-get update && \
18+
apt-get install -y --no-install-recommends curl ca-certificates xz-utils && \
19+
rm -rf /var/lib/apt/lists/*
20+
21+
COPY --from=build /bin/hackstack /bin/hackstack
22+
23+
# Tests should use non-root to simulate a real user.
24+
ARG USERNAME=testuser
25+
ARG USER_ID=1000
26+
ARG GROUP_ID=1000
27+
RUN addgroup --gid $GROUP_ID ${USERNAME} && \
28+
adduser --disabled-password --gecos '' --uid ${USER_ID} --gid ${GROUP_ID} ${USERNAME}
29+
30+
USER $USERNAME
31+
ENV HOME=/home/${USERNAME}
32+
WORKDIR ${HOME}/projects
33+
34+
ENTRYPOINT [ "/bin/hackstack" ]
35+
CMD ["--help"]

integration/docker-compose.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Integration test Docker suite
2+
services:
3+
hackstack:
4+
container_name: hackstack
5+
image: hackstack:latest
6+
build:
7+
context: ..
8+
dockerfile: integration/Dockerfile

integration/justfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# INTEGRATION TEST SCRIPTS
2+
3+
CAPTURE_OUTPUT_FILE := "output.txt"
4+
5+
# Default target to list available commands
6+
_default:
7+
@just --list --unsorted
8+
9+
##########################################################
10+
# TEST WORKSPACE SETUP
11+
##########################################################
12+
13+
# Build the services in Docker
14+
build:
15+
docker compose build
16+
17+
# Workspace teardown
18+
clean:
19+
-docker compose down
20+
-rm {{ CAPTURE_OUTPUT_FILE }}
21+
22+
##########################################################
23+
# INTERACTIVE COMMANDS
24+
##########################################################
25+
26+
# Run the CLI image with envs
27+
hackstack *args:
28+
@docker compose run \
29+
--remove-orphans --rm \
30+
hackstack {{ args }}
31+
32+
##########################################################
33+
# TEST EXECUTION
34+
##########################################################
35+
36+
# Run the full test suite
37+
test-all: test-base
38+
@echo "hackstack CLI integration test completed!"
39+
40+
test-base:
41+
@just hackstack --version | grep -n "hackstack"
42+
@just hackstack --help 2>&1 | grep -n "hackstack"

integration/sample.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: devops-common
2+
description: DevOps CLI - Simplifying your CI/CD pipelines
3+
version: 0.0.2
4+
repo_url: https://github.com/jgfranco17/devops
5+
6+
codebase:
7+
language: bash
8+
test:
9+
fail_fast: true
10+
steps:
11+
- echo "Tests completed successfully"
12+
build:
13+
fail_fast: true
14+
env:
15+
FOO: BAR
16+
steps:
17+
- echo "Build completed successfully with $FOO"

0 commit comments

Comments
 (0)