text:
package validation

// Copyright 2017 Microsoft Corporation
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.

import (
	"fmt"
	"reflect"
	"strings"
	"testing"

	"github.com/stretchr/testify/require"
)

func TestCheckForUniqueInArrayTrue(t *testing.T) {
	require.Equal(t, checkForUniqueInArray(reflect.ValueOf([]int{1, 2, 3})), true)
}

func TestCheckForUniqueInArrayFalse(t *testing.T) {
	require.Equal(t, checkForUniqueInArray(reflect.ValueOf([]int{1, 2, 3, 3})), false)
}

func TestCheckForUniqueInArrayEmpty(t *testing.T) {
	require.Equal(t, checkForUniqueInArray(reflect.ValueOf([]int{})), false)
}

func TestCheckForUniqueInMapTrue(t *testing.T) {
	require.Equal(t, checkForUniqueInMap(reflect.ValueOf(map[string]int{"one": 1, "two": 2})), true)
}

func TestCheckForUniqueInMapFalse(t *testing.T) {
	require.Equal(t, checkForUniqueInMap(reflect.ValueOf(map[int]string{1: "one", 2: "one"})), false)
}

func TestCheckForUniqueInMapEmpty(t *testing.T) {
	require.Equal(t, checkForUniqueInMap(reflect.ValueOf(map[int]string{})), false)
}

func TestCheckEmpty_WithValueEmptyRuleTrue(t *testing.T) {
	var x interface{}
	v := Constraint{
		Target: "str",
		Name:   Empty,
		Rule:   true,
		Chain:  nil,
	}
	expected := createError(reflect.ValueOf(x), v, "value can not be null or empty; required parameter")
	require.Equal(t, checkEmpty(reflect.ValueOf(x), v).Error(), expected.Error())
}

func TestCheckEmpty_WithEmptyStringRuleFalse(t *testing.T) {
	var x interface{}
	v := Constraint{
		Target: "str",
		Name:   Empty,
		Rule:   false,
		Chain:  nil,
	}
	require.Nil(t, checkEmpty(reflect.ValueOf(x), v))
}

func TestCheckEmpty_IncorrectRule(t *testing.T) {
	var x interface{}
	v := Constraint{
		Target: "str",
		Name:   Empty,
		Rule:   10,
		Chain:  nil,
	}
	expected := createError(reflect.ValueOf(x), v, fmt.Sprintf("rule must be bool value for %v constraint; got: %v", v.Name, v.Rule))
	require.Equal(t, checkEmpty(reflect.ValueOf(x), v).Error(), expected.Error())
}

func TestCheckEmpty_WithErrorArray(t *testing.T) {
	var x interface{} = []string{}
	v := Constraint{
		Target: "str",
		Name:   Empty,
		Rule:   true,
		Chain:  nil,
	}
	expected := createError(reflect.ValueOf(x), v, "value can not be null or empty; required parameter")
	require.Equal(t, checkEmpty(reflect.ValueOf(x), v).Error(), expected.Error())
}

func TestCheckNil_WithNilValueRuleTrue(t *testing.T) {
	var x interface{}
	v := Constraint{
		Target: "x",
		Name:   Null,
		Rule:   true,
		Chain: []Constraint{
			{"x", MaxItems, 4, nil},
		},
	}
	expected := createError(reflect.ValueOf(x), v, "value can not be null; required parameter")
	require.Equal(t, checkNil(reflect.ValueOf(x), v).Error(), expected.Error())
}

func TestCheckNil_WithNilValueRuleFalse(t *testing.T) {
	var x interface{}
	v := Constraint{
		Target: "x",
		Name:   Null,
		Rule:   false,
		Chain: []Constraint{
			{"x", MaxItems, 4, nil},
		},
	}
	require.Nil(t, checkNil(reflect.ValueOf(x), v))
}

func TestCheckNil_IncorrectRule(t *testing.T) {
	var x interface{}
	c := Constraint{
		Target: "str",
		Name:   Null,
		Rule:   10,
		Chain:  nil,
	}
	expected := createError(reflect.ValueOf(x), c, fmt.Sprintf("rule must be bool value for %v constraint; got: %v", c.Name, c.Rule))
	require.Equal(t, checkNil(reflect.ValueOf(x), c).Error(), expected.Error())
}

func TestValidateArrayMap_WithNilValueRuleTrue(t *testing.T) {
	var a []string
	var x interface{} = a
	c := Constraint{
		Target: "arr",
		Name:   Null,
		Rule:   true,
		Chain:  nil,
	}
	expected := createError(reflect.ValueOf(x), c, "value can not be null; required parameter")
	require.Equal(t, validateArrayMap(reflect.ValueOf(x), c), expected)
}

func TestValidateArrayMap_WithNilValueRuleFalse(t *testing.T) {
	var x interface{} = []string{}
	c := Constraint{
		Target: "arr",
		Name:   Null,
		Rule:   false,
		Chain:  nil,
	}
	require.Nil(t, validateArrayMap(reflect.ValueOf(x), c))
}

func TestValidateArrayMap_WithValueRuleNullTrue(t *testing.T) {
	var x interface{} = []string{"1", "2"}
	c := Constraint{
		Target: "arr",
		Name:   Null,
		Rule:   false,
		Chain:  nil,
	}
	require.Nil(t, validateArrayMap(reflect.ValueOf(x), c))
}

func TestValidateArrayMap_WithEmptyValueRuleTrue(t *testing.T) {
	var x interface{} = []string{}
	c := Constraint{
		Target: "arr",
		Name:   Empty,
		Rule:   true,
		Chain:  nil,
	}
	expected := createError(reflect.ValueOf(x), c, "value can not be null or empty; required parameter")
	require.Equal(t, validateArrayMap(reflect.ValueOf(x), c), expected)
}

func TestValidateArrayMap_WithEmptyValueRuleFalse(t *testing.T) {
	var x interface{} = []string{}
	c := Constraint{
		Target: "arr",
		Name:   Empty,
		Rule:   false,
		Chain:  nil,
	}
	require.Nil(t, validateArrayMap(reflect.ValueOf(x), c))
}

func TestValidateArrayMap_WithEmptyRuleEmptyTrue(t *testing.T) {
	var x interface{} = []string{"1", "2"}
	c := Constraint{
		Target: "arr",
		Name:   Empty,
		Rule:   false,
		Chain:  nil,
	}
	require.Nil(t, validateArrayMap(reflect.ValueOf(x), c))
}

func TestValidateArrayMap_MaxItemsIncorrectRule(t *testing.T) {
	var x interface{} = []string{"1", "2"}
	c := Constraint{
		Target: "arr",
		Name:   MaxItems,
		Rule:   false,
		Chain:  nil,
	}
	expected := createError(reflect.ValueOf(x), c, fmt.Sprintf("rule must be integer for %v constraint; got: %v", c.Name, c.Rule))
	require.Equal(t, validateArrayMap(reflect.ValueOf(x), c).Error(), expected.Error())
}

func TestValidateArrayMap_MaxItemsNoError(t *testing.T) {
	var x interface{} = []string{"1", "2"}
	c := Constraint{
		Target: "arr",
		Name:   MaxItems,
		Rule:   2,
		Chain:  nil,
	}
	require.Nil(t, validateArrayMap(reflect.ValueOf(x), c))
}

func TestValidateArrayMap_MaxItemsWithError(t *testing.T) {
	var x interface{} = []string{"1", "2", "3"}
	c := Constraint{
		Target: "arr",
		Name:   MaxItems,
		Rule:   2,
		Chain:  nil,
	}
	expected := createError(reflect.ValueOf(x), c, fmt.Sprintf("maximum item limit is %v; got: 3", c.Rule))
	require.Equal(t, validateArrayMap(reflect.ValueOf(x), c).Error(), expected.Error())
}

func TestValidateArrayMap_MaxItemsWithEmpty(t *testing.T) {
	var x interface{} = []string{}
	c := Constraint{
		Target: "arr",
		Name:   MaxItems,
		Rule:   2,
		Chain:  nil,
	}
	require.Nil(t, validateArrayMap(reflect.ValueOf(x), c))
}

func TestValidateArrayMap_MinItemsIncorrectRule(t *testing.T) {
	var x interface{} = []int{1, 2}
	c := Constraint{
		Target: "arr",
		Name:   MinItems,
		Rule:   false,
		Chain:  nil,
	}
	expected := createError(reflect.ValueOf(x), c, fmt.Sprintf("rule must be integer for %v constraint; got: %v", c.Name, c.Rule))
	require.Equal(t, validateArrayMap(reflect.ValueOf(x), c).Error(), expected.Error())
}

func TestValidateArrayMap_MinItemsNoError1(t *testing.T) {
	c := Constraint{
		Target: "arr",
		Name:   MinItems,
		Rule:   2,
		Chain:  nil,
	}
	require.Nil(t, validateArrayMap(reflect.ValueOf([]int{1, 2}), c))
}

func TestValidateArrayMap_MinItemsNoError2(t *testing.T) {
	c := Constraint{
		Target: "arr",
		Name:   MinItems,
		Rule:   2,
		Chain:  nil,
	}
	require.Nil(t, validateArrayMap(reflect.ValueOf([]int{1, 2, 3}), c))
}

func TestValidateArrayMap_MinItemsWithError(t *testing.T) {
	var x interface{} = []int{1}
	c := Constraint{
		Target: "arr",
		Name:   MinItems,
		Rule:   2,
		Chain:  nil,
	}
	expected := createError(reflect.ValueOf(x), c, fmt.Sprintf("minimum item limit is %v; got: 1", c.Rule))
	require.Equal(t, validateArrayMap(reflect.ValueOf(x), c).Error(), expected.Error())
}

func TestValidateArrayMap_MinItemsWithEmpty(t *testing.T) {
	var x interface{} = []int{}
	c := Constraint{
		Target: "arr",
		Name:   MinItems,
		Rule:   2,
		Chain:  nil,
	}
	expected := createError(reflect.ValueOf(x), c, fmt.Sprintf("minimum item limit is %v; got: 0", c.Rule))
	require.Equal(t, validateArrayMap(reflect.ValueOf(x), c).Error(), expected.Error())
}

func TestValidateArrayMap_Map_MaxItemsIncorrectRule(t *testing.T) {
	var x interface{} = map[int]string{1: "1", 2: "2"}
	c := Constraint{
		Target: "arr",
		Name:   MaxItems,
		Rule:   false,
		Chain:  nil,
	}
	require.Equal(t, strings.Contains(validateArrayMap(reflect.ValueOf(x), c).Error(),
		fmt.Sprintf("rule must be integer for %v constraint; got: %v", c.Name, c.Rule)), true)
}

func TestValidateArrayMap_Map_MaxItemsNoError(t *testing.T) {
	var x interface{} = map[int]string{1: "1", 2: "2"}
	c := Constraint{
		Target: "arr",
		Name:   MaxItems,
		Rule:   2,
		Chain:  nil,
	}
	require.Nil(t, validateArrayMap(reflect.ValueOf(x), c))
}

func TestValidateArrayMap_Map_MaxItemsWithError(t *testing.T) {
	a := map[int]string{1: "1", 2: "2", 3: "3"}
	var x interface{} = a
	c := Constraint{
		Target: "arr",
		Name:   MaxItems,
		Rule:   2,
		Chain:  nil,
	}
	require.Equal(t, strings.Contains(validateArrayMap(reflect.ValueOf(x), c).Error(),
		fmt.Sprintf("maximum item limit is %v; got: %v", c.Rule, len(a))), true)
}

