Skip to content

Commit a51c5e4

Browse files
authored
Merge pull request #203 from segmentio/add-e2e-cli
Add e2e-cli for E2E testing
2 parents bc3a04e + 1ba52ca commit a51c5e4

11 files changed

Lines changed: 691 additions & 40 deletions

File tree

.circleci/config.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [v3.0]
6+
pull_request:
7+
branches: [v3.0]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
go-version: ['1.21', '1.22', '1.23']
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Go ${{ matrix.go-version }}
22+
uses: actions/setup-go@v5
23+
with:
24+
go-version: ${{ matrix.go-version }}
25+
26+
- name: Download dependencies
27+
run: go get -v -t ./...
28+
29+
- name: Vet
30+
run: go vet ./...
31+
32+
- name: Test
33+
run: go test -race -coverprofile=cover.out .
34+
35+
- name: Upload coverage
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: coverage-go${{ matrix.go-version }}
39+
path: cover.out
40+
retention-days: 7

.github/workflows/e2e-tests.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: E2E Tests
2+
3+
on:
4+
push:
5+
branches: [v3.0]
6+
pull_request:
7+
branches: [v3.0]
8+
workflow_dispatch:
9+
inputs:
10+
e2e_tests_ref:
11+
description: 'Branch or ref of sdk-e2e-tests to use'
12+
required: false
13+
default: 'main'
14+
15+
jobs:
16+
e2e-tests:
17+
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout SDK
22+
uses: actions/checkout@v4
23+
with:
24+
path: sdk
25+
26+
- name: Checkout sdk-e2e-tests
27+
uses: actions/checkout@v4
28+
with:
29+
repository: segmentio/sdk-e2e-tests
30+
ref: ${{ inputs.e2e_tests_ref || 'main' }}
31+
token: ${{ secrets.E2E_TESTS_TOKEN }}
32+
path: sdk-e2e-tests
33+
34+
- name: Setup Go
35+
uses: actions/setup-go@v5
36+
with:
37+
go-version-file: sdk/go.mod
38+
39+
- name: Setup Node.js
40+
uses: actions/setup-node@v4
41+
with:
42+
node-version: '20'
43+
44+
- name: Build e2e-cli
45+
working-directory: sdk/e2e-cli
46+
run: go build -o e2e-cli-bin ./...
47+
48+
- name: Run E2E tests
49+
working-directory: sdk-e2e-tests
50+
run: |
51+
./scripts/run-tests.sh \
52+
--sdk-dir "${{ github.workspace }}/sdk/e2e-cli" \
53+
--cli "${{ github.workspace }}/sdk/e2e-cli/e2e-cli-bin"
54+
55+
- name: Upload test results
56+
if: always()
57+
uses: actions/upload-artifact@v4
58+
with:
59+
name: e2e-test-results
60+
path: sdk-e2e-tests/test-results/
61+
if-no-files-found: ignore
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Publish E2E CLI
2+
3+
on:
4+
push:
5+
branches: [v3.0]
6+
paths:
7+
- 'e2e-cli/**'
8+
- '*.go'
9+
- 'go.mod'
10+
- 'go.sum'
11+
schedule:
12+
- cron: '0 0 1 * *'
13+
workflow_dispatch:
14+
15+
jobs:
16+
publish:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout SDK
20+
uses: actions/checkout@v4
21+
22+
- name: Setup Go
23+
uses: actions/setup-go@v5
24+
with:
25+
go-version-file: go.mod
26+
27+
- name: Build e2e-cli
28+
working-directory: e2e-cli
29+
run: go build -o e2e-cli-bin ./...
30+
31+
- name: Upload CLI artifact
32+
uses: actions/upload-artifact@v4
33+
with:
34+
name: e2e-cli-go
35+
path: e2e-cli/e2e-cli-bin
36+
retention-days: 90

e2e-cli/.gitignore

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

e2e-cli/README.md

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# analytics-go e2e-cli
2+
3+
A small CLI tool used for end-to-end testing of the `analytics-go` SDK. It accepts a JSON description of event sequences, sends those events through the real SDK, and reports the result.
4+
5+
## Prerequisites
6+
7+
- Go 1.17+
8+
- (For `run-e2e.sh`) Node.js 18+ and the `sdk-e2e-tests` repo checked out alongside this repo
9+
10+
## Building
11+
12+
```bash
13+
cd e2e-cli
14+
go build -o e2e-cli-bin ./...
15+
```
16+
17+
## Usage
18+
19+
```bash
20+
./e2e-cli-bin --input '<JSON>'
21+
```
22+
23+
The CLI writes debug/log information to **stderr** and the JSON result to **stdout**.
24+
25+
Exit code is `0` on success and `1` on failure.
26+
27+
## Input JSON format
28+
29+
```json
30+
{
31+
"writeKey": "YOUR_WRITE_KEY",
32+
"apiHost": "https://api.segment.io",
33+
"sequences": [
34+
{
35+
"delayMs": 0,
36+
"events": [
37+
{
38+
"type": "track",
39+
"event": "Button Clicked",
40+
"userId": "user-123",
41+
"properties": { "plan": "pro" }
42+
},
43+
{
44+
"type": "identify",
45+
"userId": "user-123",
46+
"traits": { "email": "user@example.com" }
47+
},
48+
{
49+
"type": "page",
50+
"userId": "user-123",
51+
"name": "Home"
52+
},
53+
{
54+
"type": "screen",
55+
"userId": "user-123",
56+
"name": "Main Screen"
57+
},
58+
{
59+
"type": "alias",
60+
"userId": "new-id",
61+
"previousId": "old-id"
62+
},
63+
{
64+
"type": "group",
65+
"userId": "user-123",
66+
"groupId": "group-456",
67+
"traits": { "name": "Acme Corp" }
68+
}
69+
]
70+
}
71+
],
72+
"config": {
73+
"flushAt": 15,
74+
"flushInterval": 1000,
75+
"maxRetries": 3,
76+
"timeout": 10
77+
}
78+
}
79+
```
80+
81+
### Top-level fields
82+
83+
| Field | Type | Description |
84+
|-------------|--------|--------------------------------------------------|
85+
| `writeKey` | string | Segment write key used to authenticate requests |
86+
| `apiHost` | string | Full API endpoint URL (e.g. `https://api.segment.io`) |
87+
| `sequences` | array | List of event sequences (run in order) |
88+
| `config` | object | SDK configuration overrides |
89+
90+
### Sequence fields
91+
92+
| Field | Type | Description |
93+
|-----------|-------|---------------------------------------------------------------------|
94+
| `delayMs` | int | Milliseconds to wait before sending this sequence's events |
95+
| `events` | array | List of events to enqueue |
96+
97+
### Event fields
98+
99+
| Field | Type | Description |
100+
|---------------|--------|---------------------------------------------------------------------|
101+
| `type` | string | Event type: `track`, `identify`, `page`, `screen`, `alias`, `group` |
102+
| `event` | string | Event name (required for `track`) |
103+
| `userId` | string | User ID |
104+
| `anonymousId` | string | Anonymous ID (used when `userId` is absent) |
105+
| `messageId` | string | Optional explicit message ID |
106+
| `previousId` | string | Previous user ID (required for `alias`) |
107+
| `groupId` | string | Group ID (required for `group`) |
108+
| `name` | string | Page or screen name |
109+
| `timestamp` | string | ISO 8601 timestamp (RFC3339), e.g. `2024-01-15T10:30:00Z` |
110+
| `properties` | object | Event properties (for `track`, `page`, `screen`) |
111+
| `traits` | object | User or group traits (for `identify`, `group`) |
112+
| `integrations`| object | Integration-specific settings |
113+
114+
### Config fields
115+
116+
| Field | Type | Description |
117+
|-----------------|------|------------------------------------------|
118+
| `flushAt` | int | Max events per batch (default: 250) |
119+
| `flushInterval` | int | Flush interval in milliseconds |
120+
| `maxRetries` | int | (informational, not directly used by SDK)|
121+
| `timeout` | int | Timeout in seconds (informational) |
122+
123+
## Output JSON format
124+
125+
On success:
126+
127+
```json
128+
{"success": true, "sentBatches": 1}
129+
```
130+
131+
On failure:
132+
133+
```json
134+
{"success": false, "sentBatches": 0, "error": "description of error"}
135+
```
136+
137+
## Running E2E tests
138+
139+
Use the provided shell script to build the CLI and run the shared `sdk-e2e-tests` suite:
140+
141+
```bash
142+
# From the e2e-cli directory, with sdk-e2e-tests checked out as a sibling of analytics-go:
143+
./run-e2e.sh
144+
145+
# Override the e2e test directory:
146+
E2E_TESTS_DIR=/path/to/sdk-e2e-tests ./run-e2e.sh
147+
148+
# Pass additional arguments to run-tests.sh:
149+
./run-e2e.sh --suite basic
150+
```
151+
152+
The script:
153+
1. Builds the `e2e-cli-bin` binary using `go build`
154+
2. Invokes `sdk-e2e-tests/scripts/run-tests.sh` with the appropriate `--sdk-dir` and `--cli` flags

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

e2e-cli/go.mod

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module github.com/segmentio/analytics-go/v3/e2e-cli
2+
3+
go 1.17
4+
5+
require github.com/segmentio/analytics-go/v3 v3.0.0
6+
7+
require (
8+
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
9+
github.com/google/uuid v1.3.0 // indirect
10+
github.com/kr/pretty v0.3.1 // indirect
11+
github.com/segmentio/backo-go v1.0.0 // indirect
12+
)
13+
14+
replace github.com/segmentio/analytics-go/v3 => ../

e2e-cli/go.sum

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
2+
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
3+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
4+
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
5+
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
6+
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
7+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
8+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
9+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
10+
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
11+
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
12+
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
13+
github.com/segmentio/backo-go v1.0.0 h1:kbOAtGJY2DqOR0jfRkYEorx/b18RgtepGtY3+Cpe6qA=
14+
github.com/segmentio/backo-go v1.0.0/go.mod h1:kJ9mm9YmoWSkk+oQ+5Cj8DEoRCX2JT6As4kEtIIOp1M=
15+
github.com/segmentio/conf v1.2.0/go.mod h1:Y3B9O/PqqWqjyxyWWseyj/quPEtMu1zDp/kVbSWWaB0=
16+
github.com/segmentio/go-snakecase v1.1.0/go.mod h1:jk1miR5MS7Na32PZUykG89Arm+1BUSYhuGR6b7+hJto=
17+
github.com/segmentio/objconv v1.0.1/go.mod h1:auayaH5k3137Cl4SoXTgrzQcuQDmvuVtZgS0fb1Ahys=
18+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
19+
gopkg.in/go-playground/mold.v2 v2.2.0/go.mod h1:XMyyRsGtakkDPbxXbrA5VODo6bUXyvoDjLd5l3T0XoA=
20+
gopkg.in/validator.v2 v2.0.0-20180514200540-135c24b11c19/go.mod h1:o4V0GXN9/CAmCsvJ0oXYZvrZOe7syiDZSN1GWGZTGzc=
21+
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

0 commit comments

Comments
 (0)