Skip to content

Commit dc73964

Browse files
committed
test: Start YAML testcases for multi-doc & other edges
Signed-off-by: Robin H. Johnson <rjohnson@coreweave.com>
1 parent 45fd7be commit dc73964

File tree

6 files changed

+221
-0
lines changed

6 files changed

+221
-0
lines changed

test/validate/fail_second_yaml.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
TMP="$(mktemp -d)"
7+
clean() { rm -rf "$TMP"; }
8+
trap clean EXIT
9+
10+
cat << 'EOF' > "$TMP/schema.yaml"
11+
$schema: https://json-schema.org/draft/2019-09/schema
12+
type: object
13+
properties:
14+
foo:
15+
type: string
16+
EOF
17+
18+
cat << 'EOF' > "$TMP/instance.yaml"
19+
---
20+
foo: "good"
21+
---
22+
foo: 1
23+
EOF
24+
25+
"$1" validate "$TMP/schema.yaml" "$TMP/instance.yaml" 2> "$TMP/stderr.txt" \
26+
&& EXIT_CODE="$?" || EXIT_CODE="$?"
27+
test "$EXIT_CODE" = "2" || exit 1
28+
29+
cat << EOF > "$TMP/expected.txt"
30+
fail: $(realpath "$TMP")/instance.yaml
31+
error: Schema validation failure
32+
The value was expected to be of type string but it was of type integer
33+
at instance location "/foo" (line 1, column 1)
34+
at evaluate path "/properties/foo/type"
35+
The object value was expected to validate against the single defined property subschema
36+
at instance location "" (line 1, column 1)
37+
at evaluate path "/properties"
38+
EOF
39+
40+
diff -NuarwbB "$TMP/stderr.txt" "$TMP/expected.txt"
41+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
TMP="$(mktemp -d)"
7+
clean() { rm -rf "$TMP"; }
8+
trap clean EXIT
9+
10+
cat << 'EOF' > "$TMP/schema.yaml"
11+
$schema: https://json-schema.org/draft/2019-09/schema
12+
type: object
13+
properties:
14+
foo:
15+
type: string
16+
EOF
17+
18+
cat << 'EOF' > "$TMP/instance.yaml"
19+
---
20+
foo: "good"
21+
---
22+
foo: 1
23+
EOF
24+
25+
"$1" validate "$TMP/schema.yaml" "$TMP/instance.yaml" 2> "$TMP/stderr.txt" \
26+
&& EXIT_CODE="$?" || EXIT_CODE="$?"
27+
test "$EXIT_CODE" = "2" || exit 1
28+
29+
cat << EOF > "$TMP/expected.txt"
30+
fail: $(realpath "$TMP")/instance.yaml
31+
error: Schema validation failure
32+
The value was expected to be of type string but it was of type integer
33+
at instance location "/foo" (line 1, column 1)
34+
at evaluate path "/properties/foo/type"
35+
The object value was expected to validate against the single defined property subschema
36+
at instance location "" (line 1, column 1)
37+
at evaluate path "/properties"
38+
EOF
39+
40+
diff -NuarwbB "$TMP/stderr.txt" "$TMP/expected.txt"
41+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/sh
2+
# This test is very similar to fail_yaml.sh, with the key different being the
3+
# extra document start marker; causing the line numbers to be off-by-one.
4+
5+
set -o errexit
6+
set -o nounset
7+
8+
TMP="$(mktemp -d)"
9+
clean() { rm -rf "$TMP"; }
10+
trap clean EXIT
11+
12+
cat << 'EOF' > "$TMP/schema.yaml"
13+
$schema: https://json-schema.org/draft/2019-09/schema
14+
type: object
15+
properties:
16+
foo:
17+
type: string
18+
EOF
19+
20+
cat << 'EOF' > "$TMP/instance.yaml"
21+
---
22+
foo: 1
23+
EOF
24+
25+
"$1" validate "$TMP/schema.yaml" "$TMP/instance.yaml" 2> "$TMP/stderr.txt" \
26+
&& EXIT_CODE="$?" || EXIT_CODE="$?"
27+
test "$EXIT_CODE" = "2" || exit 1
28+
29+
cat << EOF > "$TMP/expected.txt"
30+
fail: $(realpath "$TMP")/instance.yaml
31+
error: Schema validation failure
32+
The value was expected to be of type string but it was of type integer
33+
at instance location "/foo" (line 2, column 1)
34+
at evaluate path "/properties/foo/type"
35+
The object value was expected to validate against the single defined property subschema
36+
at instance location "" (line 2, column 1)
37+
at evaluate path "/properties"
38+
EOF
39+
40+
diff "$TMP/stderr.txt" "$TMP/expected.txt"

