Skip to content

Commit fd779f6

Browse files
committed
e2e tests
1 parent 8711d50 commit fd779f6

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,35 @@ jobs:
141141
run: |
142142
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
143143
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
144+
e2e:
145+
runs-on: ubuntu-latest
146+
needs: publish-image
147+
steps:
148+
- name: Pull and run container
149+
run: |
150+
docker pull ghcr.io/pluralsh/pr-governance-webhook:main
151+
docker run -d -p 8080:8080 --name pr-server ghcr.io/pluralsh/pr-governance-webhook:main
152+
153+
- name: Wait for server to be ready
154+
run: |
155+
for i in {1..10}; do
156+
if curl -s http://localhost:8080/v1/open -o /dev/null; then
157+
echo "Server is up!"
158+
exit 0
159+
fi
160+
echo "Waiting for server..."
161+
sleep 2
162+
done
163+
echo "Server failed to start"
164+
docker logs pr-server
165+
exit 1
166+
167+
- name: Run E2E tests
168+
run: go test -v ./test/e2e
169+
170+
- name: Dump logs if tests fail
171+
if: failure()
172+
run: docker logs pr-server
173+
174+
- name: Cleanup
175+
run: docker rm -f pr-server || true

test/e2e/e2e_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package e2e
2+
3+
import (
4+
"bytes"
5+
"encoding/json"
6+
"net/http"
7+
"testing"
8+
)
9+
10+
func TestOpenEndpoint(t *testing.T) {
11+
payload := map[string]any{
12+
"pr": map[string]any{
13+
"url": "https://example.com",
14+
"title": "E2E Test PR",
15+
"body": "Some body",
16+
"ref": "feature/e2e",
17+
},
18+
}
19+
body, _ := json.Marshal(payload)
20+
21+
resp, err := http.Post("http://localhost:8080/v1/open", "application/json", bytes.NewBuffer(body))
22+
if err != nil {
23+
t.Fatalf("Failed to call /v1/open: %v", err)
24+
}
25+
defer resp.Body.Close()
26+
27+
if resp.StatusCode != http.StatusOK {
28+
t.Errorf("Expected 200 OK, got %d", resp.StatusCode)
29+
}
30+
}

0 commit comments

Comments
 (0)