Skip to content

Commit bee196b

Browse files
E2e cli work (#521)
* This commit contains code for Analytics Python CLI E2E Testing Tool - LIBRARIES-2434 * Refactor e2e-cli to use unified JSON input format - Accept --input with JSON containing sequences, config, writeKey, apiHost - Support time-delayed event sequences for retry testing - Output JSON result on stdout for test harness integration - Map config options to SDK parameters (flushAt, flushInterval, maxRetries) * Add E2E test workflow Runs sdk-e2e-tests suite against the e2e-cli to verify SDK behavior. * Add E2E_TEST_SUITES to e2e workflow for selective test execution * Fix e2e workflow CLI_COMMAND to use console script entry point Changed from 'python -m e2e_cli' (non-existent module) to 'e2e-cli' (the actual console_scripts entry point). Removed unnecessary CLI_CWD. * Rename e2e-test to e2e-cli, update README Rename directory to match the convention used by all other SDK repos. Replace the outdated README with one documenting the current unified input/output format and parameters. * Add E2E_TESTS_TOKEN for private sdk-e2e-tests repo checkout * Add e2e-config.json and run-e2e.sh for local E2E testing Per-SDK config and convenience script for the generic test runner in sdk-e2e-tests. Run ./e2e-cli/run-e2e.sh to build and test locally. * Update CI workflow to use run-tests.sh from sdk-e2e-tests Replace hardcoded env vars and direct npm test call with ./scripts/run-tests.sh which reads e2e-config.json for test configuration. This ensures CI uses the same config as local runs. --------- Co-authored-by: neelkanth-kaushik <nkaushik@segment.com> Co-authored-by: Claude Opus 4.6
1 parent bc40fba commit bee196b

File tree

12 files changed

+342
-0
lines changed

12 files changed

+342
-0
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# E2E Tests for analytics-python
2+
# Copy this file to: analytics-python/.github/workflows/e2e-tests.yml
3+
#
4+
# This workflow:
5+
# 1. Checks out the SDK and sdk-e2e-tests repos
6+
# 2. Installs the SDK and e2e-cli dependencies
7+
# 3. Runs the e2e test suite
8+
9+
name: E2E Tests
10+
11+
on:
12+
push:
13+
branches: [main, master]
14+
pull_request:
15+
branches: [main, master]
16+
workflow_dispatch: # Allow manual trigger
17+
18+
jobs:
19+
e2e-tests:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout SDK
24+
uses: actions/checkout@v4
25+
with:
26+
path: sdk
27+
28+
- name: Checkout sdk-e2e-tests
29+
uses: actions/checkout@v4
30+
with:
31+
repository: segmentio/sdk-e2e-tests
32+
token: ${{ secrets.E2E_TESTS_TOKEN }}
33+
path: sdk-e2e-tests
34+
35+
- name: Setup Python
36+
uses: actions/setup-python@v5
37+
with:
38+
python-version: '3.11'
39+
40+
- name: Setup Node.js
41+
uses: actions/setup-node@v4
42+
with:
43+
node-version: '20'
44+
45+
- name: Install Python SDK
46+
working-directory: sdk
47+
run: pip install -e .
48+
49+
- name: Install e2e-cli dependencies
50+
working-directory: sdk/e2e-cli
51+
run: pip install -e .
52+
53+
- name: Run E2E tests
54+
working-directory: sdk-e2e-tests
55+
run: |
56+
./scripts/run-tests.sh \
57+
--sdk-dir "${{ github.workspace }}/sdk/e2e-cli" \
58+
--cli "e2e-cli"
59+
60+
- name: Upload test results
61+
if: always()
62+
uses: actions/upload-artifact@v4
63+
with:
64+
name: e2e-test-results
65+
path: sdk-e2e-tests/test-results/
66+
if-no-files-found: ignore

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ build
1010
.vscode/
1111
.idea/
1212
.python-version
13+
.venv
14+
.DS_Store

e2e-cli/.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
APP_NAME='e2e-cli'
2+
DEBUG_MODE = False
3+
SEND_EVENTS = True
4+
LOG_FORMAT='%(asctime)s - %(name)s - %(levelname)s - %(message)s'

e2e-cli/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# analytics-python e2e-cli
2+
3+
E2E test CLI for the [analytics-python](https://github.com/segmentio/analytics-python) SDK. Accepts a JSON input describing events and SDK configuration, sends them through the real SDK, and outputs results as JSON.
4+
5+
## Setup
6+
7+
```bash
8+
cd e2e-cli
9+
python3 -m venv .venv
10+
source .venv/bin/activate
11+
pip install -r requirements.txt
12+
pip install -e .
13+
```
14+
15+
## Usage
16+
17+
```bash
18+
e2e-cli --input '{"writeKey":"...", ...}'
19+
```
20+
21+
Or without installing:
22+
23+
```bash
24+
python3 -m src.cli --input '{"writeKey":"...", ...}'
25+
```
26+
27+
## Input Format
28+
29+
```jsonc
30+
{
31+
"writeKey": "your-write-key", // required
32+
"apiHost": "https://...", // optional — defaults to https://api.segment.io
33+
"sequences": [ // required — event sequences to send
34+
{
35+
"delayMs": 0,
36+
"events": [
37+
{ "type": "track", "event": "Test", "userId": "user-1" }
38+
]
39+
}
40+
],
41+
"config": { // optional
42+
"flushAt": 100, // upload_size in Python SDK
43+
"flushInterval": 500, // ms (auto-converted to seconds if > 100)
44+
"maxRetries": 10,
45+
"timeout": 15
46+
}
47+
}
48+
```
49+
50+
Note: Python is a server-side SDK — there is no CDN settings fetch, so `cdnHost` does not apply.
51+
52+
## Output Format
53+
54+
```json
55+
{ "success": true, "sentBatches": 1 }
56+
```
57+
58+
On failure:
59+
60+
```json
61+
{ "success": false, "error": "description", "sentBatches": 0 }
62+
```

e2e-cli/__init__.py

Whitespace-only changes.

e2e-cli/e2e-config.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"sdk": "python",
3+
"test_suites": "basic",
4+
"auto_settings": false,
5+
"patch": null,
6+
"env": {}
7+
}

e2e-cli/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

e2e-cli/requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
click==8.1.8
2+
python-dotenv==1.0.1
3+
python-dateutil==2.8.2
4+
requests==2.32.3
5+
PyJWT==2.10.1
6+
backoff==2.2.1

e2e-cli/run-e2e.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
#
3+
# Run E2E tests for analytics-python
4+
#
5+
# Prerequisites: Python 3, pip, Node.js 18+
6+
#
7+
# Usage:
8+
# ./run-e2e.sh [extra args passed to run-tests.sh]
9+
#
10+
# Override sdk-e2e-tests location:
11+
# E2E_TESTS_DIR=../my-e2e-tests ./run-e2e.sh
12+
#
13+
14+
set -e
15+
16+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
17+
SDK_ROOT="$SCRIPT_DIR/.."
18+
E2E_DIR="${E2E_TESTS_DIR:-$SDK_ROOT/../sdk-e2e-tests}"
19+
20+
echo "=== Building analytics-python e2e-cli ==="
21+
22+
# Install SDK
23+
cd "$SDK_ROOT"
24+
pip install -e .
25+
26+
# Install e2e-cli
27+
cd "$SCRIPT_DIR"
28+
pip install -e .
29+
30+
echo ""
31+
32+
# Run tests
33+
cd "$E2E_DIR"
34+
./scripts/run-tests.sh \
35+
--sdk-dir "$SCRIPT_DIR" \
36+
--cli "e2e-cli" \
37+
"$@"

e2e-cli/setup.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from setuptools import setup, find_packages
2+
3+
setup(
4+
name='e2e-cli',
5+
version='0.1.0',
6+
packages=find_packages(),
7+
include_package_data=True,
8+
install_requires=[
9+
'click',
10+
],
11+
entry_points={
12+
'console_scripts': [
13+
'e2e-cli = src.cli:run',
14+
],
15+
},
16+
)

0 commit comments

Comments
 (0)