func TestValidateArrayMap_Map_MaxItemsWithEmpty(t *testing.T) {
	a := map[int]string{}
	var x interface{} = a
	c := Constraint{
		Target: "arr",
		Name:   MaxItems,
		Rule:   2,
		Chain:  nil,
	}
	require.Nil(t, validateArrayMap(reflect.ValueOf(x), c))
}

func TestValidateArrayMap_Map_MinItemsIncorrectRule(t *testing.T) {
	var x interface{} = map[int]string{1: "1", 2: "2"}
	c := Constraint{
		Target: "arr",
		Name:   MinItems,
		Rule:   false,
		Chain:  nil,
	}
	require.Equal(t, strings.Contains(validateArrayMap(reflect.ValueOf(x), c).Error(),
		fmt.Sprintf("rule must be integer for %v constraint; got: %v", c.Name, c.Rule)), true)
}

func TestValidateArrayMap_Map_MinItemsNoError1(t *testing.T) {
	var x interface{} = map[int]string{1: "1", 2: "2"}
	require.Nil(t, validateArrayMap(reflect.ValueOf(x),
		Constraint{
			Target: "arr",
			Name:   MinItems,
			Rule:   2,
			Chain:  nil,
		}))
}

func TestValidateArrayMap_Map_MinItemsNoError2(t *testing.T) {
	var x interface{} = map[int]string{1: "1", 2: "2", 3: "3"}
	c := Constraint{
		Target: "arr",
		Name:   MinItems,
		Rule:   2,
		Chain:  nil,
	}
	require.Nil(t, validateArrayMap(reflect.ValueOf(x), c))
}

func TestValidateArrayMap_Map_MinItemsWithError(t *testing.T) {
	a := map[int]string{1: "1"}
	var x interface{} = a
	c := Constraint{
		Target: "arr",
		Name:   MinItems,
		Rule:   2,
		Chain:  nil,
	}
	expected := createError(reflect.ValueOf(x), c, fmt.Sprintf("minimum item limit is %v; got: %v", c.Rule, len(a)))
	require.Equal(t, validateArrayMap(reflect.ValueOf(x), c).Error(), expected.Error())
}

func TestValidateArrayMap_Map_MinItemsWithEmpty(t *testing.T) {
	a := map[int]string{}
	var x interface{} = a
	c := Constraint{
		Target: "arr",
		Name:   MinItems,
		Rule:   2,
		Chain:  nil,
	}
	expected := createError(reflect.ValueOf(x), c, fmt.Sprintf("minimum item limit is %v; got: %v", c.Rule, len(a)))
	require.Equal(t, validateArrayMap(reflect.ValueOf(x), c).Error(), expected.Error())
}

// func TestValidateArrayMap_Map_MinItemsNil(t *testing.T) {
// 	var a map[int]float64
// 	var x interface{} = a
// 	c := Constraint{
// 		Target: "str",
// 		Name:   MinItems,
// 		Rule:   true,
// 		Chain:  nil,
// 	}
// 	expected := createError(reflect.Value(x), c, fmt.Sprintf("all items in parameter %v must be unique; got:%v", c.Target, x))
// 	if z := validateArrayMap(reflect.ValueOf(x), c); strings.Contains(z.Error(), "all items in parameter str must be unique;") {
// 		t.Fatalf("autorest/validation: valiateArrayMap failed to return error \nexpect: %v;\ngot: %v", expected, z)
// 	}
// }

func TestValidateArrayMap_Map_UniqueItemsTrue(t *testing.T) {
	var x interface{} = map[float64]int{1.2: 1, 1.4: 2}
	c := Constraint{
		Target: "str",
		Name:   UniqueItems,
		Rule:   true,
		Chain:  nil,
	}
	require.Nil(t, validateArrayMap(reflect.ValueOf(x), c))
}

func TestValidateArrayMap_Map_UniqueItemsFalse(t *testing.T) {
	var x interface{} = map[string]string{"1": "1", "2": "2", "3": "1"}
	c := Constraint{
		Target: "str",
		Name:   UniqueItems,
		Rule:   true,
		Chain:  nil,
	}
	z := validateArrayMap(reflect.ValueOf(x), c)
	require.Equal(t, strings.Contains(z.Error(),
		fmt.Sprintf("all items in parameter %q must be unique", c.Target)), true)
}

func TestValidateArrayMap_Map_UniqueItemsEmpty(t *testing.T) {
	// Consider Empty map as not unique returns false
	var x interface{} = map[int]float64{}
	c := Constraint{
		Target: "str",
		Name:   UniqueItems,
		Rule:   true,
		Chain:  nil,
	}
	z := validateArrayMap(reflect.ValueOf(x), c)
	require.Equal(t, strings.Contains(z.Error(),
		fmt.Sprintf("all items in parameter %q must be unique", c.Target)), true)
}

func TestValidateArrayMap_Map_UniqueItemsNil(t *testing.T) {
	var a map[int]float64
	var x interface{} = a
	c := Constraint{
		Target: "str",
		Name:   UniqueItems,
		Rule:   true,
		Chain:  nil,
	}
	z := validateArrayMap(reflect.ValueOf(x), c)
	require.Equal(t, strings.Contains(z.Error(),
		fmt.Sprintf("all items in parameter %q must be unique; got:%v", c.Target, x)), true)
}

func TestValidateArrayMap_Array_UniqueItemsTrue(t *testing.T) {
	var x interface{} = []int{1, 2}
	c := Constraint{
		Target: "str",
		Name:   UniqueItems,
		Rule:   true,
		Chain:  nil,
	}
	require.Nil(t, validateArrayMap(reflect.ValueOf(x), c))
}

func TestValidateArrayMap_Array_UniqueItemsFalse(t *testing.T) {
	var x interface{} = []string{"1", "2", "1"}
	c := Constraint{
		Target: "str",
		Name:   UniqueItems,
		Rule:   true,
		Chain:  nil,
	}
	z := validateArrayMap(reflect.ValueOf(x), c)
	require.Equal(t, strings.Contains(z.Error(),
		fmt.Sprintf("all items in parameter %q must be unique; got:%v", c.Target, x)), true)
}

func TestValidateArrayMap_Array_UniqueItemsEmpty(t *testing.T) {
	// Consider Empty array as not unique returns false
	var x interface{} = []float64{}
	c := Constraint{
		Target: "str",
		Name:   UniqueItems,
		Rule:   true,
		Chain:  nil,
	}
	z := validateArrayMap(reflect.ValueOf(x), c)
	require.Equal(t, strings.Contains(z.Error(),
		fmt.Sprintf("all items in parameter %q must be unique; got:%v", c.Target, x)), true)
}

func TestValidateArrayMap_Array_UniqueItemsNil(t *testing.T) {
	// Consider nil array as not unique returns false
	var a []float64
	var x interface{} = a
	c := Constraint{
		Target: "str",
		Name:   UniqueItems,
		Rule:   true,
		Chain:  nil,
	}
	z := validateArrayMap(reflect.ValueOf(x), c)
	require.Equal(t, strings.Contains(z.Error(),
		fmt.Sprintf("all items in parameter %q must be unique; got:%v", c.Target, x)), true)
}

func TestValidateArrayMap_Array_UniqueItemsInvalidType(t *testing.T) {
	var x interface{} = "hello"
	c := Constraint{
		Target: "str",
		Name:   UniqueItems,
		Rule:   true,
		Chain:  nil,
	}
	z := validateArrayMap(reflect.ValueOf(x), c)
	require.Equal(t, strings.Contains(z.Error(),
		fmt.Sprintf("type must be array, slice or map for constraint %v; got: %v", c.Name, reflect.ValueOf(x).Kind())), true)
}

func TestValidateArrayMap_Array_UniqueItemsInvalidConstraint(t *testing.T) {
	var x interface{} = "hello"
	c := Constraint{
		Target: "str",
		Name:   "sdad",
		Rule:   true,
		Chain:  nil,
	}
	z := validateArrayMap(reflect.ValueOf(x), c)
	require.Equal(t, strings.Contains(z.Error(),
		fmt.Sprintf("constraint %v is not applicable to array, slice and map type", c.Name)), true)
}

func TestValidateArrayMap_ValidateChainConstraint1(t *testing.T) {
	a := []int{1, 2, 3, 4}
	var x interface{} = a
	c := Constraint{
		Target: "str",
		Name:   Null,
		Rule:   true,
		Chain: []Constraint{
			{"str", MaxItems, 3, nil},
		},
	}
	z := validateArrayMap(reflect.ValueOf(x), c)
	require.Equal(t, strings.Contains(z.Error(),
		fmt.Sprintf("maximum item limit is %v; got: %v", (c.Chain)[0].Rule, len(a))), true)
}

func TestValidateArrayMap_ValidateChainConstraint2(t *testing.T) {
	a := []int{1, 2, 3, 4}
	var x interface{} = a
	c := Constraint{
		Target: "str",
		Name:   Empty,
		Rule:   true,
		Chain: []Constraint{
			{"str", MaxItems, 3, nil},
		},
	}
	z := validateArrayMap(reflect.ValueOf(x), c)
	require.Equal(t, strings.Contains(z.Error(),
		fmt.Sprintf("maximum item limit is %v; got: %v", (c.Chain)[0].Rule, len(a))), true)
}

func TestValidateArrayMap_ValidateChainConstraint3(t *testing.T) {
	var a []string
	var x interface{} = a
	c := Constraint{
		Target: "str",
		Name:   Null,
		Rule:   true,
		Chain: []Constraint{
			{"str", MaxItems, 3, nil},
		},
	}
	z := validateArrayMap(reflect.ValueOf(x), c)
	require.Equal(t, strings.Contains(z.Error(),
		fmt.Sprintf("value can not be null; required parameter")), true)
}

func TestValidateArrayMap_ValidateChainConstraint4(t *testing.T) {
	var x interface{} = []int{}
	c := Constraint{
		Target: "str",
		Name:   Empty,
		Rule:   true,
		Chain: []Constraint{
			{"str", MaxItems, 3, nil},
		},
	}
	z := validateArrayMap(reflect.ValueOf(x), c)
	require.Equal(t, strings.Contains(z.Error(),
		fmt.Sprintf("value can not be null or empty; required parameter")), true)
}

func TestValidateArrayMap_ValidateChainConstraintNilNotRequired(t *testing.T) {
	var a []int
	var x interface{} = a
	c := Constraint{
		Target: "str",
		Name:   Null,
		Rule:   false,
		Chain: []Constraint{
			{"str", MaxItems, 3, nil},
		},
	}
	require.Nil(t, validateArrayMap(reflect.ValueOf(x), c))
}

func TestValidateArrayMap_ValidateChainConstraintEmptyNotRequired(t *testing.T) {
	var x interface{} = map[string]int{}
	c := Constraint{
		Target: "str",
		Name:   Empty,
		Rule:   false,
		Chain: []Constraint{
			{"str", MaxItems, 3, nil},
		},
	}
	require.Nil(t, validateArrayMap(reflect.ValueOf(x), c))
}

func TestValidateArrayMap_ReadOnlyWithError(t *testing.T) {
	var x interface{} = []int{1, 2}
	c := Constraint{
		Target: "str",
		Name:   ReadOnly,
		Rule:   true,
		Chain: []Constraint{
			{"str", MaxItems, 3, nil},
		},
	}
	z := validateArrayMap(reflect.ValueOf(x), c)
	require.Equal(t, strings.Contains(z.Error(),
		fmt.Sprintf("readonly parameter; must send as nil or empty in request")), true)
}

func TestValidateArrayMap_ReadOnlyWithoutError(t *testing.T) {
	var x interface{} = []int{}
	c := Constraint{
		Target: "str",
		Name:   ReadOnly,
		Rule:   true,
		Chain:  nil,
	}
	require.Nil(t, validateArrayMap(reflect.ValueOf(x), c))
}

func TestValidateString_ReadOnly(t *testing.T) {
	var x interface{} = "Hello Gopher"
	c := Constraint{
		Target: "str",
		Name:   ReadOnly,
		Rule:   true,
		Chain:  nil,
	}
	require.Equal(t, strings.Contains(validateString(reflect.ValueOf(x), c).Error(),
		fmt.Sprintf("readonly parameter; must send as nil or empty in request")), true)
}

func TestValidateString_EmptyTrue(t *testing.T) {
	// Empty true means parameter is required but Empty returns error
	c := Constraint{
		Target: "str",
		Name:   Empty,
		Rule:   true,
		Chain:  nil,
	}
	require.Equal(t, strings.Contains(validateString(reflect.ValueOf(""), c).Error(),
		fmt.Sprintf("value can not be null or empty; required parameter")), true)
}

func TestValidateString_EmptyFalse(t *testing.T) {
	// Empty false means parameter is not required and Empty return nil
	var x interface{}
	c := Constraint{
		Target: "str",
		Name:   Empty,
		Rule:   false,
		Chain:  nil,
	}
	require.Nil(t, validateString(reflect.ValueOf(x), c))
}

func TestValidateString_MaxLengthInvalid(t *testing.T) {
	// Empty true means parameter is required but Empty returns error
	var x interface{} = "Hello"
	c := Constraint{
		Target: "str",
		Name:   MaxLength,
		Rule:   4,
		Chain:  nil,
	}
	require.Equal(t, strings.Contains(validateString(reflect.ValueOf(x), c).Error(),
		fmt.Sprintf("value length must be less than or equal to %v", c.Rule)), true)
}

func TestValidateString_MaxLengthValid(t *testing.T) {
	// Empty false means parameter is not required and Empty return nil
	c := Constraint{
		Target: "str",
		Name:   MaxLength,
		Rule:   7,
		Chain:  nil,
	}
	require.Nil(t, validateString(reflect.ValueOf("Hello"), c))
}

func TestValidateString_MaxLengthRuleInvalid(t *testing.T) {
	var x interface{} = "Hello"
	c := Constraint{
		Target: "str",
		Name:   MaxLength,
		Rule:   true, // must be int for maxLength
		Chain:  nil,
	}
	require.Equal(t, strings.Contains(validateString(reflect.ValueOf(x), c).Error(),
		fmt.Sprintf("rule must be integer value for %v constraint; got: %v", c.Name, c.Rule)), true)
}

func TestValidateString_MinLengthInvalid(t *testing.T) {
	var x interface{} = "Hello"
	c := Constraint{
		Target: "str",
		Name:   MinLength,
		Rule:   10,
		Chain:  nil,
	}
	require.Equal(t, strings.Contains(validateString(reflect.ValueOf(x), c).Error(),
		fmt.Sprintf("value length must be greater than or equal to %v", c.Rule)), true)
}

func TestValidateString_MinLengthValid(t *testing.T) {
	c := Constraint{
		Target: "str",
		Name:   MinLength,
		Rule:   2,
		Chain:  nil,
	}
	require.Nil(t, validateString(reflect.ValueOf("Hello"), c))
}

func TestValidateString_MinLengthRuleInvalid(t *testing.T) {
	var x interface{} = "Hello"
	c := Constraint{
		Target: "str",
		Name:   MinLength,
		Rule:   true, // must be int for minLength
		Chain:  nil,
	}
	require.Equal(t, strings.Contains(validateString(reflect.ValueOf(x), c).Error(),
		fmt.Sprintf("rule must be integer value for %v constraint; got: %v", c.Name, c.Rule)), true)
}

func TestValidateString_PatternInvalidPattern(t *testing.T) {
	var x interface{} = "Hello"
	c := Constraint{
		Target: "str",
		Name:   Pattern,
		Rule:   `^[[:alnum:$`,
		Chain:  nil,
	}
	require.Equal(t, strings.Contains(validateString(reflect.ValueOf(x), c).Error(),
		"error parsing regexp: missing closing ]"), true)
}

func TestValidateString_PatternMatch1(t *testing.T) {
	c := Constraint{
		Target: "str",
		Name:   Pattern,
		Rule:   `^http://\w+$`,
		Chain:  nil,
	}
	require.Nil(t, validateString(reflect.ValueOf("http://masd"), c))
}

func TestValidateString_PatternMatch2(t *testing.T) {
	c := Constraint{
		Target: "str",
		Name:   Pattern,
		Rule:   `^[a-zA-Z0-9]+$`,
		Chain:  nil,
	}
	require.Nil(t, validateString(reflect.ValueOf("asdadad2323sad"), c))
}

func TestValidateString_PatternNotMatch(t *testing.T) {
	var x interface{} = "asdad@@ad2323sad"
	c := Constraint{
		Target: "str",
		Name:   Pattern,
		Rule:   `^[a-zA-Z0-9]+$`,
		Chain:  nil,
	}
	require.Equal(t, strings.Contains(validateString(reflect.ValueOf(x), c).Error(),
		fmt.Sprintf("value doesn't match pattern %v", c.Rule)), true)
}

func TestValidateString_InvalidConstraint(t *testing.T) {
	var x interface{} = "asdad@@ad2323sad"
	c := Constraint{
		Target: "str",
		Name:   UniqueItems,
		Rule:   "^[a-zA-Z0-9]+$",
		Chain:  nil,
	}
	require.Equal(t, strings.Contains(validateString(reflect.ValueOf(x), c).Error(),
		fmt.Sprintf("constraint %s is not applicable to string type", c.Name)), true)
}

func TestValidateFloat_InvalidConstraint(t *testing.T) {
	var x interface{} = 1.4
	c := Constraint{
		Target: "str",
		Name:   UniqueItems,
		Rule:   3.0,
		Chain:  nil,
	}
	require.Equal(t, strings.Contains(validateFloat(reflect.ValueOf(x), c).Error(),
		fmt.Sprintf("constraint %v is not applicable for type float", c.Name)), true)
}

func TestValidateFloat_InvalidRuleValue(t *testing.T) {
	var x interface{} = 1.4
	c := Constraint{
		Target: "str",
		Name:   ExclusiveMinimum,
		Rule:   3,
		Chain:  nil,
	}
	require.Equal(t, strings.Contains(validateFloat(reflect.ValueOf(x), c).Error(),
		fmt.Sprintf("rule must be float value for %v constraint; got: %v", c.Name, c.Rule)), true)
}

func TestValidateFloat_ExclusiveMinimumConstraintValid(t *testing.T) {
	c := Constraint{
		Target: "str",
		Name:   ExclusiveMinimum,
		Rule:   1.0,
		Chain:  nil,
	}
	require.Nil(t, validateFloat(reflect.ValueOf(1.42), c))
}

func TestValidateFloat_ExclusiveMinimumConstraintInvalid(t *testing.T) {
	var x interface{} = 1.4
	c := Constraint{
		Target: "str",
		Name:   ExclusiveMinimum,
		Rule:   1.5,
		Chain:  nil,
	}
	require.Equal(t, strings.Contains(validateFloat(reflect.ValueOf(x), c).Error(),
		fmt.Sprintf("value must be greater than %v", c.Rule)), true)
}

func TestValidateFloat_ExclusiveMinimumConstraintBoundary(t *testing.T) {
	var x interface{} = 1.42
	c := Constraint{
		Target: "str",
		Name:   ExclusiveMinimum,
		Rule:   1.42,
		Chain:  nil,
	}
	require.Equal(t, strings.Contains(validateFloat(reflect.ValueOf(x), c).Error(),
		fmt.Sprintf("value must be greater than %v", c.Rule)), true)
}

func TestValidateFloat_exclusiveMaximumConstraintValid(t *testing.T) {
	c := Constraint{
		Target: "str",
		Name:   ExclusiveMaximum,
		Rule:   2.0,
		Chain:  nil,
	}
	require.Nil(t, validateFloat(reflect.ValueOf(1.42), c))
}

func TestValidateFloat_exclusiveMaximumConstraintInvalid(t *testing.T) {
	var x interface{} = 1.42
	c := Constraint{
		Target: "str",
		Name:   ExclusiveMaximum,
		Rule:   1.2,
		Chain:  nil,
	}
	require.Equal(t, strings.Contains(validateFloat(reflect.ValueOf(x), c).Error(),
		fmt.Sprintf("value must be less than %v", c.Rule)), true)
}

func TestValidateFloat_exclusiveMaximumConstraintBoundary(t *testing.T) {
	var x interface{} = 1.42
	c := Constraint{
		Target: "str",
		Name:   ExclusiveMaximum,
		Rule:   1.42,
		Chain:  nil,
	}
	require.Equal(t, strings.Contains(validateFloat(reflect.ValueOf(x), c).Error(),
		fmt.Sprintf("value must be less than %v", c.Rule)), true)
}

func TestValidateFloat_inclusiveMaximumConstraintValid(t *testing.T) {
	c := Constraint{
		Target: "str",
		Name:   InclusiveMaximum,
		Rule:   2.0,
		Chain:  nil,
	}
	require.Nil(t, validateFloat(reflect.ValueOf(1.42), c))
}

func TestValidateFloat_inclusiveMaximumConstraintInvalid(t *testing.T) {
	var x interface{} = 1.42
	c := Constraint{
		Target: "str",
		Name:   InclusiveMaximum,
		Rule:   1.2,
		Chain:  nil,
	}
	require.Equal(t, strings.Contains(validateFloat(reflect.ValueOf(x), c).Error(),
		fmt.Sprintf("value must be less than or equal to %v", c.Rule)), true)

}

func TestValidateFloat_inclusiveMaximumConstraintBoundary(t *testing.T) {
	c := Constraint{
		Target: "str",
		Name:   InclusiveMaximum,
		Rule:   1.42,
		Chain:  nil,
	}
	require.Nil(t, validateFloat(reflect.ValueOf(1.42), c))
}

func TestValidateFloat_InclusiveMinimumConstraintValid(t *testing.T) {
	c := Constraint{
		Target: "str",
		Name:   InclusiveMinimum,
		Rule:   1.0,
		Chain:  nil,
	}
	require.Nil(t, validateFloat(reflect.ValueOf(1.42), c))
}

func TestValidateFloat_InclusiveMinimumConstraintInvalid(t *testing.T) {
	var x interface{} = 1.42
	c := Constraint{
		Target: "str",
		Name:   InclusiveMinimum,
		Rule:   1.5,
		Chain:  nil,
	}
	require.Equal(t, strings.Contains(validateFloat(reflect.ValueOf(x), c).Error(),
		fmt.Sprintf("value must be greater than or equal to %v", c.Rule)), true)

}