test/validate/pass_second_yaml.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
TMP="$(mktemp -d)"
7+
clean() { rm -rf "$TMP"; }
8+
trap clean EXIT
9+
10+
cat << 'EOF' > "$TMP/schema.yaml"
11+
$schema: https://json-schema.org/draft/2019-09/schema
12+
type: object
13+
properties:
14+
foo:
15+
type: string
16+
EOF
17+
18+
cat << 'EOF' > "$TMP/instance.yaml"
19+
---
20+
foo: "good"
21+
---
22+
foo: "also good"
23+
EOF
24+
25+
"$1" validate "$TMP/schema.yaml" "$TMP/instance.yaml" 2> "$TMP/stderr.txt" \
26+
&& EXIT_CODE="$?" || EXIT_CODE="$?"
27+
test "$EXIT_CODE" = "0" || exit 1
28+
29+
# Should be empty
30+
cat << EOF > "$TMP/expected.txt"
31+
EOF
32+
33+
diff -NuarwbB "$TMP/stderr.txt" "$TMP/expected.txt"
34+
35+

test/validate/pass_yaml.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
TMP="$(mktemp -d)"
7+
clean() { rm -rf "$TMP"; }
8+
trap clean EXIT
9+
10+
cat << 'EOF' > "$TMP/schema.yaml"
11+
$schema: https://json-schema.org/draft/2019-09/schema
12+
type: object
13+
properties:
14+
foo:
15+
type: string
16+
EOF
17+
18+
cat << 'EOF' > "$TMP/instance.yaml"
19+
foo: "test"
20+
EOF
21+
22+
"$1" validate "$TMP/schema.yaml" "$TMP/instance.yaml" 2> "$TMP/stderr.txt" \
23+
&& EXIT_CODE="$?" || EXIT_CODE="$?"
24+
test "$EXIT_CODE" = "0" || exit 1
25+
26+
cat << EOF > "$TMP/expected.txt"
27+
EOF
28+
29+
diff "$TMP/stderr.txt" "$TMP/expected.txt"
30+

test/validate/pass_yaml_verbose.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
TMP="$(mktemp -d)"
7+
clean() { rm -rf "$TMP"; }
8+
trap clean EXIT
9+
10+
cat << 'EOF' > "$TMP/schema.yaml"
11+
$schema: https://json-schema.org/draft/2019-09/schema
12+
type: object
13+
properties:
14+
foo:
15+
type: string
16+
EOF
17+
18+
cat << 'EOF' > "$TMP/instance.yaml"
19+
foo: "test"
20+
EOF
21+
22+
"$1" validate --verbose "$TMP/schema.yaml" "$TMP/instance.yaml" 2> "$TMP/stderr.txt" \
23+
&& EXIT_CODE="$?" || EXIT_CODE="$?"
24+
test "$EXIT_CODE" = "0" || exit 1
25+
26+
cat << EOF > "$TMP/expected.txt"
27+
ok: $(realpath "$TMP")/instance.yaml
28+
matches $(realpath "$TMP")/schema.yaml
29+
annotation: "foo"
30+
at instance location "" (line 1, column 1)
31+
at evaluate path "/properties"
32+
EOF
33+
34+
diff "$TMP/stderr.txt" "$TMP/expected.txt"

0 commit comments

Comments
 (0)