-
Notifications
You must be signed in to change notification settings - Fork 2
/
Basic_test.go
40 lines (37 loc) · 1.04 KB
/
Basic_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package jsonschematics
import (
v2 "github.com/ashbeelghouri/jsonschematics/data/v2"
"github.com/ashbeelghouri/jsonschematics/utils"
"log"
"os"
"testing"
)
func customFunc(i interface{}, attr map[string]interface{}) error {
log.Println("--------->>> ========== >>>>> attributes are: ", attr)
return nil
}
func TestV2Validate(t *testing.T) {
schematics, err := v2.LoadJsonSchemaFile("test-data/schema/direct/v2/example-1.json")
if err != nil {
t.Error(err)
}
schematics.Logging.PrintDebugLogs = true
schematics.Logging.PrintErrorLogs = true
schematics.Validators.RegisterValidator("NewFun", NewFun)
schematics.Validators.RegisterValidator("customFunc", customFunc)
content, err := os.ReadFile("test-data/data/direct/example.json")
if err != nil {
t.Error(err)
}
jsonData, err := utils.BytesToMap(content)
if err != nil {
t.Error(err)
}
errs := schematics.Validate(jsonData)
log.Println(errs.GetStrings("ar", "%message\n"))
}
func NewFun(i interface{}, attr map[string]interface{}) error {
log.Println(i)
log.Println(attr)
return nil
}