func TestValidateFloat_InclusiveMinimumConstraintBoundary(t *testing.T) {
	c := Constraint{
		Target: "str",
		Name:   InclusiveMinimum,
		Rule:   1.42,
		Chain:  nil,
	}
	require.Nil(t, validateFloat(reflect.ValueOf(1.42), c))
}

func TestValidateInt_InvalidConstraint(t *testing.T) {
	var x interface{} = 1
	c := Constraint{
		Target: "str",
		Name:   UniqueItems,
		Rule:   3,
		Chain:  nil,
	}
	require.Equal(t, strings.Contains(validateInt(reflect.ValueOf(x), c).Error(),
		fmt.Sprintf("constraint %s is not applicable for type integer", c.Name)), true)
}

func TestValidateInt_InvalidRuleValue(t *testing.T) {
	var x interface{} = 1
	c := Constraint{
		Target: "str",
		Name:   ExclusiveMinimum,
		Rule:   3.4,
		Chain:  nil,
	}
	require.Equal(t, strings.Contains(validateInt(reflect.ValueOf(x), c).Error(),
		fmt.Sprintf("rule must be integer value for %v constraint; got: %v", c.Name, c.Rule)), true)
}

func TestValidateInt_ExclusiveMinimumConstraintValid(t *testing.T) {
	c := Constraint{
		Target: "str",
		Name:   ExclusiveMinimum,
		Rule:   1,
		Chain:  nil,
	}
	require.Nil(t, validateInt(reflect.ValueOf(3), c))
}

func TestValidateInt_ExclusiveMinimumConstraintInvalid(t *testing.T) {
	var x interface{} = 1
	c := Constraint{
		Target: "str",
		Name:   ExclusiveMinimum,
		Rule:   3,
		Chain:  nil,
	}
	require.Equal(t, validateInt(reflect.ValueOf(x), c).Error(),
		createError(reflect.ValueOf(x), c, fmt.Sprintf("value must be greater than %v", c.Rule)).Error())
}

func TestValidateInt_ExclusiveMinimumConstraintBoundary(t *testing.T) {
	var x interface{} = 1
	c := Constraint{
		Target: "str",
		Name:   ExclusiveMinimum,
		Rule:   1,
		Chain:  nil,
	}
	require.Equal(t, validateInt(reflect.ValueOf(x), c).Error(),
		createError(reflect.ValueOf(x), c, fmt.Sprintf("value must be greater than %v", c.Rule)).Error())
}

func TestValidateInt_exclusiveMaximumConstraintValid(t *testing.T) {
	c := Constraint{
		Target: "str",
		Name:   ExclusiveMaximum,
		Rule:   2,
		Chain:  nil,
	}
	require.Nil(t, validateInt(reflect.ValueOf(1), c))
}

func TestValidateInt_exclusiveMaximumConstraintInvalid(t *testing.T) {
	var x interface{} = 2
	c := Constraint{
		Target: "str",
		Name:   ExclusiveMaximum,
		Rule:   1,
		Chain:  nil,
	}
	require.Equal(t, validateInt(reflect.ValueOf(x), c).Error(),
		createError(reflect.ValueOf(x), c, fmt.Sprintf("value must be less than %v", c.Rule)).Error())
}

func TestValidateInt_exclusiveMaximumConstraintBoundary(t *testing.T) {
	var x interface{} = 1
	c := Constraint{
		Target: "str",
		Name:   ExclusiveMaximum,
		Rule:   1,
		Chain:  nil,
	}
	require.Equal(t, validateInt(reflect.ValueOf(x), c).Error(),
		createError(reflect.ValueOf(x), c, fmt.Sprintf("value must be less than %v", c.Rule)).Error())
}

func TestValidateInt_inclusiveMaximumConstraintValid(t *testing.T) {
	c := Constraint{
		Target: "str",
		Name:   InclusiveMaximum,
		Rule:   2,
		Chain:  nil,
	}
	require.Nil(t, validateInt(reflect.ValueOf(1), c))
}

func TestValidateInt_inclusiveMaximumConstraintInvalid(t *testing.T) {
	var x interface{} = 2
	c := Constraint{
		Target: "str",
		Name:   InclusiveMaximum,
		Rule:   1,
		Chain:  nil,
	}
	require.Equal(t, validateInt(reflect.ValueOf(x), c).Error(),
		createError(reflect.ValueOf(x), c, fmt.Sprintf("value must be less than or equal to %v", c.Rule)).Error())
}

func TestValidateInt_inclusiveMaximumConstraintBoundary(t *testing.T) {
	c := Constraint{
		Target: "str",
		Name:   InclusiveMaximum,
		Rule:   1,
		Chain:  nil,
	}
	require.Nil(t, validateInt(reflect.ValueOf(1), c))
}

func TestValidateInt_InclusiveMinimumConstraintValid(t *testing.T) {
	c := Constraint{
		Target: "str",
		Name:   InclusiveMinimum,
		Rule:   1,
		Chain:  nil,
	}
	require.Nil(t, validateInt(reflect.ValueOf(1), c))
}

func TestValidateInt_InclusiveMinimumConstraintInvalid(t *testing.T) {
	var x interface{} = 1
	c := Constraint{
		Target: "str",
		Name:   InclusiveMinimum,
		Rule:   2,
		Chain:  nil,
	}
	require.Equal(t, validateInt(reflect.ValueOf(x), c).Error(),
		createError(reflect.ValueOf(x), c, fmt.Sprintf("value must be greater than or equal to %v", c.Rule)).Error())
}

func TestValidateInt_InclusiveMinimumConstraintBoundary(t *testing.T) {
	c := Constraint{
		Target: "str",
		Name:   InclusiveMinimum,
		Rule:   1,
		Chain:  nil,
	}
	require.Nil(t, validateInt(reflect.ValueOf(1), c))
}

func TestValidateInt_MultipleOfWithoutError(t *testing.T) {
	c := Constraint{
		Target: "str",
		Name:   MultipleOf,
		Rule:   10,
		Chain:  nil,
	}
	require.Nil(t, validateInt(reflect.ValueOf(2300), c))
}

func TestValidateInt_MultipleOfWithError(t *testing.T) {
	c := Constraint{
		Target: "str",
		Name:   MultipleOf,
		Rule:   11,
		Chain:  nil,
	}
	require.Equal(t, validateInt(reflect.ValueOf(2300), c).Error(),
		createError(reflect.ValueOf(2300), c, fmt.Sprintf("value must be a multiple of %v", c.Rule)).Error())
}

func TestValidatePointer_NilTrue(t *testing.T) {
	var z *int
	var x interface{} = z
	c := Constraint{
		Target: "ptr",
		Name:   Null,
		Rule:   true, // Required property
		Chain:  nil,
	}
	require.Equal(t, validatePtr(reflect.ValueOf(x), c).Error(),
		createError(reflect.ValueOf(x), c, "value can not be null; required parameter").Error())
}

func TestValidatePointer_NilFalse(t *testing.T) {
	var z *int
	var x interface{} = z
	c := Constraint{
		Target: "ptr",
		Name:   Null,
		Rule:   false, // not required property
		Chain:  nil,
	}
	require.Nil(t, validatePtr(reflect.ValueOf(x), c))
}

func TestValidatePointer_NilReadonlyValid(t *testing.T) {
	var z *int
	var x interface{} = z
	c := Constraint{
		Target: "ptr",
		Name:   ReadOnly,
		Rule:   true,
		Chain:  nil,
	}
	require.Nil(t, validatePtr(reflect.ValueOf(x), c))
}

func TestValidatePointer_NilReadonlyInvalid(t *testing.T) {
	z := 10
	var x interface{} = &z
	c := Constraint{
		Target: "ptr",
		Name:   ReadOnly,
		Rule:   true,
		Chain:  nil,
	}
	require.Equal(t, validatePtr(reflect.ValueOf(x), c).Error(),
		createError(reflect.ValueOf(z), c, "readonly parameter; must send as nil or empty in request").Error())
}

func TestValidatePointer_IntValid(t *testing.T) {
	z := 10
	var x interface{} = &z
	c := Constraint{
		Target: "ptr",
		Name:   InclusiveMinimum,
		Rule:   3,
		Chain:  nil,
	}
	require.Nil(t, validatePtr(reflect.ValueOf(x), c))
}

func TestValidatePointer_IntInvalid(t *testing.T) {
	z := 10
	var x interface{} = &z
	c := Constraint{
		Target: "ptr",
		Name:   Null,
		Rule:   true,
		Chain: []Constraint{
			{
				Target: "ptr",
				Name:   InclusiveMinimum,
				Rule:   11,
				Chain:  nil,
			},
		},
	}
	require.Equal(t, validatePtr(reflect.ValueOf(x), c).Error(),
		createError(reflect.ValueOf(10), c.Chain[0], "value must be greater than or equal to 11").Error())
}

func TestValidatePointer_IntInvalidConstraint(t *testing.T) {
	z := 10
	var x interface{} = &z
	c := Constraint{
		Target: "ptr",
		Name:   Null,
		Rule:   true,
		Chain: []Constraint{
			{
				Target: "ptr",
				Name:   MaxItems,
				Rule:   3,
				Chain:  nil,
			},
		},
	}
	require.Equal(t, validatePtr(reflect.ValueOf(x), c).Error(),
		createError(reflect.ValueOf(10), c.Chain[0],
			fmt.Sprintf("constraint %v is not applicable for type integer", MaxItems)).Error())
}

func TestValidatePointer_ValidInt64(t *testing.T) {
	z := int64(10)
	var x interface{} = &z
	c := Constraint{
		Target: "ptr",
		Name:   Null,
		Rule:   true,
		Chain: []Constraint{
			{
				Target: "ptr",
				Name:   InclusiveMinimum,
				Rule:   3,
				Chain:  nil,
			},
		}}
	require.Nil(t, validatePtr(reflect.ValueOf(x), c))
}

func TestValidatePointer_InvalidConstraintInt64(t *testing.T) {
	z := int64(10)
	var x interface{} = &z
	c := Constraint{
		Target: "ptr",
		Name:   Null,
		Rule:   true,
		Chain: []Constraint{
			{
				Target: "ptr",
				Name:   MaxItems,
				Rule:   3,
				Chain:  nil,
			},
		},
	}
	require.Equal(t, validatePtr(reflect.ValueOf(x), c).Error(),
		createError(reflect.ValueOf(10), c.Chain[0],
			fmt.Sprintf("constraint %v is not applicable for type integer", MaxItems)).Error())
}

func TestValidatePointer_ValidFloat(t *testing.T) {
	z := 10.1
	var x interface{} = &z
	c := Constraint{
		Target: "ptr",
		Name:   Null,
		Rule:   true,
		Chain: []Constraint{
			{
				Target: "ptr",
				Name:   InclusiveMinimum,
				Rule:   3.0,
				Chain:  nil,
			}}}
	require.Nil(t, validatePtr(reflect.ValueOf(x), c))
}

func TestValidatePointer_InvalidFloat(t *testing.T) {
	z := 10.1
	var x interface{} = &z
	c := Constraint{
		Target: "ptr",
		Name:   Null,
		Rule:   true,
		Chain: []Constraint{
			{
				Target: "ptr",
				Name:   InclusiveMinimum,
				Rule:   12.0,
				Chain:  nil,
			}},
	}
	require.Equal(t, validatePtr(reflect.ValueOf(x), c).Error(),
		createError(reflect.ValueOf(10.1), c.Chain[0],
			"value must be greater than or equal to 12").Error())
}

