Chalk home page
Docs
API
CLI
  1. Testing
  2. Integration Tests

Chalk resolvers are callable and unit-testable Python functions. However, you may want to test the interactions between Chalk resolvers with an integration test.

With branch deploys, you can deploy and test your changes before shipping your code to production.


Branch deployments

Chalk allows you to create an unlimited number of branch deployments. Branch deployments run all of your resolvers in the same way that they run in production. However, branch deployments don’t impact the offline store.

Creating a branch deployment

You can create a branch deployment in the same way that you create a full deployment by passing the flag --branch <branch_name>.

# --branch creates a branch deployment
> chalk apply --force --await --branch <branch_name>

The --await flag means that the deployment will be live by the time that the command returns.

Querying a branch deployment

You can quickly check your branch deployment using chalk query --branch on the command line to pull feature values:

# Example of making a query directly
> chalk query --branch <branch_name> \
              --in user.id=1 \
              --out user.id \
              --out user.email

The flag --branch tells this query to target the branch set during chalk apply.


Integration test

You can also target a branch from the Chalk API client. Using this client, you can write integration tests:

integration_test.py
def test_get_features():
    client = ChalkClient()
    resp = client.query(
        input={User.id: 1},
        output=[
            User.credit_report.fico_score,
            User.email,
            User.name,
            User.dob,
        ],
        preview_deployment_id=os.getenv("DEPLOYMENT_ID"),
    )
    assert resp.get_feature_value(User.credit_report.fico_score) == 700
    assert resp.get_feature_value(User.email) == "katherine.johnson@nasa.gov"

GitHub Action

Chalk can be easily integrated in a GitHub Action. You will need to create a Chalk token from the settings page of your dashboard and store the resulting client id and secret as GitHub Secrets.

name: Chalk Integration Test

on: push

jobs:
  chalk-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.10'
          cache: 'pip'

      - name: Install dependencies
        run: pip install -r requirements.txt

      - uses: chalk-ai/deploy-action@v2
        with:
          client-id: ${{secrets.CHALK_CLIENT_ID}}
          client-secret: ${{secrets.CHALK_CLIENT_SECRET}}
          # Deploys Chalk to a branch environment
          branch: ${{ GITHUB_REF_NAME }}
          # Waits for the deployment to succeed (Optional, default false)
          await: true

      - name: Runs a test query against the branch
        run: |
          # Example of making a query directly against a branch
          chalk query --branch ${{ GITHUB_REF_NAME }} \
                      --in user.id=1 \
                      --out user.id \
                      --out user.email \
                      --json \
                      --include-meta
          # Alternatively, run the integration test suite, which should make queries with the branch parameter.
          python -m unittest ./tests/integration_tests.py