Links
Comment on page
🔬

Testing Transforms

Transforms can be tested as you develop them by using the runreveal transform test command.
This command requires the argument --file or -f which will specify the code that you want to test. Along with the source code is the data you'd like transform.
$ runreveal
When running the transform command, the entire Event that we store gets printed, along with any errors that were encountered when executing your transform. Here's an example invocation of our tailscale transform.
$ transform test --file tailscale.py --data data.json
{
"Event": {
"id": "2QWXKsRgsoVos0W8RGpZySpGUW0",
"workspace_id": "2KUOdhvRReF5RZfQX8ILneT4fSd",
"source_type": "webhook",
"source_id": "1",
"log": {
"data": {
"actor": "[email protected]",
"deviceName": "ip-172-30-1-102.tail9287b.ts.net",
"managedBy": "tag:production",
"nodeID": "n79eR77CNTRL",
"url": "https://login.tailscale.com/admin/machines/100.115.73.73"
},
"message": "Node ip-172-30-1-102.tail9287b.ts.net created",
"tailnet": "runreveal.com",
"timestamp": "2023-05-23T15:54:23.498133536Z",
"type": "nodeCreated",
"version": 1
},
"raw_log": "eyJ0aW1lc3RhbXAiOiIyMDIzLTA1LTIzVDE1OjU0OjIzLjQ5ODEzMzUzNloiLCJ2ZXJzaW9uIjoxLCJ0eXBlIjoibm9kZUNyZWF0ZWQiLCJ0YWlsbmV0IjoicnVucmV2ZWFsLmNvbSIsIm1lc3NhZ2UiOiJOb2RlIGlwLTE3Mi0zMC0xLTEwMi50YWlsOTI4N2IudHMubmV0IGNyZWF0ZWQiLCJkYXRhIjp7Im5vZGVJRCI6Im43OWVSNzdDTlRSTCIsInVybCI6Imh0dHBzOi8vbG9naW4udGFpbHNjYWxlLmNvbS9hZG1pbi9tYWNoaW5lcy8xMDAuMTE1LjczLjczIiwiZGV2aWNlTmFtZSI6ImlwLTE3Mi0zMC0xLTEwMi50YWlsOTI4N2IudHMubmV0IiwibWFuYWdlZEJ5IjoidGFnOnByb2R1Y3Rpb24iLCJhY3RvciI6ImV2YW5AcnVucmV2ZWFsLmNvbSJ9fQo=",
"normalized": {
"id": "",
"event_time": "2023-05-23T15:54:23Z",
"event_name": "nodeCreated",
"read_only": false,
"actor": {},
"src": {},
"dst": {},
"tags": {
"device_name": "n79eR77CNTRL",
"node_id": "n79eR77CNTRL",
"tailnet": "runreveal.com",
}
}
},
"Error": ""
}

Printing Errors

If a python error exists while running your transform, the results of that error can be pretty printed using the jq command. Piping the output of the command to jq -r .Error will pretty print the results of Error including all python formatting.
$ ./dist/runreveal/runreveal transform test --file bad-transform.py --data data.json | jq -r .Error
Traceback (most recent call last):
File "/transform.py", line 75, in main
resp = v.transform(evt)
^^^^^^^^^^^^^^^^
File "/test-transform.py", line 2, in transform
return false
^^^^^
NameError: name 'false' is not defined
:) cat bad-transform.py
def transform(event):
return false