Skip to content

Commit d2bf593

Browse files
Copilotpelikhan
andcommitted
Add integration test suite with GitHub Actions workflow
Co-authored-by: pelikhan <[email protected]>
1 parent 1c7ad11 commit d2bf593

File tree

6 files changed

+386
-0
lines changed

6 files changed

+386
-0
lines changed

.github/workflows/integration.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: "Integration Tests"
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
integration:
18+
runs-on: ubuntu-latest
19+
env:
20+
GOPROXY: https://proxy.golang.org/,direct
21+
GOPRIVATE: ""
22+
GONOPROXY: ""
23+
GONOSUMDB: github.com/github/*
24+
steps:
25+
- uses: actions/checkout@v4
26+
27+
- uses: actions/setup-go@v5
28+
with:
29+
go-version: ">=1.22"
30+
check-latest: true
31+
32+
- name: Build gh-models binary
33+
run: script/build
34+
35+
- name: Run integration tests (without auth)
36+
working-directory: integration
37+
run: |
38+
go mod tidy
39+
go test -v -timeout=5m
40+
env:
41+
# Explicitly unset any GitHub tokens to test unauthenticated behavior
42+
GITHUB_TOKEN: ""
43+
GH_TOKEN: ""
44+
45+
- name: Install gh CLI
46+
if: github.event_name == 'workflow_dispatch'
47+
run: |
48+
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
49+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
50+
sudo apt update
51+
sudo apt install gh
52+
53+
- name: Run integration tests (with auth)
54+
if: github.event_name == 'workflow_dispatch'
55+
working-directory: integration
56+
run: |
57+
gh auth login --with-token <<< "${{ secrets.GITHUB_TOKEN }}"
58+
go test -v -timeout=10m
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
/gh-models-linux-*
55
/gh-models-windows-*
66
/gh-models-android-*
7+
8+
# Integration test dependencies
9+
integration/go.sum

DEV.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ make vet # to find suspicious constructs
3434
make tidy # to keep dependencies up-to-date
3535
```
3636

37+
### Integration Tests
38+
39+
In addition to unit tests, we have integration tests that use the compiled binary to test against live endpoints:
40+
41+
```shell
42+
# Build the binary first
43+
script/build
44+
45+
# Run integration tests
46+
cd integration
47+
go test -v
48+
```
49+
50+
Integration tests are located in the `integration/` directory and automatically skip tests requiring authentication when no GitHub token is available. See `integration/README.md` for more details.
51+
3752
## Releasing
3853

3954
When upgrading or installing the extension using `gh extension upgrade github/gh-models` or

integration/README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Integration Tests
2+
3+
This directory contains integration tests for the `gh-models` CLI extension. These tests are separate from the unit tests and use the compiled binary to test actual functionality.
4+
5+
## Overview
6+
7+
The integration tests:
8+
- Use the compiled `gh-models` binary (not mocked clients)
9+
- Test basic functionality of each command (`list`, `run`, `view`, `eval`)
10+
- Are designed to work with or without GitHub authentication
11+
- Skip tests requiring live endpoints when authentication is unavailable
12+
- Keep assertions minimal to avoid brittleness
13+
14+
## Running the Tests
15+
16+
### Prerequisites
17+
18+
1. Build the `gh-models` binary:
19+
```bash
20+
cd ..
21+
script/build
22+
```
23+
24+
2. (Optional) Authenticate with GitHub CLI for full testing:
25+
```bash
26+
gh auth login
27+
```
28+
29+
### Running Locally
30+
31+
From the integration directory:
32+
```bash
33+
go test -v
34+
```
35+
36+
Without authentication, some tests will be skipped:
37+
```
38+
=== RUN TestIntegrationHelp
39+
--- PASS: TestIntegrationHelp (0.05s)
40+
=== RUN TestIntegrationList
41+
integration_test.go:90: Skipping integration test - no GitHub authentication available
42+
--- SKIP: TestIntegrationList (0.04s)
43+
```
44+
45+
With authentication, all tests should run and test live endpoints.
46+
47+
## CI/CD
48+
49+
The integration tests run automatically on pushes to `main` via the GitHub Actions workflow `.github/workflows/integration.yml`.
50+
51+
The workflow:
52+
1. Builds the binary
53+
2. Runs tests without authentication (tests basic functionality)
54+
3. On manual dispatch, can also run with authentication for full testing
55+
56+
## Test Structure
57+
58+
Each test follows this pattern:
59+
- Check for binary existence (skip if not built)
60+
- Check for authentication (skip live endpoint tests if unavailable)
61+
- Execute the binary with specific arguments
62+
- Verify basic output format and success/failure
63+
64+
Tests are intentionally simple and focus on:
65+
- Commands execute without errors
66+
- Help text is present and correctly formatted
67+
- Basic output format is as expected
68+
- Authentication requirements are respected
69+
70+
## Adding New Tests
71+
72+
When adding new commands or features:
73+
1. Add a corresponding integration test
74+
2. Follow the existing pattern of checking authentication
75+
3. Keep assertions minimal but meaningful
76+
4. Ensure tests work both with and without authentication

integration/go.mod

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module github.com/github/gh-models/integration
2+
3+
go 1.22
4+
5+
require github.com/stretchr/testify v1.10.0
6+
7+
require (
8+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
9+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
10+
gopkg.in/yaml.v3 v3.0.1 // indirect
11+
)

0 commit comments

Comments
 (0)