Skip to content

Commit

Permalink
Use hoverfly to record tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandrodnm committed Jul 9, 2024
1 parent b4158bf commit 3722f40
Show file tree
Hide file tree
Showing 5 changed files with 666 additions and 1 deletion.
33 changes: 33 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- "**"

jobs:
docker:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Set up Docker Compose
run: sudo apt-get install docker-compose

- name: Build and run pgai-tests
run: docker-compose run pgai-tests
11 changes: 10 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# syntax=docker/dockerfile:1.3-labs
FROM postgres:16
FROM postgres:16 as pgai

ENV DEBIAN_FRONTEND=noninteractive
USER root
Expand All @@ -23,3 +23,12 @@ COPY ./ai--*.sql /usr/share/postgresql/16/extension/
RUN chmod -R go+w /usr/share/postgresql/16/extension/
RUN chmod -R go+w /usr/lib/postgresql/16/lib/
WORKDIR /pgai

FROM pgai as pgai-tests

COPY tests/hoverfly.crt /usr/local/share/ca-certificates/hoverfly.crt
COPY tests/mockserver.crt /usr/local/share/ca-certificates/mockserver.crt

RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates && \
update-ca-certificates
51 changes: 51 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
services:
postgres:
image: pgai:ci
build:
context: .
dockerfile: Dockerfile
target: pgai-tests
environment:
POSTGRES_DB: postgres
HTTPS_PROXY: hoverfly:8500
HTTP_PROXY: hoverfly:8500
POSTGRES_HOST_AUTH_METHOD: trust
REQUESTS_CA_BUNDLE: /usr/local/share/ca-certificates/hoverfly.crt
SSL_CERT_FILE: /usr/local/share/ca-certificates/hoverfly.crt
ports:
- "5432:5432"
depends_on:
- hoverfly
pgai-tests:
image: postgres:alpine
command:
environment:
ENABLE_COHERE_TESTS: 1
COHERE_API_KEY: cohere_api
depends_on:
- postgres
volumes:
- .:/sql-scripts
entrypoint: |
/bin/sh -c "
until pg_isready -h postgres -U postgres; do
echo 'Waiting for postgres to be ready...'
sleep 2
done
cd /sql-scripts
psql -d postgres -f test.sql -h postgres -U postgres
"
restart: "no"

hoverfly:
image: spectolabs/hoverfly:latest
volumes:
- ./tests:/config
ports:
- 8888:8888
- 8500:8500
# To record the requests, set -spy or -capture. Then retrieve them with
# docker-compose up when it's done, don't kill the containers and run
# docker-compose exec hoverfly -- wget -O - localhost:8888/api/v2/simulation | pbcopy
# command: -capture
command: -import /config/cohere-hoverfly-simulations.json
Loading

0 comments on commit 3722f40

Please sign in to comment.