-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #895 from matthias-pichler-warrify/matthias-pichle…
…r/invalid-do-switch-894 Make do an array
- Loading branch information
Showing
32 changed files
with
1,281 additions
and
989 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2023-Present The Serverless Workflow Specification Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { SWSchemaValidator } from "./index"; | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
import marked from "marked"; | ||
|
||
SWSchemaValidator.prepareSchemas(); | ||
|
||
const dslReferencePath = path.join( | ||
__dirname, | ||
"..", | ||
"..", | ||
"..", | ||
"dsl-reference.md" | ||
); | ||
|
||
describe(`Verify every example in the dsl docs`, () => { | ||
const workflows = marked | ||
.lexer(fs.readFileSync(dslReferencePath, SWSchemaValidator.defaultEncoding)) | ||
.filter((item): item is marked.Tokens.Code => item.type === "code") | ||
.filter((item) => item.lang === "yaml") | ||
.map((item) => item.text) | ||
.map((text) => SWSchemaValidator.yamlToJSON(text)) | ||
.filter((workflow) => typeof workflow === "object") | ||
.filter((workflow) => "document" in workflow) | ||
.filter((workflow) => "dsl" in workflow.document); | ||
|
||
test.each(workflows)("$document.name", (workflow) => { | ||
const results = SWSchemaValidator.validateSchema(workflow); | ||
if (results?.errors) { | ||
console.warn( | ||
`Schema validation on workflow ${workflow.document.name} failed with: `, | ||
JSON.stringify(results.errors, null, 2) | ||
); | ||
} | ||
expect(results?.valid).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2023-Present The Serverless Workflow Specification Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { SWSchemaValidator } from "./index"; | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
|
||
SWSchemaValidator.prepareSchemas(); | ||
|
||
const invalidPath = "../test/fixtures/invalid"; | ||
|
||
describe(`Check that invalid workflows are rejected`, () => { | ||
const examples = fs | ||
.readdirSync(path.join(__dirname, invalidPath), { | ||
encoding: SWSchemaValidator.defaultEncoding, | ||
recursive: false, | ||
withFileTypes: true, | ||
}) | ||
.filter((file) => file.isFile()) | ||
.filter((file) => file.name.endsWith(".yaml")) | ||
.map((file) => file.name); | ||
|
||
test.each(examples)("Example %s", (file) => { | ||
const workflow = SWSchemaValidator.loadAsJSON( | ||
path.join(__dirname, `${invalidPath}/${file}`) | ||
); | ||
const results = SWSchemaValidator.validateSchema(workflow); | ||
expect(results?.valid).toBeFalsy(); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
.ci/validation/test/fixtures/invalid/extra-property-in-call.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
document: | ||
dsl: 1.0.0-alpha1 | ||
namespace: examples | ||
name: two-tasks-in-one-item | ||
version: 1.0.0-alpha1 | ||
do: | ||
- getPet: | ||
call: http | ||
with: | ||
method: get | ||
endpoint: https://petstore.swagger.io/v2/pet/{petId} | ||
foo: bar |
14 changes: 14 additions & 0 deletions
14
.ci/validation/test/fixtures/invalid/two-tasks-in-one-item.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
document: | ||
dsl: 1.0.0-alpha1 | ||
namespace: examples | ||
name: two-tasks-in-one-item | ||
version: 1.0.0-alpha1 | ||
do: | ||
- getPet: | ||
call: http | ||
with: | ||
method: get | ||
endpoint: https://petstore.swagger.io/v2/pet/{petId} | ||
setMessage: | ||
set: | ||
message: "Looking for {petId}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Feature: Composite Task | ||
As an implementer of the workflow DSL | ||
I want to ensure that composite tasks can be executed within the workflow | ||
So that my implementation conforms to the expected behavior | ||
|
||
# Tests composite tasks With competing concurrent sub tasks | ||
Scenario: Fork Task With Competing Concurrent Sub Tasks | ||
Given a workflow with definition: | ||
"""yaml | ||
document: | ||
dsl: 1.0.0-alpha1 | ||
namespace: default | ||
name: fork | ||
do: | ||
- branchWithCompete: | ||
fork: | ||
compete: true | ||
branches: | ||
- setRed: | ||
set: | ||
colors: ${ .colors + ["red"] } | ||
- setGreen: | ||
set: | ||
colors: ${ .colors + ["green"] } | ||
- setBlue: | ||
set: | ||
colors: ${ .colors + ["blue"] } | ||
""" | ||
When the workflow is executed | ||
Then the workflow should complete | ||
And the workflow output should have a 'colors' property containing 1 items |
Oops, something went wrong.