Beispiel #1
0
func TestEq(t *testing.T) {
	dat := map[string]interface{}{
		"a": "example1234",
	}
	scheme := map[string]interface{}{
		"a": map[string]interface{}{
			"type":  "eq",
			"value": "example123",
			"must":  true,
		},
	}
	res, err := sanitize.Fast(scheme, dat)
	if err == nil {
		t.Fatal()
	}
	dat1 := map[string]interface{}{
		"a": "example123",
	}
	res, err = sanitize.Fast(scheme, dat1)
	if err != nil {
		t.Fatal(err)
	}
	if res["a"] != "example123" {
		t.Fatal(res["a"])
	}
}
Beispiel #2
0
func (h *HighLev) userChecks(user iface.User) error {
	verbSpec, ok := jsonp.GetM(h.nouns, fmt.Sprint("%v.verbs.%v.userCrit", h.desc.Sentence.Noun, h.desc.Sentence.Verb))
	if ok {
		_, err := sanitize.Fast(verbSpec, user.Data())
		return err
	}
	nounSpec, ok := jsonp.GetM(h.nouns, fmt.Sprintf("%v.userCrit", h.desc.Sentence.Noun))
	if !ok {
		return nil
	}
	_, err := sanitize.Fast(nounSpec, user.Data())
	return err
}
Beispiel #3
0
func TestAnySlice(t *testing.T) {
	dat := map[string]interface{}{
		"a": []interface{}{1, 2, 3},
	}
	scheme := map[string]interface{}{
		"a": map[string]interface{}{
			"type":  "any",
			"slice": true,
			"must":  true,
		},
	}
	res, err := sanitize.Fast(scheme, dat)
	if err != nil {
		t.Fatal(err)
	}
	if len(res["a"].([]interface{})) != 3 {
		t.Fatal(res)
	}
}