Skip to content

chore: webhook integration tests generation script upgrade #4215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules/

Check warning on line 1 in .eslintignore

View workflow job for this annotation

GitHub Actions / Check for formatting & lint errors

File ignored by default.
.husky/
reports/
test/
Expand Down Expand Up @@ -28,4 +28,5 @@
.prettierignore
*.json
Dockerfile*
*.properties
*.properties
*.go
39 changes: 39 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
# Get changed files in test/integrations/sources/

Check warning on line 1 in .husky/pre-commit

View workflow job for this annotation

GitHub Actions / Check for formatting & lint errors

File ignored by default.
changed_sources=$(git diff --cached --name-only | grep "test/integrations/sources/" | cut -d'/' -f4 | sort -u)

if [ ! -z "$changed_sources" ]; then
changes_detected=false
modified_sources=""

for source in $changed_sources; do
echo "Generating test cases for $source"
go_testcase_path="go/webhook/testcases/testdata/testcases/$source"

# Store git status before generation
before_status=$(git status --porcelain "$go_testcase_path")

# Generate new test cases
npm run generate:testcases -- --source "$source"

# Check if files were modified
after_status=$(git status --porcelain "$go_testcase_path")
if [ "$before_status" != "$after_status" ]; then
# New changes detected, add them to git
git add "$go_testcase_path"
changes_detected=true
modified_sources="$modified_sources\n\033[1;32m- $source\033[0m"
fi
done

# If any changes were detected, show summary and exit
if [ "$changes_detected" = true ]; then
echo "\n\033[1;33m🔔 ATTENTION 🔔\033[0m"
echo "\033[1;36mNew integration test cases were generated for the following sources:\033[0m"
echo "$modified_sources"
echo "\n\033[1;36mTest cases have been added to git in:\033[0m"
echo "\033[1;32mgo/webhook/testcases/testdata/testcases/<source>\033[0m"
echo "\n\033[1;31m⚠️ Action Required: Please verify the generated test cases and commit again ⚠️\033[0m\n"
exit 1
fi
fi

# If we get here, either no test files changed or no new Go files were generated
npm run pre-commit
25 changes: 21 additions & 4 deletions go/webhook/testcases/testcases.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testcases