func TestValidatePointer_InvalidConstraintFloat(t *testing.T) {
	z := 10.1
	var x interface{} = &z
	c := Constraint{
		Target: "ptr",
		Name:   Null,
		Rule:   true,
		Chain: []Constraint{
			{
				Target: "ptr",
				Name:   MaxItems,
				Rule:   3.0,
				Chain:  nil,
			}},
	}
	require.Equal(t, validatePtr(reflect.ValueOf(x), c).Error(),
		createError(reflect.ValueOf(10.1), c.Chain[0],
			fmt.Sprintf("constraint %v is not applicable for type float", MaxItems)).Error())
}

func TestValidatePointer_StringValid(t *testing.T) {
	z := "hello"
	var x interface{} = &z
	c := Constraint{
		Target: "ptr",
		Name:   Null,
		Rule:   true,
		Chain: []Constraint{
			{
				Target: "ptr",
				Name:   Pattern,
				Rule:   "^[a-z]+$",
				Chain:  nil,
			}}}
	require.Nil(t, validatePtr(reflect.ValueOf(x), c))
}

func TestValidatePointer_StringInvalid(t *testing.T) {
	z := "hello"
	var x interface{} = &z
	c := Constraint{
		Target: "ptr",
		Name:   Null,
		Rule:   true,
		Chain: []Constraint{
			{
				Target: "ptr",
				Name:   MaxLength,
				Rule:   2,
				Chain:  nil,
			}}}
	require.Equal(t, validatePtr(reflect.ValueOf(x), c).Error(),
		createError(reflect.ValueOf("hello"), c.Chain[0],
			"value length must be less than or equal to 2").Error())
}

func TestValidatePointer_ArrayValid(t *testing.T) {
	c := Constraint{
		Target: "ptr",
		Name:   Null,
		Rule:   true,
		Chain: []Constraint{
			{
				Target: "ptr",
				Name:   UniqueItems,
				Rule:   "true",
				Chain:  nil,
			}}}
	require.Nil(t, validatePtr(reflect.ValueOf(&[]string{"1", "2"}), c))
}

func TestValidatePointer_ArrayInvalid(t *testing.T) {
	z := []string{"1", "2", "2"}
	var x interface{} = &z
	c := Constraint{
		Target: "ptr",
		Name:   Null,
		Rule:   true,
		Chain: []Constraint{{
			Target: "ptr",
			Name:   UniqueItems,
			Rule:   true,
			Chain:  nil,
		}},
	}
	require.Equal(t, validatePtr(reflect.ValueOf(x), c).Error(),
		createError(reflect.ValueOf(z), c.Chain[0],
			fmt.Sprintf("all items in parameter %q must be unique; got:%v", c.Target, z)).Error())
}

func TestValidatePointer_MapValid(t *testing.T) {
	c := Constraint{
		Target: "ptr",
		Name:   Null,
		Rule:   true,
		Chain: []Constraint{
			{
				Target: "ptr",
				Name:   UniqueItems,
				Rule:   true,
				Chain:  nil,
			}}}
	require.Nil(t, validatePtr(reflect.ValueOf(&map[interface{}]string{1: "1", "1": "2"}), c))
}

func TestValidatePointer_MapInvalid(t *testing.T) {
	z := map[interface{}]string{1: "1", "1": "2", 1.3: "2"}
	var x interface{} = &z
	c := Constraint{
		Target: "ptr",
		Name:   Null,
		Rule:   true,
		Chain: []Constraint{{
			Target: "ptr",
			Name:   UniqueItems,
			Rule:   true,
			Chain:  nil,
		}},
	}
	require.Equal(t, strings.Contains(validatePtr(reflect.ValueOf(x), c).Error(),
		fmt.Sprintf("all items in parameter %q must be unique;", c.Target)), true)
}

type Child struct {
	I string
}
type Product struct {
	C    *Child
	Str  *string
	Name string
	Arr  *[]string
	M    *map[string]string
	Num  *int32
}

type Sample struct {
	M    *map[string]*string
	Name string
}

func TestValidatePointer_StructWithError(t *testing.T) {
	s := "hello"
	var x interface{} = &Product{
		C:    &Child{"100"},
		Str:  &s,
		Name: "Gopher",
	}
	c := Constraint{
		"p", Null, "True",
		[]Constraint{
			{"C", Null, true,
				[]Constraint{
					{"I", MaxLength, 2, nil},
				}},
			{"Str", MaxLength, 2, nil},
			{"Name", MaxLength, 5, nil},
		},
	}
	require.Equal(t, validatePtr(reflect.ValueOf(x), c).Error(),
		createError(reflect.ValueOf("100"), c.Chain[0].Chain[0],
			"value length must be less than or equal to 2").Error())
}

func TestValidatePointer_WithNilStruct(t *testing.T) {
	var p *Product
	var x interface{} = p
	c := Constraint{
		"p", Null, true,
		[]Constraint{
			{"C", Null, true,
				[]Constraint{
					{"I", Empty, true,
						[]Constraint{
							{"I", MaxLength, 5, nil},
						}},
				}},
			{"Str", MaxLength, 2, nil},
			{"Name", MaxLength, 5, nil},
		},
	}
	require.Equal(t, validatePtr(reflect.ValueOf(x), c).Error(),
		createError(reflect.ValueOf(x), c,
			fmt.Sprintf("value can not be null; required parameter")).Error())
}

func TestValidatePointer_StructWithNoError(t *testing.T) {
	s := "hello"
	var x interface{} = &Product{
		C:    &Child{"100"},
		Str:  &s,
		Name: "Gopher",
	}
	c := Constraint{
		"p", Null, true,
		[]Constraint{
			{"C", Null, true,
				[]Constraint{
					{"I", Empty, true,
						[]Constraint{
							{"I", MaxLength, 5, nil},
						}},
				}},
		},
	}
	require.Nil(t, validatePtr(reflect.ValueOf(x), c))
}

func TestValidateStruct_FieldNotExist(t *testing.T) {
	s := "hello"
	var x interface{} = Product{
		C:    &Child{"100"},
		Str:  &s,
		Name: "Gopher",
	}
	c := Constraint{
		"C", Null, true,
		[]Constraint{
			{"Name", Empty, true, nil},
		},
	}
	s = "Name"
	require.Equal(t, validateStruct(reflect.ValueOf(x), c).Error(),
		createError(reflect.ValueOf(Child{"100"}), c.Chain[0],
			fmt.Sprintf("field %q doesn't exist", s)).Error())
}

func TestValidateStruct_WithChainConstraint(t *testing.T) {
	s := "hello"
	var x interface{} = Product{
		C:    &Child{"100"},
		Str:  &s,
		Name: "Gopher",
	}
	c := Constraint{
		"C", Null, true,
		[]Constraint{
			{"I", Empty, true,
				[]Constraint{
					{"I", MaxLength, 2, nil},
				}},
		},
	}
	require.Equal(t, validateStruct(reflect.ValueOf(x), c).Error(),
		createError(reflect.ValueOf("100"), c.Chain[0].Chain[0], "value length must be less than or equal to 2").Error())
}

func TestValidateStruct_WithoutChainConstraint(t *testing.T) {
	s := "hello"
	var x interface{} = Product{
		C:    &Child{""},
		Str:  &s,
		Name: "Gopher",
	}
	c := Constraint{"C", Null, true,
		[]Constraint{
			{"I", Empty, true, nil}, // throw error for Empty
		}}
	require.Equal(t, validateStruct(reflect.ValueOf(x), c).Error(),
		createError(reflect.ValueOf(""), c.Chain[0], "value can not be null or empty; required parameter").Error())
}

func TestValidateStruct_WithArrayNull(t *testing.T) {
	s := "hello"
	var x interface{} = Product{
		C:    &Child{""},
		Str:  &s,
		Name: "Gopher",
		Arr:  nil,
	}
	c := Constraint{"Arr", Null, true,
		[]Constraint{
			{"Arr", MaxItems, 4, nil},
			{"Arr", MinItems, 2, nil},
		},
	}
	require.Equal(t, validateStruct(reflect.ValueOf(x), c).Error(),
		createError(reflect.ValueOf(x.(Product).Arr), c, "value can not be null; required parameter").Error())
}

func TestValidateStruct_WithArrayEmptyError(t *testing.T) {
	// arr := []string{}
	var x interface{} = Product{
		Arr: &[]string{},
	}
	c := Constraint{
		"Arr", Null, true,
		[]Constraint{
			{"Arr", Empty, true, nil},
			{"Arr", MaxItems, 4, nil},
			{"Arr", MinItems, 2, nil},
		}}

	require.Equal(t, validateStruct(reflect.ValueOf(x), c).Error(),
		createError(reflect.ValueOf(*(x.(Product).Arr)), c.Chain[0],
			fmt.Sprintf("value can not be null or empty; required parameter")).Error())
}

func TestValidateStruct_WithArrayEmptyWithoutError(t *testing.T) {
	var x interface{} = Product{
		Arr: &[]string{},
	}
	c := Constraint{
		"Arr", Null, true,
		[]Constraint{
			{"Arr", Empty, false, nil},
			{"Arr", MaxItems, 4, nil},
		},
	}
	require.Nil(t, validateStruct(reflect.ValueOf(x), c))
}

func TestValidateStruct_ArrayWithError(t *testing.T) {
	arr := []string{"1", "1"}
	var x interface{} = Product{
		Arr: &arr,
	}
	c := Constraint{
		"Arr", Null, true,
		[]Constraint{
			{"Arr", Empty, true, nil},
			{"Arr", MaxItems, 4, nil},
			{"Arr", UniqueItems, true, nil},
		},
	}
	s := "Arr"
	require.Equal(t, validateStruct(reflect.ValueOf(x), c).Error(),
		createError(reflect.ValueOf(*(x.(Product).Arr)), c.Chain[2],
			fmt.Sprintf("all items in parameter %q must be unique; got:%v", s, *(x.(Product).Arr))).Error())
}

func TestValidateStruct_MapWithError(t *testing.T) {
	m := map[string]string{
		"a": "hello",
		"b": "hello",
	}
	var x interface{} = Product{
		M: &m,
	}
	c := Constraint{
		"M", Null, true,
		[]Constraint{
			{"M", Empty, true, nil},
			{"M", MaxItems, 4, nil},
			{"M", UniqueItems, true, nil},
		},
	}

	s := "M"
	require.Equal(t, strings.Contains(validateStruct(reflect.ValueOf(x), c).Error(),
		fmt.Sprintf("all items in parameter %q must be unique;", s)), true)
}

func TestValidateStruct_MapWithNoError(t *testing.T) {
	m := map[string]string{}
	var x interface{} = Product{
		M: &m,
	}
	c := Constraint{
		"M", Null, true,
		[]Constraint{
			{"M", Empty, false, nil},
			{"M", MaxItems, 4, nil},
		},
	}
	require.Nil(t, validateStruct(reflect.ValueOf(x), c))
}

