-
Notifications
You must be signed in to change notification settings - Fork 0
Feat: implement mock server for thunderstorm #1
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
Open
gremat
wants to merge
4
commits into
master
Choose a base branch
from
feat/implement-mock-server-for-thunderstorm
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main, master] | ||
| tags: | ||
| - 'v*.*.*' | ||
| pull_request: | ||
| branches: [main, master] | ||
|
|
||
| jobs: | ||
| format: | ||
| name: Check Formatting | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: '1.24' | ||
|
|
||
| - name: Check gofmt | ||
| run: | | ||
| unformatted=$(gofmt -l .) | ||
| if [ -n "$unformatted" ]; then | ||
| echo "The following files are not formatted correctly:" | ||
| echo "$unformatted" | ||
| echo "" | ||
| echo "Run 'gofmt -w .' to fix formatting" | ||
| exit 1 | ||
| fi | ||
| echo "All files are properly formatted" | ||
|
|
||
| lint: | ||
| name: Lint | ||
| runs-on: ubuntu-latest | ||
| needs: format | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: '1.24' | ||
|
|
||
| - name: Run golangci-lint | ||
| uses: golangci/golangci-lint-action@v6 | ||
| with: | ||
| version: latest | ||
|
|
||
| test: | ||
| name: Test | ||
| runs-on: ubuntu-latest | ||
| needs: lint | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: '1.24' | ||
|
|
||
| - name: Download dependencies | ||
| run: go mod download | ||
|
|
||
| - name: Run unit tests | ||
| run: go test -v -count=1 ./go/... | ||
|
|
||
| - name: Run integration tests | ||
| run: go test -tags=integration -v -count=1 | ||
|
|
||
| build: | ||
| name: Build | ||
| runs-on: ubuntu-latest | ||
| needs: test | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 # Needed for git describe | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: '1.24' | ||
|
|
||
| - name: Download dependencies | ||
| run: go mod download | ||
|
|
||
| - name: Get version from git | ||
| id: version | ||
| run: | | ||
| VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "v0.0.0-dev") | ||
| echo "version=$VERSION" >> $GITHUB_OUTPUT | ||
| echo "Building version: $VERSION" | ||
|
|
||
| - name: Build binary with version | ||
| run: | | ||
| go build -ldflags "-X main.Version=${{ steps.version.outputs.version }}" -o thunderstorm-mock . | ||
|
|
||
| - name: Verify version in binary | ||
| run: | | ||
| ./thunderstorm-mock --version | ||
| BINARY_VERSION=$(./thunderstorm-mock --version) | ||
| echo "Binary reports version: $BINARY_VERSION" | ||
| if [ "$BINARY_VERSION" != "${{ steps.version.outputs.version }}" ]; then | ||
| echo "ERROR: Binary version mismatch!" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Upload artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: thunderstorm-mock | ||
| path: thunderstorm-mock | ||
| retention-days: 7 | ||
|
|
||
| release: | ||
| name: Release | ||
| runs-on: ubuntu-latest | ||
| needs: build | ||
| # Quick minimal test, proper one follows | ||
| if: startsWith(github.ref, 'refs/tags/v') | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: '1.24' | ||
|
|
||
| - name: Verify tag version | ||
| id: tag | ||
| run: | | ||
| TAG="${GITHUB_REF#refs/tags/}" | ||
| if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
| echo "" | ||
| echo "ERROR: Tag pattern mismatch!" | ||
| echo "Tag $TAG does not match the required format v[0-9]+.[0-9]+.[0-9]+" | ||
| echo "" | ||
| exit 1 | ||
| fi | ||
| echo "tag=$TAG" >> $GITHUB_OUTPUT | ||
| echo "Release tag: $TAG" | ||
|
|
||
| - name: Validate version constant matches tag | ||
| run: | | ||
| TAG="${{ steps.tag.outputs.tag }}" | ||
| # Extract the Version constant from main.go | ||
| CODE_VERSION=$(grep -E '^var Version = ".*"$' main.go | sed 's/.*"\(.*\)".*/\1/') | ||
| echo "Tag version: $TAG" | ||
| echo "Code version constant: $CODE_VERSION" | ||
| if [ "$CODE_VERSION" != "$TAG" ]; then | ||
| echo "" | ||
| echo "ERROR: Version mismatch!" | ||
| echo "The Version constant in main.go ($CODE_VERSION) does not match the git tag ($TAG)." | ||
| echo "" | ||
| echo "Please update the Version constant in main.go to match the release tag:" | ||
| echo " var Version = \"$TAG\"" | ||
| echo "" | ||
| exit 1 | ||
| fi | ||
| echo "Version constant matches tag - OK" | ||
|
|
||
| - name: Download artifact | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: thunderstorm-mock | ||
|
|
||
| - name: Make binary executable | ||
| run: chmod +x thunderstorm-mock | ||
|
|
||
| - name: Verify binary version matches tag | ||
| run: | | ||
| BINARY_VERSION=$(./thunderstorm-mock --version) | ||
| TAG="${{ steps.tag.outputs.tag }}" | ||
| echo "Binary version: $BINARY_VERSION" | ||
| echo "Tag version: $TAG" | ||
| if [ "$BINARY_VERSION" != "$TAG" ]; then | ||
| echo "ERROR: Binary version does not match tag!" | ||
| exit 1 | ||
| fi | ||
| echo "Binary version matches tag - OK" | ||
|
|
||
| - name: Rename binary with version | ||
| run: | | ||
| TAG="${{ steps.tag.outputs.tag }}" | ||
| mv thunderstorm-mock "thunderstorm-mock-${TAG}" | ||
| - name: Create Release | ||
| uses: softprops/action-gh-release@v2 | ||
| with: | ||
| files: thunderstorm-mock-${{ steps.tag.outputs.tag }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /.openapi-generator/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # OpenAPI Generator Ignore | ||
| # Generated by openapi-generator https://github.com/openapitools/openapi-generator | ||
|
|
||
| # Use this file to prevent files from being overwritten by the generator. | ||
| # The patterns follow closely to .gitignore or .dockerignore. | ||
|
|
||
| # As an example, the C# client generator defines ApiClient.cs. | ||
| # You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: | ||
| #ApiClient.cs | ||
|
|
||
| # You can match any string of characters against a directory, file or extension with a single asterisk (*): | ||
| #foo/*/qux | ||
| # The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux | ||
|
|
||
| # You can recursively match patterns against a directory, file or extension with a double asterisk (**): | ||
| #foo/**/qux | ||
| # This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux | ||
|
|
||
| # You can also negate patterns with an exclamation (!). | ||
| # For example, you can ignore all files in a docs folder with the file extension .md: | ||
| #docs/*.md | ||
| # Then explicitly reverse the ignore rule for a single file: | ||
| #!docs/README.md | ||
|
|
||
| # Files expected to be customized after first generation and then fixed: | ||
| # (i.e., you probably want to keep these ignores permanently, or only disable | ||
| # temporarily on massive API changes or huge version bumps of the generator.) | ||
| /README.md | ||
| go/*_service.go | ||
|
|
||
| # Files that normally shouldn't be changed, but we need changes there: | ||
| # (i.e., you might want to disable these ignores temporarily to check for | ||
| # updates in the generation code when regenerating.) | ||
| go/model_thor_finding.go | ||
| go/model_thor_report.go | ||
| go/model_timestamp_map.go | ||
| go/logger.go | ||
| main.go | ||
| go.mod |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| FROM golang:1.19 AS build | ||
| WORKDIR /go/src | ||
| COPY go ./go | ||
| COPY main.go . | ||
| COPY go.sum . | ||
| COPY go.mod . | ||
|
|
||
| ENV CGO_ENABLED=0 | ||
|
|
||
| RUN go build -o thunderstormmock . | ||
|
|
||
| FROM scratch AS runtime | ||
| COPY --from=build /go/src/thunderstormmock ./ | ||
| EXPOSE 8080/tcp | ||
| ENTRYPOINT ["./thunderstormmock"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,80 @@ | ||
| # Thunderstorm Mock Server | ||
|
|
||
| The server implements a mock version of the Thunderstorm API that can be used for testing purposes. All requests do nothing but log to the console. | ||
| The server implements a mock version of the Thunderstorm API that can be used for testing purposes. All requests do nothing but logging. | ||
gremat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Download | ||
|
|
||
| Download the latest release from the [Releases page](https://github.com/NextronSystems/thunderstorm-mock/releases). | ||
|
|
||
| ## Usage | ||
|
|
||
| ```bash | ||
| ./thunderstorm-mock [options] | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| | Flag | Environment Variable | Default | Description | | ||
| |------|---------------------|---------|-------------| | ||
| | `-p, --port` | `THUNDERSTORM_MOCK_PORT` | `8080` | Port to listen on | | ||
| | `-a, --address` | `THUNDERSTORM_MOCK_ADDRESS` | (all interfaces) | Address to bind to | | ||
| | `-o, --output` | `THUNDERSTORM_MOCK_OUTPUT` | (stdout) | Log output file path | | ||
| | `-v, --version` | | | Print version and exit | | ||
| | `-h, --help` | | | Print help and exit | | ||
|
|
||
| CLI flags take precedence over environment variables. | ||
|
|
||
| ### Examples | ||
|
|
||
| ```bash | ||
| # Start server on default port 8080 | ||
| ./thunderstorm-mock | ||
|
|
||
| # Start server on port 9000 | ||
| ./thunderstorm-mock --port 9000 | ||
|
|
||
| # Bind to localhost only and log to file | ||
| ./thunderstorm-mock --address 127.0.0.1 --output server.log | ||
|
|
||
| # Using environment variables | ||
| THUNDERSTORM_MOCK_PORT=9000 ./thunderstorm-mock | ||
| ``` | ||
|
|
||
| The server will be available at `http://localhost:8080` (or your configured port). | ||
|
|
||
| --- | ||
|
|
||
| ## Development | ||
|
|
||
| ### Running from Source | ||
|
|
||
| ```bash | ||
| go run main.go | ||
| ``` | ||
|
|
||
| ### Running with Docker | ||
|
|
||
| Build the image: | ||
| ```bash | ||
| docker build --network=host -t thunderstormmock . | ||
| ``` | ||
|
|
||
| Run the container: | ||
| ```bash | ||
| docker run --rm -it thunderstormmock | ||
| ``` | ||
|
|
||
| ### Code Generation | ||
|
|
||
| This server was generated by the [openapi-generator](https://openapi-generator.tech) project using the | ||
| [Thunderstorm OpenAPI specification](https://github.com/NextronSystems/thunderstorm-openapi) and the | ||
| configuration found in `./openapi-genconfig.yaml`. | ||
|
|
||
| - API version: 1.0.0 | ||
| - Build date: 2026-01-26T17:16:00.310597514+01:00[Europe/Berlin] | ||
| - Generator version: 7.19.0 | ||
|
|
||
| Command used to generate this server: | ||
| ```bash | ||
| GO_POST_PROCESS_FILE="gofmt -w" openapi-generator-cli generate --generator-name go-server --config ./openapi-genconfig.yaml | ||
| ``` | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Docker build stage uses
golang:1.19, butgo.moddeclaresgo 1.24.0(and CI uses Go 1.24). This will fail to build in Docker due to an unsupported Go toolchain. Update the Docker base image to a Go version compatible withgo.mod(or lower thegodirective if 1.24 is not required).