forked from jsonresume/resume-schema
-
Notifications
You must be signed in to change notification settings - Fork 0
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 jsonresume#33 from ss22ever/restructure
Add validator test
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
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 @@ | ||
package tests |
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,55 @@ | ||
package tests | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/resumic/schema/cmd/resumic/validate" | ||
) | ||
|
||
//TestValidatorValidExamples used to test valid JSON passed in ValidateJSON | ||
func TestValidatorValidExamples(t *testing.T) { | ||
files := run("../../../examples/valid") | ||
for _, file := range files { | ||
fmt.Println("In %s:", file) | ||
result := validate.ValidateJSON(file) | ||
if result != true { | ||
t.Errorf("Expected valid state, got error") | ||
} | ||
} | ||
|
||
} | ||
|
||
//TestValidatorInValidExamples used to test valid JSON passed in ValidateJSON | ||
func TestValidatorInvalidExamples(t *testing.T) { | ||
files := run("../../../examples/invalid") | ||
for _, file := range files { | ||
fmt.Println("In %s:", file) | ||
result := validate.ValidateJSON(file) | ||
if result != false { | ||
t.Errorf("Expected invalid state, got valid") | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
func run(searchDir string) []string { | ||
ext := ".json" | ||
fileList := make([]string, 0) | ||
e := filepath.Walk(searchDir, func(path string, f os.FileInfo, err error) error { | ||
if filepath.Ext(path) == ext { | ||
fileList = append(fileList, path) | ||
} | ||
|
||
return err | ||
}) | ||
|
||
if e != nil { | ||
panic(e) | ||
} | ||
|
||
return fileList | ||
} |