func TestValidateStruct_MapNilNoError(t *testing.T) {
	var m map[string]string
	var x interface{} = Product{
		M: &m,
	}
	c := Constraint{
		"M", Null, false,
		[]Constraint{
			{"M", Empty, false, nil},
			{"M", MaxItems, 4, nil},
		},
	}
	require.Nil(t, validateStruct(reflect.ValueOf(x), c))
}

func TestValidate_MapValidationWithError(t *testing.T) {
	var x1 interface{} = &Product{
		Arr: &[]string{"1", "2"},
		M:   &map[string]string{"a": "hello"},
	}
	s := "hello"
	var x2 interface{} = &Sample{
		M: &map[string]*string{"a": &s},
	}
	v := []Validation{
		{x1,
			[]Constraint{{"x1", Null, true,
				[]Constraint{
					{"Arr", Null, true,
						[]Constraint{
							{"Arr", Empty, true, nil},
							{"Arr", MaxItems, 4, nil},
							{"Arr", UniqueItems, true, nil},
						},
					},
					{"M", Null, false,
						[]Constraint{
							{"M", Empty, false, nil},
							{"M", MinItems, 1, nil},
							{"M", UniqueItems, true, nil},
						},
					},
				},
			}}},
		{x2,
			[]Constraint{
				{"x2", Null, true,
					[]Constraint{
						{"M", Null, false,
							[]Constraint{
								{"M", Empty, false, nil},
								{"M", MinItems, 2, nil},
								{"M", UniqueItems, true, nil},
							},
						},
					},
				},
				{"Name", Empty, true, nil},
			}},
	}

	z := Validate(v).Error()
	require.Equal(t, strings.Contains(z, "minimum item limit is 2; got: 1"), true)
	require.Equal(t, strings.Contains(z, "MinItems"), true)
}

func TestValidate_MapValidationWithoutError(t *testing.T) {
	var x1 interface{} = &Product{
		Arr: &[]string{"1", "2"},
		M:   &map[string]string{"a": "hello"},
	}
	s := "hello"
	var x2 interface{} = &Sample{
		M: &map[string]*string{"a": &s},
	}
	v := []Validation{
		{x1,
			[]Constraint{{"x1", Null, true,
				[]Constraint{
					{"Arr", Null, true,
						[]Constraint{
							{"Arr", Empty, true, nil},
							{"Arr", MaxItems, 4, nil},
							{"Arr", UniqueItems, true, nil},
						},
					},
					{"M", Null, false,
						[]Constraint{
							{"M", Empty, false, nil},
							{"M", MinItems, 1, nil},
							{"M", UniqueItems, true, nil},
							{"M", Pattern, "^[a-z]+$", nil},
						},
					},
				},
			}}},
		{x2,
			[]Constraint{
				{"x2", Null, true,
					[]Constraint{
						{"M", Null, false,
							[]Constraint{
								{"M", Empty, false, nil},
								{"M", MinItems, 1, nil},
								{"M", UniqueItems, true, nil},
								{"M", Pattern, "^[a-z]+$", nil},
							},
						},
					},
				},
				{"Name", Empty, true, nil},
			}},
	}
	require.Nil(t, Validate(v))
}

func TestValidate_UnknownType(t *testing.T) {
	var c chan int
	v := []Validation{
		{c,
			[]Constraint{{"c", Null, true, nil}}},
	}
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf(c), v[0].Constraints[0],
			fmt.Sprintf("unknown type %v", reflect.ValueOf(c).Kind())).Error())
}

func TestValidate_example1(t *testing.T) {
	var x1 interface{} = Product{
		Arr: &[]string{"1", "1"},
		M:   &map[string]string{"a": "hello"},
	}
	s := "hello"
	var x2 interface{} = Sample{
		M: &map[string]*string{"a": &s},
	}
	v := []Validation{
		{x1,
			[]Constraint{{"Arr", Null, true,
				[]Constraint{
					{"Arr", Empty, true, nil},
					{"Arr", MaxItems, 4, nil},
					{"Arr", UniqueItems, true, nil},
				}},
				{"M", Null, false,
					[]Constraint{
						{"M", Empty, false, nil},
						{"M", MinItems, 1, nil},
						{"M", UniqueItems, true, nil},
					},
				},
			}},
		{x2,
			[]Constraint{
				{"M", Null, false,
					[]Constraint{
						{"M", Empty, false, nil},
						{"M", MinItems, 1, nil},
						{"M", UniqueItems, true, nil},
					},
				},
				{"Name", Empty, true, nil},
			}},
	}
	s = "Arr"
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf([]string{"1", "1"}), v[0].Constraints[0].Chain[2],
			fmt.Sprintf("all items in parameter %q must be unique; got:%v", s, []string{"1", "1"})).Error())
}

func TestValidate_Int(t *testing.T) {
	n := int32(100)
	v := []Validation{
		{n,
			[]Constraint{
				{"n", MultipleOf, 10, nil},
				{"n", ExclusiveMinimum, 100, nil},
			},
		},
	}
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf(n), v[0].Constraints[1],
			"value must be greater than 100").Error())
}

func TestValidate_IntPointer(t *testing.T) {
	n := int32(100)
	p := &n
	v := []Validation{
		{p,
			[]Constraint{
				{"p", Null, true, []Constraint{
					{"p", ExclusiveMinimum, 100, nil},
				}},
			},
		},
	}
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf(n), v[0].Constraints[0].Chain[0],
			"value must be greater than 100").Error())

	// required paramter
	p = nil
	v = []Validation{
		{p,
			[]Constraint{
				{"p", Null, true, []Constraint{
					{"p", ExclusiveMinimum, 100, nil},
				}},
			},
		},
	}
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf(v[0].TargetValue), v[0].Constraints[0],
			"value can not be null; required parameter").Error())

	// Not required
	p = nil
	v = []Validation{
		{p,
			[]Constraint{
				{"p", Null, false, []Constraint{
					{"p", ExclusiveMinimum, 100, nil},
				}},
			},
		},
	}
	require.Nil(t, Validate(v))
}

func TestValidate_IntStruct(t *testing.T) {
	n := int32(100)
	p := &Product{
		Num: &n,
	}

	v := []Validation{
		{p, []Constraint{{"p", Null, true,
			[]Constraint{
				{"Num", Null, true, []Constraint{
					{"Num", ExclusiveMinimum, 100, nil},
				}},
			},
		}}},
	}
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf(n), v[0].Constraints[0].Chain[0].Chain[0],
			"value must be greater than 100").Error())

	// required paramter
	p = &Product{}
	v = []Validation{
		{p, []Constraint{{"p", Null, true,
			[]Constraint{
				{"p.Num", Null, true, []Constraint{
					{"p.Num", ExclusiveMinimum, 100, nil},
				}},
			},
		}}},
	}
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf(p.Num), v[0].Constraints[0].Chain[0],
			"value can not be null; required parameter").Error())

	// Not required
	p = &Product{}
	v = []Validation{
		{p, []Constraint{{"p", Null, true,
			[]Constraint{
				{"Num", Null, false, []Constraint{
					{"Num", ExclusiveMinimum, 100, nil},
				}},
			},
		}}},
	}
	require.Nil(t, Validate(v))

	// Parent not required
	p = nil
	v = []Validation{
		{p, []Constraint{{"p", Null, false,
			[]Constraint{
				{"Num", Null, false, []Constraint{
					{"Num", ExclusiveMinimum, 100, nil},
				}},
			},
		}}},
	}
	require.Nil(t, Validate(v))
}

func TestValidate_String(t *testing.T) {
	s := "hello"
	v := []Validation{
		{s,
			[]Constraint{
				{"s", Empty, true, nil},
				{"s", Empty, true,
					[]Constraint{{"s", MaxLength, 3, nil}}},
			},
		},
	}
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf(s), v[0].Constraints[1].Chain[0],
			"value length must be less than or equal to 3").Error())

	// required paramter
	s = ""
	v = []Validation{
		{s,
			[]Constraint{
				{"s", Empty, true, nil},
				{"s", Empty, true,
					[]Constraint{{"s", MaxLength, 3, nil}}},
			},
		},
	}
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf(s), v[0].Constraints[1],
			"value can not be null or empty; required parameter").Error())

	// not required paramter
	s = ""
	v = []Validation{
		{s,
			[]Constraint{
				{"s", Empty, false, nil},
				{"s", Empty, false,
					[]Constraint{{"s", MaxLength, 3, nil}}},
			},
		},
	}
	require.Nil(t, Validate(v))
}

func TestValidate_StringStruct(t *testing.T) {
	s := "hello"
	p := &Product{
		Str: &s,
	}

	v := []Validation{
		{p, []Constraint{{"p", Null, true,
			[]Constraint{
				{"p.Str", Null, true, []Constraint{
					{"p.Str", Empty, true, nil},
					{"p.Str", MaxLength, 3, nil},
				}},
			},
		}}},
	}
	// e := ValidationError{
	// 	Constraint:  MaxLength,
	// 	Target:      "Str",
	// 	TargetValue: s,
	// 	Details:     fmt.Sprintf("value length must be less than 3", s),
	// }
	// if z := Validate(v); !reflect.DeepEqual(e, z) {
	// 	t.Fatalf("autorest/validation: Validate failed to return error \nexpect: %v\ngot: %v", e, z)
	// }
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf(s), v[0].Constraints[0].Chain[0].Chain[1],
			"value length must be less than or equal to 3").Error())

	// required paramter - can't be Empty
	s = ""
	p = &Product{
		Str: &s,
	}
	v = []Validation{
		{p, []Constraint{{"p", Null, true,
			[]Constraint{
				{"Str", Null, true, []Constraint{
					{"Str", Empty, true, nil},
					{"Str", MaxLength, 3, nil},
				}},
			},
		}}},
	}
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf(s), v[0].Constraints[0].Chain[0].Chain[0],
			"value can not be null or empty; required parameter").Error())

	// required paramter - can't be null
	p = &Product{}
	v = []Validation{
		{p, []Constraint{{"p", Null, true,
			[]Constraint{
				{"p.Str", Null, true, []Constraint{
					{"p.Str", Empty, true, nil},
					{"p.Str", MaxLength, 3, nil},
				}},
			},
		}}},
	}
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf(p.Str), v[0].Constraints[0].Chain[0],
			"value can not be null; required parameter").Error())

	// Not required
	p = &Product{}
	v = []Validation{
		{p, []Constraint{{"p", Null, true,
			[]Constraint{
				{"Str", Null, false, []Constraint{
					{"Str", Empty, true, nil},
					{"Str", MaxLength, 3, nil},
				}},
			},
		}}},
	}
	require.Nil(t, Validate(v))

	// Parent not required
	p = nil
	v = []Validation{
		{p, []Constraint{{"p", Null, false,
			[]Constraint{
				{"Str", Null, true, []Constraint{
					{"Str", Empty, true, nil},
					{"Str", MaxLength, 3, nil},
				}},
			},
		}}},
	}
	require.Nil(t, Validate(v))
}

