Skip to content

Commit f95eeef

Browse files
committed
pr ci include test runs against api mock
Using openapi.yml godon-api mock deliberately. That avoids having to start godon-api dependencies and keeps the test flow simple.
1 parent ef5abe4 commit f95eeef

3 files changed

Lines changed: 93 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
3333
# Set environment variables for this session
3434
export SSL_CERT_FILE="/etc/ssl/certs/ca-bundle.crt"
35-
export NIX_SSL_CERT_FILE="/etc/ssl/certs/ca-bundle.crt"
35+
export NIX_SSL_CERT_FILE="/etc/ssl/certs/ca-bundle.crt"
3636
export CURL_CA_BUNDLE="/etc/ssl/certs/ca-bundle.crt"
3737
3838
# Add to nix.conf for daemon
@@ -58,3 +58,90 @@ jobs:
5858
ls -la $(nix path-info .#default)/bin/ || echo "$out/bin not found"
5959
echo "Testing compiled binary with direct path..."
6060
$(nix path-info .#default)/bin/godon_cli --help
61+
62+
- name: Start Prism mock container
63+
run: |
64+
# Download the OpenAPI spec with retry
65+
echo "Downloading OpenAPI spec..."
66+
curl -L --retry 3 --retry-delay 5 -o openapi.yml \
67+
https://raw.githubusercontent.com/godon-dev/godon-images/main/images/godon-api/openapi.yml
68+
69+
# Verify the spec was downloaded
70+
if [ ! -f openapi.yml ]; then
71+
echo "Failed to download OpenAPI spec"
72+
exit 1
73+
fi
74+
echo "OpenAPI spec downloaded successfully"
75+
head -5 openapi.yml
76+
77+
# Start Prism container in background
78+
docker run -d --name prism -p 4010:4010 \
79+
-v $(pwd)/openapi.yml:/tmp/openapi.yml \
80+
stoplight/prism:4 \
81+
mock --host 0.0.0.0 /tmp/openapi.yml
82+
83+
# Wait for Prism to start
84+
echo "Waiting for Prism to start..."
85+
sleep 15
86+
87+
# Verify Prism is running with retry
88+
for i in {1..5}; do
89+
if curl -f http://localhost:4010/health; then
90+
echo "Prism container started successfully on port 4010"
91+
break
92+
else
93+
echo "Attempt $i: Prism not ready yet, waiting..."
94+
sleep 5
95+
fi
96+
done
97+
98+
- name: Integration tests against Prism mock
99+
run: |
100+
# Get the binary path
101+
BINARY_PATH=$(nix path-info .#default)/bin/godon_cli
102+
103+
echo "Running integration tests against Prism mock..."
104+
105+
# Test breeder list
106+
echo "Testing: breeder list"
107+
$BINARY_PATH --hostname=localhost --port=4010 breeder list
108+
109+
# Create test YAML files using echo
110+
echo 'name: "Test Breeder"' > test_breeder.yml
111+
echo 'description: "Integration test breeder"' >> test_breeder.yml
112+
echo 'config:' >> test_breeder.yml
113+
echo ' setting1: "value1"' >> test_breeder.yml
114+
echo ' setting2: 42' >> test_breeder.yml
115+
116+
echo "Testing: breeder create"
117+
$BINARY_PATH --hostname=localhost --port=4010 breeder create --file=test_breeder.yml
118+
119+
# Test breeder show with a mock UUID
120+
echo "Testing: breeder show"
121+
$BINARY_PATH --hostname=localhost --port=4010 breeder show --uuid=123e4567-e89b-12d3-a456-426614174000
122+
123+
# Create update test file
124+
echo 'name: "Updated Test Breeder"' > test_breeder_update.yml
125+
echo 'description: "Updated integration test breeder"' >> test_breeder_update.yml
126+
echo 'config:' >> test_breeder_update.yml
127+
echo ' setting1: "updated_value1"' >> test_breeder_update.yml
128+
echo ' setting2: 100' >> test_breeder_update.yml
129+
echo ' new_setting: "new_value"' >> test_breeder_update.yml
130+
131+
echo "Testing: breeder update"
132+
$BINARY_PATH --hostname=localhost --port=4010 breeder update --file=test_breeder_update.yml
133+
134+
# Test breeder purge
135+
echo "Testing: breeder purge"
136+
$BINARY_PATH --hostname=localhost --port=4010 breeder purge --uuid=123e4567-e89b-12d3-a456-426614174000
137+
138+
# Test help commands
139+
echo "Testing: help commands"
140+
$BINARY_PATH --help
141+
$BINARY_PATH breeder --help || true # May fail but tests argument parsing
142+
143+
- name: Cleanup Prism container
144+
if: always()
145+
run: |
146+
docker stop prism || true
147+
docker rm prism || true

src/godon/client.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ proc baseUrl*(client: GodonClient): string =
3333

3434
proc handleResponse*[T](client: GodonClient; response: Response): ApiResponse[T] =
3535
## Handle HTTP response and convert to ApiResponse
36-
let statusCode = parseInt(response.status)
36+
let statusCode = parseInt(split(response.status, " ")[0])
3737
if statusCode >= 200 and statusCode < 300:
3838
try:
3939
let jsonData = parseJson(response.body)
@@ -50,7 +50,7 @@ proc handleResponse*[T](client: GodonClient; response: Response): ApiResponse[T]
5050

5151
proc handleError*(client: GodonClient, response: Response): ref CatchableError =
5252
## Convert HTTP error response to exception
53-
let statusCode = parseInt(response.status)
53+
let statusCode = parseInt(split(response.status, " ")[0])
5454
var errorMsg = "HTTP Error: " & $statusCode
5555
try:
5656
let errorJson = parseJson(response.body)

src/godon_cli.nim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ proc parseArgs(): (string, string, int, string, seq[string]) =
4141
var p = initOptParser(commandLineParams())
4242

4343
for kind, key, val in p.getopt():
44+
echo "Parsed: kind=", kind, " key=", key, " val=", val
4445
case kind
4546
of cmdArgument:
4647
if command.len == 0:
@@ -53,6 +54,8 @@ proc parseArgs(): (string, string, int, string, seq[string]) =
5354
of "hostname":
5455
hostname = val
5556
of "port":
57+
if val.len == 0:
58+
writeError("Port option requires a value")
5659
try:
5760
port = parseInt(val)
5861
except ValueError:

0 commit comments

Comments
 (0)