Skip to content

introduce variablesToOverwrite #445

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

Merged
merged 3 commits into from
Mar 7, 2025
Merged
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ See the [docs](https://octomind.dev/docs) for more details.
environmentName: <environment name that your test cases should run against. optional,
will use the "default" environment otherwise.>
blocking: <if your pipeline should block until all tests have passed, optional, defaults to false>
variablesToOverwrite: <multiline string in the form of VARIABLE_NAME:value per line>
tags: <if only a subset of your tests should be executed use this multiline string, with one tag per line>
```

Expand All @@ -33,6 +34,7 @@ By default the task will run a maximum duration of 2 hours before it will fail w
- 2024-10-18: Added blocking parameter to allow blocking your pipeline until all tests have passed.
- 2024-10-30: Added environment name parameter to allow running your tests against a specified environment, uses the
default environment if not specified.
- 2025-02-05: Added variablesToOverwrite parameter, we will use the provided variable values instead of the ones defined in the environment for this test run.
- 2025-02-19: Added tags parameter, we will only execute test cases that have at least one matching tag.

## Publishing notes
Expand Down
20 changes: 19 additions & 1 deletion automagicallyexecute/src/executeAutomagically.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {ExecuteResponse, TestReport} from './types.js'
import {
debug,
getBoolInput,
getDelimitedInput,
getEndpointAuthorizationParameter,
getInput,
getDelimitedInput,
getInputRequired,
getVariable,
setResult,
Expand All @@ -31,6 +31,18 @@ const getTestReportApiUrl = (
) =>
`${automagicallyUrl}/api/apiKey/v2/test-targets/${testTargetId}/test-reports/${testReportId}`

const multilineMappingToObject = (
input: string[]
): Record<string, string[]> => {
const keySplitOff = input
.filter(mapping => mapping.length > 0)
.map(mapping => mapping.split(':'))
// the api takes an array of values per key, so we just wrap the value in an array
// then we join with ':' to make it a string again and preserve colons in the value
.map(parts => [parts[0], [parts.slice(1).join(':')]])
return Object.fromEntries(keySplitOff)
}

export const executeAutomagically = async ({
pollingIntervalInMilliseconds = TIME_BETWEEN_POLLS_MILLISECONDS,
maximumPollingTimeInMilliseconds = MAXIMUM_POLL_TIME_MILLISECONDS
Expand All @@ -44,6 +56,11 @@ export const executeAutomagically = async ({
const environmentName = getInput('environmentName')
const tags = getDelimitedInput('tags', '\n')

const variablesToOverwrite = getDelimitedInput('variablesToOverwrite', '\n')
const variablesToOverwriteObject = variablesToOverwrite
? multilineMappingToObject(variablesToOverwrite)
: undefined

const blocking = getBoolInput('blocking')
// https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables
const collectionUri = getVariable('System.TeamFoundationCollectionUri')
Expand Down Expand Up @@ -91,6 +108,7 @@ export const executeAutomagically = async ({
url,
testTargetId,
environmentName,
variablesToOverwrite: variablesToOverwriteObject,
tags,
context: {
source: 'azureDevOps',
Expand Down
9 changes: 8 additions & 1 deletion automagicallyexecute/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"author": "OctoMind GmbH",
"version": {
"Major": 2,
"Minor": 3,
"Minor": 4,
"Patch": 0
},
"instanceNameFormat": "Execute Automagically",
Expand Down Expand Up @@ -48,6 +48,13 @@
"required": false,
"helpMarkDown": "(Optional) which environment your tests should be executed against. Will use the 'default' environment if not defined"
},
{
"name": "variablesToOverwrite",
"type": "multiLine",
"label": "Variables to Overwrite",
"required": false,
"helpMarkDown": "(Optional) Variable values to use for this test run. Format: KEY1:value1\nKEY2:value2"
},
{
"name": "tags",
"type": "multiLine",
Expand Down
28 changes: 28 additions & 0 deletions automagicallyexecute/tests/executeAutomagically.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {beforeEach, describe, expect, it, vi} from 'vitest'
import {fetchJson} from '../src/fetchJson'
import {
getBoolInput,
getDelimitedInput,
getEndpointAuthorizationParameter,
getInput,
getInputRequired,
Expand Down Expand Up @@ -49,6 +50,33 @@ describe(executeAutomagically.name, () => {
expect(getInput).toHaveBeenCalledWith('environmentName')
})

it('includes variablesToOverwrite name if defined and preserves colons in the values', async () => {
const variablesToOverwrite = ['key1:value1', 'key2:value:2']
vi.mocked(getDelimitedInput).mockReturnValue(variablesToOverwrite)

await executeAutomagically()

expect(fetchJson).toHaveBeenCalledWith(
expect.objectContaining({
method: 'POST'
})
)

const sentBody = JSON.parse(
vi.mocked(fetchJson).mock.calls[0][0].body as string
)

expect(sentBody).toEqual(
expect.objectContaining({
variablesToOverwrite: {
key1: ['value1'],
key2: ['value:2']
}
})
)
expect(getDelimitedInput).toHaveBeenCalledWith('variablesToOverwrite', '\n')
})

it("executes and DOESN'T wait if it's not blocking", async () => {
await executeAutomagically()

Expand Down
Loading