import (
"bytes"
"embed"
"encoding/json"
"io/fs"
Expand Down Expand Up @@ -30,12 +31,17 @@ type Case struct {

type Input struct {
Request Request
Source Source
}

type Source struct {
Config string `json:"config"`
}
type Request struct {
Method string
RawQuery string `json:"query_parameters"`
RawQuery map[string][]string `json:"query"`
Headers map[string]string
Body json.RawMessage
Body string
}

type Output struct {
Expand Down Expand Up @@ -81,11 +87,22 @@ func Load(t *testing.T) Setup {
}
defer f.Close()

var tc Case
err = json.NewDecoder(f).Decode(&tc)
// Read the entire file first
rawJSON, err := fs.ReadFile(testdata, path)
if err != nil {
return err
}

// Compact the JSON to remove whitespace
buffer := new(bytes.Buffer)
if err := json.Compact(buffer, rawJSON); err != nil {
return err
}

var tc Case
if err := json.NewDecoder(buffer).Decode(&tc); err != nil {
return err
}
tcs = append(tcs, tc)

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@
"description": "Simple track call",
"input": {
"request": {
"body": {
"id": "adjust",
"query_parameters": {
"gps_adid": ["38400000-8cf0-11bd-b23e-10b96e40000d"],
"adid": ["18546f6171f67e29d1cb983322ad1329"],
"tracker_token": ["abc"],
"custom": ["custom"],
"tracker_name": ["dummy"],
"created_at": ["1404214665"],
"event_name": ["Click"]
},
"updated_at": "2023-02-10T12:16:07.251Z",
"created_at": "2023-02-10T12:05:04.402Z"
"query": {
"gps_adid": ["38400000-8cf0-11bd-b23e-10b96e40000d"],
"adid": ["18546f6171f67e29d1cb983322ad1329"],
"tracker_token": ["abc"],
"custom": ["custom"],
"tracker_name": ["dummy"],
"created_at": ["1404214665"],
"event_name": ["Click"]
},
"body": "{\"id\":\"adjust\",\"updated_at\":\"2023-02-10T12:16:07.251Z\",\"created_at\":\"2023-02-10T12:05:04.402Z\"}",
"headers": {
"Content-Type": "application/json"
},
"method": "GET"
"method": "POST"
},
"source": {
"config": "{}"
}
},
"output": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
"description": "Simple track call with no query parameters",
"input": {
"request": {
"body": {
"id": "adjust",
"updated_at": "2023-02-10T12:16:07.251Z",
"created_at": "2023-02-10T12:05:04.402Z"
},
"query": {},
"body": "{\"id\":\"adjust\",\"updated_at\":\"2023-02-10T12:16:07.251Z\",\"created_at\":\"2023-02-10T12:05:04.402Z\"}",
"headers": {
"Content-Type": "application/json"
},
"method": "GET"
"method": "POST"
},
"source": {
"config": "{}"
}
},
"output": {
"response": {
"status": 400,
"body": "Query_parameters is missing"
"body": "Query_parameters is missing\n"
},
"queue": [],
"errQueue": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "adjust",
"description": "Simple track call with wrong created at",
"input": {
"request": {
"query": {
"gps_adid": ["38400000-8cf0-11bd-b23e-10b96e40000d"],
"adid": ["18546f6171f67e29d1cb983322ad1329"],
"tracker_token": ["abc"],
"custom": ["custom"],
"tracker_name": ["dummy"],
"created_at": ["test"],
"event_name": ["Click"]
},
"body": "{\"id\":\"adjust\",\"updated_at\":\"2023-02-10T12:16:07.251Z\",\"created_at\":\"test\"}",
"headers": {
"Content-Type": "application/json"
},
"method": "POST"
},
"source": {
"config": "{}"
}
},
"output": {
"response": {
"status": 400,
"body": "Failed to parse timestamp: \"test\"\n"
},
"queue": [],
"errQueue": [
{
"id": "adjust",
"updated_at": "2023-02-10T12:16:07.251Z",
"created_at": "test"
}
]
},
"skip": "FIXME"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
"description": "test-0",
"input": {
"request": {
"body": {
"text": "Hello from your abc-test app in App Center!",
"sent_at": "2023-01-02T07: 53: 28.3117824Z",
"url": "https://appcenter.ms/users/abc-rudderstack.com/apps/abc-test"
},
"query": {},
"body": "{\"text\":\"Hello from your abc-test app in App Center!\",\"sent_at\":\"2023-01-02T07: 53: 28.3117824Z\",\"url\":\"https://appcenter.ms/users/abc-rudderstack.com/apps/abc-test\"}",
"headers": {
"Content-Type": "application/json"
}
},
"method": "POST"
},
"source": {
"config": "{}"
}
},
"output": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,15 @@
"description": "test-1",
"input": {
"request": {
"body": {
"app_name": "MSAppCenterTesting",
"branch": "master",
"build_status": "Succeeded",
"build_id": "1",
"build_link": "https://appcenter.ms/users/venkat-rudderstack.com/apps/MSAppCenterTesting/build/branches/master/builds/1",
"build_reason": "manual",
"finish_time": "2021-03-02T16:41:29.891411Z",
"icon_link": null,
"notification_settings_link": "https://appcenter.ms/users/venkat-rudderstack.com/apps/MSAppCenterTesting/settings/notifications",
"os": "Android",
"start_time": "2021-03-02T16:34:13.9184874Z",
"source_version": "7ed5c7b279316f19e9a0c45bb0fb49c0655471af",
"sent_at": "2021-03-02T16:41:55.8819564Z"
},
"query": {},
"body": "{\"app_name\":\"MSAppCenterTesting\",\"branch\":\"master\",\"build_status\":\"Succeeded\",\"build_id\":\"1\",\"build_link\":\"https://appcenter.ms/users/venkat-rudderstack.com/apps/MSAppCenterTesting/build/branches/master/builds/1\",\"build_reason\":\"manual\",\"finish_time\":\"2021-03-02T16:41:29.891411Z\",\"icon_link\":null,\"notification_settings_link\":\"https://appcenter.ms/users/venkat-rudderstack.com/apps/MSAppCenterTesting/settings/notifications\",\"os\":\"Android\",\"start_time\":\"2021-03-02T16:34:13.9184874Z\",\"source_version\":\"7ed5c7b279316f19e9a0c45bb0fb49c0655471af\",\"sent_at\":\"2021-03-02T16:41:55.8819564Z\"}",
"headers": {
"Content-Type": "application/json"
}
},
"method": "POST"
},
"source": {
"config": "{}"
}
},
"output": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,15 @@
"description": "test-2",
"input": {
"request": {
"body": {
"app_name": "MSAppCenterTesting",
"branch": "master",
"build_status": "Broken",
"build_id": "2",
"build_link": "https://appcenter.ms/users/venkat-rudderstack.com/apps/MSAppCenterTesting/build/branches/master/builds/2",
"build_reason": "automatic",
"finish_time": "2021-03-02T16:52:04.2587506Z",
"icon_link": null,
"notification_settings_link": "https://appcenter.ms/users/venkat-rudderstack.com/apps/MSAppCenterTesting/settings/notifications",
"os": "Android",
"start_time": "2021-03-02T16:50:52.2584107Z",
"source_version": "0624e1e3e48eaf2371c37316208ff83bdd5c123b",
"sent_at": "2021-03-02T16:52:35.8848052Z"
},
"query": {},
"body": "{\"app_name\":\"MSAppCenterTesting\",\"branch\":\"master\",\"build_status\":\"Broken\",\"build_id\":\"2\",\"build_link\":\"https://appcenter.ms/users/venkat-rudderstack.com/apps/MSAppCenterTesting/build/branches/master/builds/2\",\"build_reason\":\"automatic\",\"finish_time\":\"2021-03-02T16:52:04.2587506Z\",\"icon_link\":null,\"notification_settings_link\":\"https://appcenter.ms/users/venkat-rudderstack.com/apps/MSAppCenterTesting/settings/notifications\",\"os\":\"Android\",\"start_time\":\"2021-03-02T16:50:52.2584107Z\",\"source_version\":\"0624e1e3e48eaf2371c37316208ff83bdd5c123b\",\"sent_at\":\"2021-03-02T16:52:35.8848052Z\"}",
"headers": {
"Content-Type": "application/json"
}
},
"method": "POST"
},
"source": {
"config": "{}"
}
},
"output": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,15 @@
"description": "test-3",
"input": {
"request": {
"body": {
"app_name": "MSAppCenterTesting",
"app_display_name": "MSAppCenterTesting",
"release_id": "1",
"platform": "Android",
"uploaded_at": "2021-03-02T17:49:35.463Z",
"fingerprint": "9cbdc86d96c5359d2af3972fdda46624",
"release_notes": "Degraded to 4.0.0",
"version": "1614707021",
"short_version": "1.0",
"min_os": "7.1",
"mandatory_update": true,
"size": 2919106,
"provisioning_profile_name": null,
"provisioning_profile_type": null,
"bundle_identifier": "tech.desusai.msappcentertesting",
"install_link": "https://install.appcenter.ms/users/venkat-rudderstack.com/apps/MSAppCenterTesting/releases/1?source=email",
"icon_link": "https://appcenter-filemanagement-distrib2ede6f06e.azureedge.net/dbbd3d57-9c09-448b-9782-0d57200f7c9b/ic_launcher.png?sv=2019-02-02&sr=c&sig=BNzQcMcvTbwf4fv59ByGiYXsr%2BA9PYDFyGJCqsE2RO0%3D&se=2021-03-09T17%3A49%3A35Z&sp=r",
"distribution_group_id": "00000000-0000-0000-0000-000000000000",
"installable": true,
"sent_at": "2021-03-02T17:49:37.127635Z",
"app_id": "ce8b5280-4605-4c1c-8c48-bd54c8fdda31"
},
"query": {},
"body": "{\"app_name\":\"MSAppCenterTesting\",\"app_display_name\":\"MSAppCenterTesting\",\"release_id\":\"1\",\"platform\":\"Android\",\"uploaded_at\":\"2021-03-02T17:49:35.463Z\",\"fingerprint\":\"9cbdc86d96c5359d2af3972fdda46624\",\"release_notes\":\"Degraded to 4.0.0\",\"version\":\"1614707021\",\"short_version\":\"1.0\",\"min_os\":\"7.1\",\"mandatory_update\":true,\"size\":2919106,\"provisioning_profile_name\":null,\"provisioning_profile_type\":null,\"bundle_identifier\":\"tech.desusai.msappcentertesting\",\"install_link\":\"https://install.appcenter.ms/users/venkat-rudderstack.com/apps/MSAppCenterTesting/releases/1?source=email\",\"icon_link\":\"https://appcenter-filemanagement-distrib2ede6f06e.azureedge.net/dbbd3d57-9c09-448b-9782-0d57200f7c9b/ic_launcher.png?sv=2019-02-02&sr=c&sig=BNzQcMcvTbwf4fv59ByGiYXsr%2BA9PYDFyGJCqsE2RO0%3D&se=2021-03-09T17%3A49%3A35Z&sp=r\",\"distribution_group_id\":\"00000000-0000-0000-0000-000000000000\",\"installable\":true,\"sent_at\":\"2021-03-02T17:49:37.127635Z\",\"app_id\":\"ce8b5280-4605-4c1c-8c48-bd54c8fdda31\"}",
"headers": {
"Content-Type": "application/json"
}
},
"method": "POST"
},
"source": {
"config": "{}"
}
},
"output": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,15 @@
"description": "test-4",
"input": {
"request": {
"body": {
"id": "1139624368u",
"name": "tech.desusai.msappcentertesting.MainActivity$1.onClick (MainActivity.java:25)",
"reason": "java.lang.ArithmeticException: divide by zero",
"file_name": null,
"line_number": null,
"url": "https://appcenter.ms/users/venkat-rudderstack.com/apps/MSAppCenterTesting/crashes/errors/1139624368u",
"app_display_name": "MSAppCenterTesting",
"app_platform": "Java",
"app_version": "1.0(1)",
"stack_trace": [
"tech.desusai.msappcentertesting.MainActivity$1.onClick (MainActivity.java:25);"
],
"affected_users": 0,
"crash_count": 0,
"sent_at": "2021-03-02T18:14:33.9713246Z",
"app_id": "ce8b5280-4605-4c1c-8c48-bd54c8fdda31"
},
"query": {},
"body": "{\"id\":\"1139624368u\",\"name\":\"tech.desusai.msappcentertesting.MainActivity$1.onClick (MainActivity.java:25)\",\"reason\":\"java.lang.ArithmeticException: divide by zero\",\"file_name\":null,\"line_number\":null,\"url\":\"https://appcenter.ms/users/venkat-rudderstack.com/apps/MSAppCenterTesting/crashes/errors/1139624368u\",\"app_display_name\":\"MSAppCenterTesting\",\"app_platform\":\"Java\",\"app_version\":\"1.0(1)\",\"stack_trace\":[\"tech.desusai.msappcentertesting.MainActivity$1.onClick (MainActivity.java:25);\"],\"affected_users\":0,\"crash_count\":0,\"sent_at\":\"2021-03-02T18:14:33.9713246Z\",\"app_id\":\"ce8b5280-4605-4c1c-8c48-bd54c8fdda31\"}",
"headers": {
"Content-Type": "application/json"
}
},
"method": "POST"
},
"source": {
"config": "{}"
}
},
"output": {
Expand Down
Loading
Loading