func TestValidate_Array(t *testing.T) {
	s := []string{"hello"}
	v := []Validation{
		{s,
			[]Constraint{
				{"s", Null, true,
					[]Constraint{
						{"s", Empty, true, nil},
						{"s", MinItems, 2, nil},
					}},
			},
		},
	}
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf(s), v[0].Constraints[0].Chain[1],
			fmt.Sprintf("minimum item limit is 2; got: %v", len(s))).Error())

	// Empty array
	v = []Validation{
		{[]string{},
			[]Constraint{
				{"s", Null, true,
					[]Constraint{
						{"s", Empty, true, nil},
						{"s", MinItems, 2, nil}}},
			},
		},
	}
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf([]string{}), v[0].Constraints[0].Chain[0],
			"value can not be null or empty; required parameter").Error())

	// null array
	var s1 []string
	v = []Validation{
		{s1,
			[]Constraint{
				{"s1", Null, true,
					[]Constraint{
						{"s1", Empty, true, nil},
						{"s1", MinItems, 2, nil}}},
			},
		},
	}
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf(s1), v[0].Constraints[0],
			"value can not be null; required parameter").Error())

	// not required paramter
	v = []Validation{
		{s1,
			[]Constraint{
				{"s1", Null, false,
					[]Constraint{
						{"s1", Empty, true, nil},
						{"s1", MinItems, 2, nil}}},
			},
		},
	}
	require.Nil(t, Validate(v))
}

func TestValidate_ArrayPointer(t *testing.T) {
	s := []string{"hello"}
	v := []Validation{
		{&s,
			[]Constraint{
				{"s", Null, true,
					[]Constraint{
						{"s", Empty, true, nil},
						{"s", MinItems, 2, nil},
					}},
			},
		},
	}
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf(s), v[0].Constraints[0].Chain[1],
			fmt.Sprintf("minimum item limit is 2; got: %v", len(s))).Error())

	// Empty array
	v = []Validation{
		{&[]string{},
			[]Constraint{
				{"s", Null, true,
					[]Constraint{
						{"s", Empty, true, nil},
						{"s", MinItems, 2, nil}}},
			},
		},
	}
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf([]string{}), v[0].Constraints[0].Chain[0],
			"value can not be null or empty; required parameter").Error())

	// null array
	var s1 *[]string
	v = []Validation{
		{s1,
			[]Constraint{
				{"s1", Null, true,
					[]Constraint{
						{"s1", Empty, true, nil},
						{"s1", MinItems, 2, nil}}},
			},
		},
	}
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf(s1), v[0].Constraints[0],
			"value can not be null; required parameter").Error())

	// not required paramter
	v = []Validation{
		{s1,
			[]Constraint{
				{"s1", Null, false,
					[]Constraint{
						{"s1", Empty, true, nil},
						{"s1", MinItems, 2, nil}}},
			},
		},
	}
	require.Nil(t, Validate(v))
}

func TestValidate_ArrayInStruct(t *testing.T) {
	s := []string{"hello"}
	p := &Product{
		Arr: &s,
	}

	v := []Validation{
		{p, []Constraint{{"p", Null, true,
			[]Constraint{
				{"p.Arr", Null, true, []Constraint{
					{"p.Arr", Empty, true, nil},
					{"p.Arr", MinItems, 2, nil},
				}},
			},
		}}},
	}
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf(s), v[0].Constraints[0].Chain[0].Chain[1],
			fmt.Sprintf("minimum item limit is 2; got: %v", len(s))).Error())

	// required paramter - can't be Empty
	p = &Product{
		Arr: &[]string{},
	}
	v = []Validation{
		{p, []Constraint{{"p", Null, true,
			[]Constraint{
				{"p.Arr", Null, true, []Constraint{
					{"p.Arr", Empty, true, nil},
					{"p.Arr", MinItems, 2, nil},
				}},
			},
		}}},
	}
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf([]string{}), v[0].Constraints[0].Chain[0].Chain[0],
			"value can not be null or empty; required parameter").Error())

	// required paramter - can't be null
	p = &Product{}
	v = []Validation{
		{p, []Constraint{{"p", Null, true,
			[]Constraint{
				{"p.Arr", Null, true, []Constraint{
					{"p.Arr", Empty, true, nil},
					{"p.Arr", MinItems, 2, nil},
				}},
			},
		}}},
	}
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf(p.Arr), v[0].Constraints[0].Chain[0],
			"value can not be null; required parameter").Error())

	// Not required
	v = []Validation{
		{&Product{}, []Constraint{{"p", Null, true,
			[]Constraint{
				{"Arr", Null, false, []Constraint{
					{"Arr", Empty, true, nil},
					{"Arr", MinItems, 2, nil},
				}},
			},
		}}},
	}
	require.Nil(t, Validate(v))

	// Parent not required
	p = nil
	v = []Validation{
		{p, []Constraint{{"p", Null, false,
			[]Constraint{
				{"Arr", Null, true, []Constraint{
					{"Arr", Empty, true, nil},
					{"Arr", MinItems, 2, nil},
				}},
			},
		}}},
	}
	require.Nil(t, Validate(v))
}

func TestValidate_StructInStruct(t *testing.T) {
	p := &Product{
		C: &Child{I: "hello"},
	}
	v := []Validation{
		{p, []Constraint{{"p", Null, true,
			[]Constraint{{"C", Null, true,
				[]Constraint{{"I", MinLength, 7, nil}}},
			},
		}}},
	}
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf(p.C.I), v[0].Constraints[0].Chain[0].Chain[0],
			"value length must be greater than or equal to 7").Error())

	// required paramter - can't be Empty
	p = &Product{
		C: &Child{I: ""},
	}

	v = []Validation{
		{p, []Constraint{{"p", Null, true,
			[]Constraint{{"C", Null, true,
				[]Constraint{{"I", Empty, true, nil}}},
			},
		}}},
	}
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf(p.C.I), v[0].Constraints[0].Chain[0].Chain[0],
			"value can not be null or empty; required parameter").Error())

	// required paramter - can't be null
	p = &Product{}
	v = []Validation{
		{p, []Constraint{{"p", Null, true,
			[]Constraint{{"C", Null, true,
				[]Constraint{{"I", Empty, true, nil}}},
			},
		}}},
	}
	require.Equal(t, Validate(v).Error(),
		createError(reflect.ValueOf(p.C), v[0].Constraints[0].Chain[0],
			"value can not be null; required parameter").Error())

	// Not required
	v = []Validation{
		{&Product{}, []Constraint{{"p", Null, true,
			[]Constraint{{"p.C", Null, false,
				[]Constraint{{"p.C.I", Empty, true, nil}}},
			},
		}}},
	}
	require.Nil(t, Validate(v))

	// Parent not required
	p = nil
	v = []Validation{
		{p, []Constraint{{"p", Null, false,
			[]Constraint{{"p.C", Null, false,
				[]Constraint{{"p.C.I", Empty, true, nil}}},
			},
		}}},
	}
	require.Nil(t, Validate(v))
}

func TestNewError(t *testing.T) {
	p := &Product{}
	v := []Validation{
		{p, []Constraint{{"p", Null, true,
			[]Constraint{{"p.C", Null, true,
				[]Constraint{{"p.C.I", Empty, true, nil}}},
			},
		}}},
	}
	err := createError(reflect.ValueOf(p.C), v[0].Constraints[0].Chain[0], "value can not be null; required parameter")
	z := fmt.Sprintf("batch.AccountClient#Create: Invalid input: %s",
		err.Error())
	require.Equal(t, NewError("batch.AccountClient", "Create", err.Error()).Error(), z)
}

func TestNewErrorWithValidationError(t *testing.T) {
	p := &Product{}
	v := []Validation{
		{p, []Constraint{{"p", Null, true,
			[]Constraint{{"p.C", Null, true,
				[]Constraint{{"p.C.I", Empty, true, nil}}},
			},
		}}},
	}
	err := createError(reflect.ValueOf(p.C), v[0].Constraints[0].Chain[0], "value can not be null; required parameter")
	z := fmt.Sprintf("batch.AccountClient#Create: Invalid input: %s",
		err.Error())
	valError := NewErrorWithValidationError(err, "batch.AccountClient", "Create")
	require.IsType(t, valError, Error{})
	require.Equal(t, valError.Error(), z)
}

redpajama_set_name: RedPajamaGithub


text:
BACKGROUND INVESTIGATIONS GOVERNMENT JOBS
Donald John Trump was born on June 14, , at Jamaica Hospital in the borough of Queens in New York City, the fourth child of Fred Trump, a Bronx-born real estate developer whose parents were German immigrants, and Mary Anne MacLeod Trump, an immigrant from www.tv247.ru grew up with older siblings Maryanne, Fred Jr., and Elizabeth, and younger brother Robert in . Official website for Virginia Coronavirus (COVID) Data, information and resources. Find out how to get your free COVID vaccination. WebJul 20, · Where We Are a Service Provider. Our Customers are organizations such as federal, state, local, tribal, or other municipal government agencies (including administrative agencies, departments, and offices thereof), private businesses, and educational institutions (including without limitation K schools, colleges, universities, and vocational schools), .
Applicants for the federal positions are required to complete a questionnaire and undergo some form of a background check, specifically a suitability review or. Positions in the federal government are classified in three ways: Non-sensitive positions. Public trust positions. National security positions. Each of these positions requires some form of background investigation. For lower levels of security clearances, these investigations typically rely on automated checks of an applicant's history. Browse FEDERAL BACKGROUND INVESTIGATOR jobs ($35k-$65k) from companies near you with job openings that are hiring now and 1-click apply! The personnel security background investigation begins after an individual has been given a conditional offer of employment and has completed the. Official website for Virginia Coronavirus (COVID) Data, information and resources. Find out how to get your free COVID vaccination. WebPositions in the federal government are classified in three ways: Non-sensitive positions. Public trust positions. National security positions. Each of these positions requires some form of background investigation. For lower levels of security clearances, these investigations typically rely on automated checks of an applicant's history. The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this. Q: Why are you going to investigate me? I'm only applying for an entry level job and I don't need a security clearance. A: The interests of. WebMay 17, · Who this information is for. This page contains information for professionals and the public on the epidemiology, virology and clinical features of coronavirus (COVID), the infection caused by. Regular handwashing is one of the best ways to remove germs, avoid getting sick, and prevent the spread of germs to others. Whether you are at home, at work, traveling, or out in the community, find out how handwashing with soap and water can protect you and your family. Goran Dragić shares a long history with Dallas Mavericks star Luka Dončić: 'It's nice to play with him but it's not good when you play against him'. Prior to submitting an appeal to OIP, you have the option to seek dispute resolution services by contacting the Office of Government Information Services (OGIS) at () , or by emailing. Aug 26, · An official website of the United States Government Here's how you know. Official websites www.tv247.ru www.tv247.ru website belongs to an official government organization in the United States. www.tv247.ru websites use HTTPS. A lock () or https:// means you've safely connected to www.tv247.ru website. Share sensitive information only on official, secure. Secure websites use HTTPS certificate. A lock icon () or https:// means you've safely connected to the official website. Share sensitive information only on official, secure websites.
What is a Career as Background Investigator Like?
Criminal background checks at the federal, state and county levels · Social Security number tracking reports and work authorizations · Motor vehicle records. May 17, · Who this information is for. This page contains information for professionals and the public on the epidemiology, virology and clinical features of coronavirus (COVID), the infection caused by. WebAmeriCorps Recognized as Government Leader in Evidence-Based Federal Grants. November 17, AmeriCorps Names New Senior Advisor to the CEO. November 16, See all news. Back to main content. Sign up to hear about our latest news, events, and opportunities. Sign up for our newsletter. Footer about. About. What we do; Our impact;. Job Recruitments; Extra Help Employment; Background Investigations Human Resources Division website at www.tv247.ru The first step of a government background check requires an applicant to fill out a security questionnaire that has extremely personal questions on it. We live in a data-driven world. Almost every transaction and interaction you have with most organisations involves you sharing personal data, such as your name, address and birth date. You share data online too, every time you visit a website, search for or buy something, use social media or send an email. Mar 04, · which convictions must be declared when applying for jobs or insurance which spent cautions or convictions must still be declared The document was updated after the Legal Aid and Sentencing and. Applicants for the federal positions are required to complete a questionnaire and undergo some form of a background check, specifically a suitability review or. DPSAC processes are governed by federal regulations. The U.S. Government conducts background investigations to determine if applicants or employees meet the. To be hired for a federal job, you must undergo a basic background investigation of your criminal and credit histories. The government wants to ensure you. A background investigation is conducted to ensure that the candidate is suitable for employment, i.e. reliable, trustworthy, of good conduct and character. GENERAL QUESTIONS AND ANSWERS ABOUT OPM BACKGROUND INVESTIGATIONS I'm only applying for an entry level job and I don't need a security clearance.
Hotel reservations jobs in gauteng|Ultrasound technician jobs in jacksonville fl
Where We Are a Service Provider. Our Customers are organizations such as federal, state, local, tribal, or other municipal government agencies (including administrative agencies, departments, and offices thereof), private businesses, and educational institutions (including without limitation K schools, colleges, universities, and vocational schools), who use our Services to . Yes, in government jobs, the background of the candidate is checked, but it is done to verify the genuineness of the certificate. · Police Verification: This. Watch full episodes, specials and documentaries with National Geographic TV channel online. The government prefers to be thorough rather than swift when selecting candidates, especially for more sensitive positions. As such, the federal vetting process. About the Background Investigation · Assists Baltimore County in identifying the suitability of job applicants for the position · Preserves the safety and. 4. Prepare for Background Checks For any government agency, you'll need to go through a standard background check. This could consist of your educational. The latest news on Congress, campaigns, elections, policy and everything politics from HuffPost. WebJul 20, · Where We Are a Service Provider. Our Customers are organizations such as federal, state, local, tribal, or other municipal government agencies (including administrative agencies, departments, and offices thereof), private businesses, and educational institutions (including without limitation K schools, colleges, universities, and vocational schools), .
WebJul 20, · If you may need assistance during the application process, or already have a Government Jobs account and are having troubles accessing your account, please contact NEOGOV's Customer Service Center at () The customer service center is available to assist Monday - Friday, am - pm PST, with exception to holiday . Conducting thorough government background checks on a job applicant gives you peace of mind that you're choosing the best person for the position, as well as. Jul 20, · Where We Are a Service Provider. Our Customers are organizations such as federal, state, local, tribal, or other municipal government agencies (including administrative agencies, departments, and offices thereof), private businesses, and educational institutions (including without limitation K schools, colleges, universities, and vocational schools), who . USIS (formerly US Investigations Services) is the largest provider of background investigations and employment screening to the Read more. When evaluating an individual for a security clearance, the government examines an individual's history over years. A Top-Secret investigation will look further. Donald John Trump was born on June 14, , at Jamaica Hospital in the borough of Queens in New York City, the fourth child of Fred Trump, a Bronx-born real estate developer whose parents were German immigrants, and Mary Anne MacLeod Trump, an immigrant from www.tv247.ru grew up with older siblings Maryanne, Fred Jr., and Elizabeth, and younger brother Robert in . Option 2: Two years of experience with primary responsibility for conducting pre-employment background investigations. criminal investigations in a law. The basic government background checks includes a NACI investigation, which uncovers law enforcement, residence, employment, education and credit history.

redpajama_set_name: RedPajamaCommonCrawl


A ribbon engagement ring featuring channel set diamonds in a cross ribbon design. This engagement ring sits flush with our perfectly matched Lily band.
My fiance proposed with the ring and it looks fantastic! I have a size 6 finger and looks great without being overwhelming big for my hand. Everyone complements it. Thank you!
My fiance proposed with this and it exceeded all expectation and dreams I could ever have for a ring! It is so memorizing and just plain gorgeous!
I absolutely love my Lily ring. I know all people who are engaged say this, but I really think that this is the prettiest ring.
I proposed with the Lily ring and it's absolutely beautiful! My fiancee is so impressed with how it looks, and with how it fits!


Botswana is a peaceful, stable, low crime, multi-party democracy with a vigorous free-market economy and a small population (just over two million people). It's a member of the Commonwealth, enjoys one of the world's highest economic growth rates and has the highest GDP per capita in Africa.
The Botswana 'Pula' is one of Africa's strongest currencies. Named after the precious rainfall, it symbolizes the stability of the country itself.
The Botswana government is also very dedicated to the preservation of its wildlife. Sport and trophy hunting have been prohibited since 1st January 2014. With a full 38% of its total land area devoted to national parks, reserves and wildlife management areas, mostly unfenced area, animals are allowed to roam wild and free.


text:
Q: PSOne discs are dirty. Limit Break has trouble loading. How to resolve? I am playing through the original Final Fantasy VII, on a PS2 with the original PSOne discs. I'm only a few hours in, but Tifa's Limit Break is causing the game to sit on a close up of the enemy until I take the disc out, wipe it with a soft cloth, and put it back in.
There are some small circular splodges on there (water drops?) and a few scratches. I'm worried that I will get further into the game and hit a section of the disc that doesn't want to load.
How can I mitigate this?

A: You can try cleaning the disc, with some glasses cleaner and a soft cloth.  Spray a bit of the cleaner on the cloth, and then wipe from the center to the edge of the disc.  This ought to remove most spots, although it won't do much for scratches.
If that doesn't seem to help, most stores that sell used games (ie, your local used game shop) have a machine that can resurface discs.  This isn't a perfect solution, but if cleaning it yourself has failed, it can help.
Finally, you might consider playing on a PC with an emulator - PCs tend to have a bit more error resiliency, and you might even be able to back up the disc to your PC's hard drive, thus reducing the need to depend on an unreliable disc.

redpajama_set_name: RedPajamaStackExchange


The post How To Juice Without A Juicer (It's So Easy!) appeared first on Food Babe.
Get inspired by the Instagram photos of healthy-eating trendsetters who put colorful ingredients at the forefront of their dishes.


text:
Spartan Stadium falcon nest box is empty
WKAR Public Media | By Genevieve Fox
Published June 16, 2022 at 10:35 AM EDT
MSU Fisheries Club
A nest box located on the roof of Spartan Stadium is seen via a MSU Fisheries Club Youtube livestream on the morning of Wednesday, June 15, 2022.
The last of three young peregrine falcons left a nest box Wednesday morning located on top of Spartan Stadium at Michigan State University.
A Youtube livestream showed Wednesday that at least two of the chicks, which hatched last month, were still roaming the stadium's roof, near the box.
MSU Fisheries and Wildlife Club Advisor Jim Schneider said the falcons are expected to migrate south sometime in November.
"It's nature, that's what we want. This is what we're expecting, this is all part of their biology," Schneider said.
Jennifer Owen is a professor at MSU and an expert in behavioral ecology of migratory birds, she says peregrine falcons are sensitive to the environment.
The falcon was once an endangered species, but is now recovered thanks to the banning of the insecticide DDT and human efforts like nesting boxes, Owen said.
"With humans invading natural areas, species oftentimes don't have the habitat that they need," Owen said.
Owen says nesting boxes can mitigate that impact, adding that the falcon is an important indicator of environmental health.
"It's amazing the fascination that people have had with these peregrines. And that's a connection to nature and connecting people to nature in whatever form you can do. That is so critical for people wanting to preserve our natural environment," Owen added.
Schneider is excited that the club was able to help add three new falcons to the now stable population of peregrines.
Since the chicks are banded, Schneider said he's hopeful someone who happens across them will be able to track their movements, though it's unlikely they'll come back to MSU after migrating.
Genevieve's story is brought to you as part of a partnership between WKAR and Michigan State University's Knight Center for Environmental Journalism.
WKAR News Michigan State UniversityBirdwatchingEnvironmentEast Lansing
Genevieve Fox
See stories by Genevieve Fox


Do you understand — Why people are shifting to Incorporating a ChatBot for their business websites or even on many popular social media platforms such as Facebook, Twitter, Telegram and Slack?
Whether Its a smiley rating system, to choose a value, select or book a date in the calendar, pick an option, select value range and a lot more. .
Inspection And mark down the negative and positive stats accumulated from the chatbot responses, work on these and improve the efficacy to gain more leads and revenue.
Collect.chat pricing programs match for any size Businesses! Little, Medium-sized or Big Business profiles. The service enables you to pay monthly or yearly with no credit cardnecessity and supplies a 30-day money back guarantee.
Endless bots, 30 Number of complete Conversations or responses, 30 days up to that answers are on the dashboard or you'll be able to say 30 days of Data storage, and Responses and Insights.
Do not Have Sufficient time to set the chatbot For your WordPress site? Collect.chat gives you Free Chatbot Templates and examples for your website.
To ask name of your customer, pick "Text Question". You can ask your visitor's name or any information that you seek.
Experiment with all the areas given in the Script section. As you are able to add Personalize you chat dialog using variables, use conditional logic, request ratings, discuss your social profiles and hyperlinks etc..
Software experts Recently recognized and awarded our chatbot builder instrument for its capacities and functionality. Collect.Chat went through a review by trusted B2B directory FinancesOnline.com and emerged with a score of 8.0 as well as an ideal 100% user satisfaction score. Reviewers observed how Collect.Chat assists users produce chatbots for websites as options to sales agents and static web forms in engaging visitors.
Reviewers gave their approving nods and conferred on Collect.Chat the 2017 Rising Star Award and Great User Experience Award from FinancesOnline for greatest live chat applications. These badges of distinction are awarded to deserving products which have gained strong customer following on the basis of strong features and complete usability.
A big thank you for FinancesOnline for the honors! Astonishingly, the recognition didn't stop there. Because of the awards and positive review and evaluation, our program was pushed to the top levels of the directory's rankings. Collect.Chat is currently one of FinancesOnline's recommendation within their what's CRM software manual, joining the league of best products in this program category.
Indeed, from a practical Perspective and based on Performance standards, Collect.Chat is top notch. Users save time and money as they do not need to hire coders for creating chat widgets that can easily be deployable to websites as a copy-paste code snippet, as a WordPress plugin, or by simply mailing it to the developer. When the chatbot is installed, Collect.Chat provides details via strong visualizations through the user-friendly dashboard.


"I recently did a go-around at night and scared myself. How can I best control the airplane when performing this maneuver?" - Stuart N.
"Night go-arounds and missed approaches have the potential to be dangerous maneuvers for the unwary.
The problem occurs in situations where the go-around is initiated in poorly lit terrain with poor outside references at night, when the aircraft attitude cannot be controlled precisely. This can lead to a descent into dark terrain or a steep climb leading to a stall.
Anticipation of this situation is a key factor in avoiding flight into terrain or a stall. Be prepared to go directly to your instruments when initiating a go-around or missed approach at night. Use your attitude indicator and airspeed indicator to properly position the nose for a climb as you add power.
This is another good reason to be proficient at basic instrument skills. Instrument proficiency is gained through practice."