Skip to content

test: skip TestInvalidAPIKeyRejected when auth is disabled (#41) #167

test: skip TestInvalidAPIKeyRejected when auth is disabled (#41)

test: skip TestInvalidAPIKeyRejected when auth is disabled (#41) #167

Workflow file for this run

name: Test CyborgDB Go SDK
permissions:
contents: read
on:
pull_request:
types: [opened, synchronize]
push:
branches: [main]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: '1.21'
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.12.2
args: --config .golangci.yml
compute_version:
runs-on: ubuntu-latest
outputs:
env: ${{ steps.compute.outputs.env }}
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
fetch-tags: true
- name: Compute environment
id: compute
run: |
# For PRs and main branch pushes, use dev environment
# For tags, determine based on tag pattern
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
TAG="${{ github.ref_name }}"
if [[ "$TAG" == *"rc"* ]]; then
echo "env=staging" >> $GITHUB_OUTPUT
else
echo "env=prod" >> $GITHUB_OUTPUT
fi
else
# Default to dev for PRs and main branch
echo "env=dev" >> $GITHUB_OUTPUT
fi
test:
runs-on: ubuntu-latest
needs: [lint, compute_version]
permissions:
contents: read
id-token: write
steps:
- name: Checkout SDK code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: '1.21'
- name: Set up Python for server
uses: actions/setup-python@v6
with:
python-version: '3.13'
- name: Load secrets from 1Password
uses: 1password/load-secrets-action@v4
with:
export-env: true
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_TOKEN }}
CYBORGDB_API_KEY: "op://CyborgDB/CyborgDB ${{ needs.compute_version.outputs.env == 'dev' && 'Dev' || needs.compute_version.outputs.env == 'staging' && 'Staging' || 'Prod' }}/CYBORGDB_API_KEY_STANDARD"
- name: Load CodeArtifact account ID from 1Password
if: needs.compute_version.outputs.env != 'prod'
uses: 1password/load-secrets-action@v4
with:
export-env: true
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_TOKEN }}
CA_AWS_ACCOUNT_ID: "op://CyborgDB/CyborgDB ${{ needs.compute_version.outputs.env == 'dev' && 'Dev' || 'Staging' }}/CA_AWS_ACCOUNT_ID"
- name: Get CodeArtifact pip index URL
if: needs.compute_version.outputs.env != 'prod'
id: ca-url
uses: ./.github/workflows/actions/codeartifact-pip-url
with:
aws-account-id: ${{ env.CA_AWS_ACCOUNT_ID }}
role-to-assume: arn:aws:iam::${{ env.CA_AWS_ACCOUNT_ID }}:role/CyborgGitHubActionsS3Role
codeartifact-repository: ${{ needs.compute_version.outputs.env == 'dev' && 'cyborg-dev' || 'cyborg-staging' }}
- name: Export PIP_INDEX_URL
if: needs.compute_version.outputs.env != 'prod'
run: echo "PIP_INDEX_URL=${{ steps.ca-url.outputs.pip-index-url }}" >> $GITHUB_ENV
- name: Install service dependencies
run: |
# Install CPU-only torch
pip install torch --index-url https://download.pytorch.org/whl/cpu
# Install optional test dependencies
pip install sentence-transformers
- name: Install cyborgdb-service
run: |
# For dev/staging, PIP_INDEX_URL points at CodeArtifact (PyPI upstream). For prod, it is unset and pip falls back to PyPI.
pip install "cyborgdb-service[embeddings]" --pre
## TODO - Add a test for Lite version
# - name: Test with Lite version
# run: |
# echo "=== Testing with Lite version ==="
# ...
- name: Test with Standard version
run: |
echo "=== Testing with Standard version ==="
# Set up environment for Standard
export CYBORGDB_API_KEY="${CYBORGDB_API_KEY}"
export CYBORGDB_DB_TYPE=disk
export CYBORGDB_SERVICE_LOG_LEVEL=DEBUG
export CYBORGDB_BASE_URL=http://localhost:8000
# Start the service with Standard API key
nohup cyborgdb-service > server-standard.log 2>&1 &
echo $! > server-standard.pid
# Wait for service to be ready
for i in {1..30}; do
if curl -fs http://localhost:8000/v1/health > /dev/null; then
echo "Standard service is up!"
break
fi
sleep 1
done
if ! curl -fs http://localhost:8000/v1/health > /dev/null; then
echo "Standard service failed to start"
cat server-standard.log
exit 1
fi
# Run tests based on trigger type
# Note: -race flag removed because it uses 5-10x more memory which causes
# the server to crash during auto-training with memory exhaustion
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "Running quick flow tests for PR..."
go test -v -run TestUnitFlow -coverprofile=coverage.txt -covermode=atomic -coverpkg=github.com/cyborginc/cyborgdb-go ./test
else
echo "Running all tests for main branch..."
go test -v -coverprofile=coverage.txt -covermode=atomic -coverpkg=github.com/cyborginc/cyborgdb-go ./test
fi
# Stop standard server
kill $(cat server-standard.pid) || true
- name: Upload coverage reports
uses: codecov/codecov-action@v7
with:
file: ./coverage.txt
flags: unittests
name: codecov-umbrella
continue-on-error: true