Skip to content
Snippets Groups Projects
Commit 8f23de46 authored by Ken Brooks's avatar Ken Brooks
Browse files

adding tests for the yaml side

parent 69ff3e0d
No related branches found
No related tags found
No related merge requests found
yajsv
build/
coverage.out
\ No newline at end of file
......@@ -81,7 +81,7 @@ func realMain(args []string) int {
}
}
if len(docs) == 0 {
return usageError("no JSON documents to validate")
return usageError("no documents to validate")
}
// Compile target schema
......@@ -129,8 +129,10 @@ func realMain(args []string) int {
loader, err := jsonLoader(path)
if err != nil {
log.Fatalf("%s: unable to load doc: %s\n", *schemaFlag, err)
}
msg := fmt.Sprintf("%s: unable to load doc: %s\n", *schemaFlag, err)
fmt.Println(msg)
errors = append(errors, msg)
} else {
result, err := schema.Validate(loader)
switch {
case err != nil:
......@@ -150,6 +152,7 @@ func realMain(args []string) int {
case !*quietFlag:
fmt.Printf("%s: pass\n", path)
}
}
}(p)
}
wg.Wait()
......
......@@ -6,7 +6,25 @@ import (
"log"
)
func ExampleMain_pass() {
func ExampleMain_pass_ymlschema_ymldoc() {
exit := realMain([]string{"-s", "testdata\\schema.yml", "testdata\\data-pass.yml"})
if exit != 0 {
log.Fatalf("exit: got %d, want 0", exit)
}
// Output:
// testdata\data-pass.yml: pass
}
func ExampleMain_pass_jsonschema_ymldoc() {
exit := realMain([]string{"-s", "testdata\\schema.json", "testdata\\data-pass.yml"})
if exit != 0 {
log.Fatalf("exit: got %d, want 0", exit)
}
// Output:
// testdata\data-pass.yml: pass
}
func ExampleMain_pass_jsonschema_jsondoc() {
exit := realMain([]string{"-s", "testdata\\schema.json", "testdata\\data-pass.json"})
if exit != 0 {
log.Fatalf("exit: got %d, want 0", exit)
......@@ -15,7 +33,34 @@ func ExampleMain_pass() {
// testdata\data-pass.json: pass
}
func ExampleMain_fail() {
func ExampleMain_pass_ymlschema_jsondoc() {
exit := realMain([]string{"-s", "testdata\\schema.yml", "testdata\\data-pass.json"})
if exit != 0 {
log.Fatalf("exit: got %d, want 0", exit)
}
// Output:
// testdata\data-pass.json: pass
}
func ExampleMain_fail_ymlschema_ymldoc() {
exit := realMain([]string{"-q", "-s", "testdata\\schema.yml", "testdata\\data-fail.yml"})
if exit != 1 {
log.Fatalf("exit: got %d, want 1", exit)
}
// Output:
// testdata\data-fail.yml: fail: (root): foo is required
}
func ExampleMain_fail_jsonschema_ymldoc() {
exit := realMain([]string{"-q", "-s", "testdata\\schema.json", "testdata\\data-fail.yml"})
if exit != 1 {
log.Fatalf("exit: got %d, want 1", exit)
}
// Output:
// testdata\data-fail.yml: fail: (root): foo is required
}
func ExampleMain_fail_jsonschema_jsondoc() {
exit := realMain([]string{"-q", "-s", "testdata\\schema.json", "testdata\\data-fail.json"})
if exit != 1 {
log.Fatalf("exit: got %d, want 1", exit)
......@@ -24,7 +69,16 @@ func ExampleMain_fail() {
// testdata\data-fail.json: fail: (root): foo is required
}
func ExampleMain_error() {
func ExampleMain_fail_ymlschema_jsondoc() {
exit := realMain([]string{"-q", "-s", "testdata\\schema.yml", "testdata\\data-fail.json"})
if exit != 1 {
log.Fatalf("exit: got %d, want 1", exit)
}
// Output:
// testdata\data-fail.json: fail: (root): foo is required
}
func ExampleMain_error_jsonschema_jsondoc() {
exit := realMain([]string{"-q", "-s", "testdata\\schema.json", "testdata\\data-error.json"})
if exit != 2 {
log.Fatalf("exit: got %d, want 2", exit)
......@@ -33,7 +87,16 @@ func ExampleMain_error() {
// testdata\data-error.json: error: invalid character 'o' in literal null (expecting 'u')
}
func ExampleMain_glob() {
func ExampleMain_error_ymlschema_ymldoc() {
exit := realMain([]string{"-q", "-s", "testdata\\schema.yml", "testdata\\data-error.yml"})
if exit != 2 {
log.Fatalf("exit: got %d, want 2", exit)
}
// Output:
// testdata\schema.yml: unable to load doc: yaml: found unexpected end of stream
}
func ExampleMain_glob_jsonschema_jsondoc() {
exit := realMain([]string{"-q", "-s", "testdata\\schema.json", "testdata\\data-*.json"})
if exit != 3 {
log.Fatalf("exit: got %d, want 3", exit)
......@@ -42,3 +105,14 @@ func ExampleMain_glob() {
// testdata\data-error.json: error: invalid character 'o' in literal null (expecting 'u')
// testdata\data-fail.json: fail: (root): foo is required
}
func ExampleMain_glob_ymlschema_ymldoc() {
exit := realMain([]string{"-q", "-s", "testdata\\schema.yml", "testdata\\data-*.yml"})
if exit != 3 {
log.Fatalf("exit: got %d, want 3", exit)
}
// Unordered output:
// testdata\schema.yml: unable to load doc: yaml: found unexpected end of stream
//
// testdata\data-fail.yml: fail: (root): foo is required
}
invalid: "an escaped \' single quote is not valid yaml
\ No newline at end of file
---
bar: missing foo
---
foo: asdf
bar: zxcv
---
properties:
foo:
type: string
bar: {}
required:
- foo
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment