Skip to content

Commit 3d4dd86

Browse files
authored
E2e cli for cross-SDK tests (#532)
* Add e2e-cli module for analytics-java - Kotlin CLI using Gson for JSON parsing - Separate from existing analytics-cli to avoid disruption - Added to parent pom.xml modules * 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 * Adding README.md for e2e-cli * Add E2E_TESTS_TOKEN for private sdk-e2e-tests repo checkout 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. 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: Claude Opus 4.6
1 parent 1eb13a3 commit 3d4dd86

File tree

7 files changed

+423
-0
lines changed

7 files changed

+423
-0
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# E2E Tests for analytics-java
2+
# Copy this file to: analytics-java/.github/workflows/e2e-tests.yml
3+
#
4+
# This workflow:
5+
# 1. Checks out the SDK and sdk-e2e-tests repos
6+
# 2. Builds the SDK and e2e-cli
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 Java
36+
uses: actions/setup-java@v4
37+
with:
38+
distribution: 'temurin'
39+
java-version: '11'
40+
41+
- name: Setup Node.js
42+
uses: actions/setup-node@v4
43+
with:
44+
node-version: '20'
45+
46+
- name: Build Java SDK and e2e-cli
47+
working-directory: sdk
48+
run: mvn package -pl e2e-cli -am -DskipTests
49+
50+
- name: Find e2e-cli jar
51+
id: find-jar
52+
working-directory: sdk
53+
run: |
54+
JAR_PATH=$(find e2e-cli/target -name "e2e-cli-*-jar-with-dependencies.jar" | head -1)
55+
echo "jar_path=$JAR_PATH" >> $GITHUB_OUTPUT
56+
57+
- name: Run E2E tests
58+
working-directory: sdk-e2e-tests
59+
run: |
60+
./scripts/run-tests.sh \
61+
--sdk-dir "${{ github.workspace }}/sdk/e2e-cli" \
62+
--cli "java -jar ${{ github.workspace }}/sdk/${{ steps.find-jar.outputs.jar_path }}"
63+
64+
- name: Upload test results
65+
if: always()
66+
uses: actions/upload-artifact@v4
67+
with:
68+
name: e2e-test-results
69+
path: sdk-e2e-tests/test-results/
70+
if-no-files-found: ignore

e2e-cli/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# analytics-java e2e-cli
2+
3+
E2E test CLI for the [analytics-java](https://github.com/segmentio/analytics-java) SDK. Accepts a JSON input describing events and SDK configuration, sends them through the real SDK, and outputs results as JSON.
4+
5+
Built with Kotlin (JVM) and packaged as a fat jar via Maven.
6+
7+
## Setup
8+
9+
```bash
10+
mvn package -pl e2e-cli -am
11+
```
12+
13+
## Usage
14+
15+
```bash
16+
java -jar e2e-cli/target/e2e-cli-*-jar-with-dependencies.jar --input '{"writeKey":"...", ...}'
17+
```
18+
19+
## Input Format
20+
21+
```jsonc
22+
{
23+
"writeKey": "your-write-key", // required
24+
"apiHost": "https://...", // optional — SDK default if omitted
25+
"sequences": [ // required — event sequences to send
26+
{
27+
"delayMs": 0,
28+
"events": [
29+
{ "type": "track", "event": "Test", "userId": "user-1" }
30+
]
31+
}
32+
],
33+
"config": { // optional
34+
"flushAt": 250,
35+
"flushInterval": 10000,
36+
"maxRetries": 3,
37+
"timeout": 15
38+
}
39+
}
40+
```
41+
42+
Note: Java is a server-side SDK — there is no CDN settings fetch, so `cdnHost` does not apply.
43+
44+
## Output Format
45+
46+
```json
47+
{ "success": true, "sentBatches": 1 }
48+
```
49+
50+
On failure:
51+
52+
```json
53+
{ "success": false, "error": "description", "sentBatches": 0 }
54+
```

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": "java",
3+
"test_suites": "basic",
4+
"auto_settings": false,
5+
"patch": null,
6+
"env": {}
7+
}

e2e-cli/pom.xml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<artifactId>analytics-parent</artifactId>
8+
<groupId>com.segment.analytics.java</groupId>
9+
<version>3.5.5-SNAPSHOT</version>
10+
</parent>
11+
12+
<groupId>com.segment.analytics.java</groupId>
13+
<artifactId>e2e-cli</artifactId>
14+
<version>3.5.5-SNAPSHOT</version>
15+
<name>Analytics Java E2E CLI</name>
16+
17+
<description>E2E testing CLI for Segment Analytics for Java.</description>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.jetbrains.kotlin</groupId>
22+
<artifactId>kotlin-stdlib</artifactId>
23+
<version>${kotlin.version}</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>com.segment.analytics.java</groupId>
27+
<artifactId>analytics</artifactId>
28+
<version>${project.version}</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.jetbrains.kotlinx</groupId>
32+
<artifactId>kotlinx-serialization-json</artifactId>
33+
<version>1.4.1</version>
34+
</dependency>
35+
</dependencies>
36+
37+
<build>
38+
<sourceDirectory>src/main/kotlin</sourceDirectory>
39+
40+
<plugins>
41+
<plugin>
42+
<artifactId>kotlin-maven-plugin</artifactId>
43+
<groupId>org.jetbrains.kotlin</groupId>
44+
<version>${kotlin.version}</version>
45+
<configuration>
46+
<compilerPlugins>
47+
<plugin>kotlinx-serialization</plugin>
48+
</compilerPlugins>
49+
</configuration>
50+
<dependencies>
51+
<dependency>
52+
<groupId>org.jetbrains.kotlin</groupId>
53+
<artifactId>kotlin-maven-serialization</artifactId>
54+
<version>${kotlin.version}</version>
55+
</dependency>
56+
</dependencies>
57+
<executions>
58+
<execution>
59+
<id>compile</id>
60+
<phase>compile</phase>
61+
<goals>
62+
<goal>compile</goal>
63+
</goals>
64+
</execution>
65+
</executions>
66+
</plugin>
67+
<plugin>
68+
<groupId>org.apache.maven.plugins</groupId>
69+
<artifactId>maven-assembly-plugin</artifactId>
70+
<configuration>
71+
<descriptorRefs>
72+
<descriptorRef>jar-with-dependencies</descriptorRef>
73+
</descriptorRefs>
74+
<archive>
75+
<manifest>
76+
<mainClass>cli.MainKt</mainClass>
77+
</manifest>
78+
</archive>
79+
</configuration>
80+
<executions>
81+
<execution>
82+
<phase>package</phase>
83+
<goals>
84+
<goal>single</goal>
85+
</goals>
86+
</execution>
87+
</executions>
88+
</plugin>
89+
</plugins>
90+
</build>
91+
</project>

e2e-cli/run-e2e.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
#
3+
# Run E2E tests for analytics-java
4+
#
5+
# Prerequisites: Java 11+, Maven, 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-java e2e-cli ==="
21+
22+
# Build SDK and e2e-cli
23+
cd "$SDK_ROOT"
24+
mvn package -pl e2e-cli -am -DskipTests
25+
26+
# Find the built jar
27+
CLI_JAR=$(find "$SDK_ROOT/e2e-cli/target" -name "e2e-cli-*-jar-with-dependencies.jar" | head -1)
28+
if [[ -z "$CLI_JAR" ]]; then
29+
echo "Error: Could not find e2e-cli jar"
30+
exit 1
31+
fi
32+
echo "Found jar: $CLI_JAR"
33+
34+
echo ""
35+
36+
# Run tests
37+
cd "$E2E_DIR"
38+
./scripts/run-tests.sh \
39+
--sdk-dir "$SCRIPT_DIR" \
40+
--cli "java -jar $CLI_JAR" \
41+
"$@"

0 commit comments

Comments
 (0)