Skip to content

Commit

Permalink
Merge pull request jsonresume#33 from ss22ever/restructure
Browse files Browse the repository at this point in the history
Add validator test
  • Loading branch information
stp-ip committed Mar 20, 2018
2 parents bcc0b39 + d2b15d5 commit 57b95ff
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/resumic/tests/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package tests
55 changes: 55 additions & 0 deletions cmd/resumic/tests/validator_test.go
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
}

0 comments on commit 57b95ff

Please sign in to comment.