Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
yajsv - Yet Another Json Schema Validator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
SmartDataLab
public
CI-CD tools
yajsv - Yet Another Json Schema Validator
Commits
717589cb
Commit
717589cb
authored
5 years ago
by
Ken Brooks
Browse files
Options
Downloads
Patches
Plain Diff
attempting to make a universal test
parent
896f3e4c
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
main.go
+9
-3
9 additions, 3 deletions
main.go
main_test.go
+81
-7
81 additions, 7 deletions
main_test.go
main_windows_test.go
+0
-118
0 additions, 118 deletions
main_windows_test.go
with
90 additions
and
128 deletions
main.go
+
9
−
3
View file @
717589cb
...
...
@@ -70,6 +70,7 @@ func realMain(args []string) int {
if
!
filepath
.
IsAbs
(
pattern
)
{
pattern
=
filepath
.
Join
(
dir
,
pattern
)
}
docs
=
append
(
docs
,
glob
(
pattern
)
...
)
}
if
err
:=
scanner
.
Err
();
err
!=
nil
{
...
...
@@ -90,7 +91,7 @@ func realMain(args []string) int {
for
_
,
p
:=
range
glob
(
ref
)
{
absPath
,
absPathErr
:=
filepath
.
Abs
(
p
)
if
absPathErr
!=
nil
{
log
.
Fatalf
(
"%s: unable to convert to absolute path: %s
\n
"
,
absPath
,
e
rr
)
log
.
Fatalf
(
"%s: unable to convert to absolute path: %s
\n
"
,
absPath
,
absPathE
rr
)
}
if
absPath
==
schemaPath
{
...
...
@@ -124,6 +125,7 @@ func realMain(args []string) int {
failures
:=
make
([]
string
,
0
)
errors
:=
make
([]
string
,
0
)
for
_
,
p
:=
range
docs
{
//fmt.Println(p)
wg
.
Add
(
1
)
go
func
(
path
string
)
{
defer
wg
.
Done
()
...
...
@@ -233,14 +235,18 @@ func glob(pattern string) []string {
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
universalPaths
:=
make
([]
string
,
0
)
paths
,
err
:=
filepath
.
Glob
(
pattern
)
for
_
,
mypath
:=
range
paths
{
universalPaths
=
append
(
universalPaths
,
filepath
.
ToSlash
(
mypath
))
}
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
if
len
(
p
aths
)
==
0
{
if
len
(
universalP
aths
)
==
0
{
log
.
Fatalf
(
"%s: no such file or directory"
,
pattern
)
}
return
p
aths
return
universalP
aths
}
type
stringFlags
[]
string
...
...
This diff is collapsed.
Click to expand it.
main_test.go
+
81
−
7
View file @
717589cb
// +build !windows
// +build
windows
!windows
package
main
...
...
@@ -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,21 +69,50 @@ 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
)
}
// Output:
// testdata/data-error.json: error: invalid character 'o' in literal null (expecting 'u')
// testdata/data-error.json: error:
validate:
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/data-error.yml: error: 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
)
}
// Unordered output:
// testdata/data-error.json: error: invalid character 'o' in literal null (expecting 'u')
// testdata/data-error.json: error:
validate:
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/data-fail.yml: fail: (root): foo is required
//
// testdata/data-error.yml: error: load doc yaml: found unexpected end of stream
}
This diff is collapsed.
Click to expand it.
main_windows_test.go
deleted
100644 → 0
+
0
−
118
View file @
896f3e4c
// +build windows
package
main
import
(
"log"
)
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
)
}
// Output:
// testdata\data-pass.json: pass
}
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
)
}
// Output:
// testdata\data-fail.json: fail: (root): foo is required
}
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
)
}
// Output:
// testdata\data-error.json: error: validate: invalid character 'o' in literal null (expecting 'u')
}
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\data-error.yml: error: 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
)
}
// Unordered output:
// testdata\data-error.json: error: validate: 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\data-error.yml: error: load doc yaml: found unexpected end of stream
//
// testdata\data-fail.yml: fail: (root): foo is required
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment