Skip to content

Commit 06fa87a

Browse files
test: add invalid workflows
Signed-off-by: Matthias Pichler <[email protected]>
1 parent 470709a commit 06fa87a

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

.ci/validation/src/examples.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe(`Verify every example in the repository`, () => {
3838
path.join(__dirname, `${examplePath}/${file}`)
3939
);
4040
const results = SWSchemaValidator.validateSchema(workflow);
41-
if (results?.errors != null) {
41+
if (results?.errors) {
4242
console.warn(
4343
`Schema validation on ${file} failed with: `,
4444
JSON.stringify(results.errors, null, 2)

.ci/validation/src/invalid.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2023-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { SWSchemaValidator } from "./index";
18+
import fs from "node:fs";
19+
import path from "node:path";
20+
21+
SWSchemaValidator.prepareSchemas();
22+
23+
const invalidPath = "../test/fixtures/invalid";
24+
25+
describe(`Check that invalid workflows are rejected`, () => {
26+
const examples = fs
27+
.readdirSync(path.join(__dirname, invalidPath), {
28+
encoding: SWSchemaValidator.defaultEncoding,
29+
recursive: false,
30+
withFileTypes: true,
31+
})
32+
.filter((file) => file.isFile())
33+
.filter((file) => file.name.endsWith(".yaml"))
34+
.map((file) => file.name);
35+
36+
test.each(examples)("Example %s", (file) => {
37+
const workflow = SWSchemaValidator.toJSON(
38+
path.join(__dirname, `${invalidPath}/${file}`)
39+
);
40+
const results = SWSchemaValidator.validateSchema(workflow);
41+
expect(results?.valid).toBeFalsy();
42+
});
43+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
document:
2+
dsl: 1.0.0-alpha1
3+
namespace: examples
4+
name: two-tasks-in-one-item
5+
version: 1.0.0-alpha1
6+
do:
7+
- getPet:
8+
call: http
9+
with:
10+
method: get
11+
endpoint: https://petstore.swagger.io/v2/pet/{petId}
12+
foo: bar
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
document:
2+
dsl: 1.0.0-alpha1
3+
namespace: examples
4+
name: two-tasks-in-one-item
5+
version: 1.0.0-alpha1
6+
do:
7+
- getPet:
8+
call: http
9+
with:
10+
method: get
11+
endpoint: https://petstore.swagger.io/v2/pet/{petId}
12+
setMessage:
13+
set:
14+
message: "Looking for {petId}"

0 commit comments

Comments
 (0)