|
|
@ -228,9 +228,9 @@ func TestStructPartial(t *testing.T) { |
|
|
|
"SubTest.Test", |
|
|
|
"SubTest.Test", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// p4 := []string{
|
|
|
|
p4 := []string{ |
|
|
|
// "A",
|
|
|
|
"A", |
|
|
|
// }
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
tPartial := &TestPartial{ |
|
|
|
tPartial := &TestPartial{ |
|
|
|
NoTag: "NoTag", |
|
|
|
NoTag: "NoTag", |
|
|
@ -309,123 +309,117 @@ func TestStructPartial(t *testing.T) { |
|
|
|
Equal(t, errs, nil) |
|
|
|
Equal(t, errs, nil) |
|
|
|
|
|
|
|
|
|
|
|
// inversion and retesting Partial to generate failures:
|
|
|
|
// inversion and retesting Partial to generate failures:
|
|
|
|
// errs = validate.StructPartial(tPartial, p1...)
|
|
|
|
errs = validate.StructPartial(tPartial, p1...) |
|
|
|
// NotEqual(t, errs, nil)
|
|
|
|
NotEqual(t, errs, nil) |
|
|
|
// AssertError(t, errs, "TestPartial.Required", "Required", "required")
|
|
|
|
AssertError(t, errs, "TestPartial.Required", "Required", "required") |
|
|
|
|
|
|
|
|
|
|
|
// errs = validate.StructExcept(tPartial, p2)
|
|
|
|
errs = validate.StructExcept(tPartial, p2...) |
|
|
|
// AssertError(t, errs, "TestPartial.Required", "Required", "required")
|
|
|
|
AssertError(t, errs, "TestPartial.Required", "Required", "required") |
|
|
|
|
|
|
|
|
|
|
|
// // reset Required field, and set nested struct
|
|
|
|
// reset Required field, and set nested struct
|
|
|
|
// tPartial.Required = "Required"
|
|
|
|
tPartial.Required = "Required" |
|
|
|
// tPartial.Anonymous.A = ""
|
|
|
|
tPartial.Anonymous.A = "" |
|
|
|
|
|
|
|
|
|
|
|
// // will pass as unset feilds is not going to be tested
|
|
|
|
// will pass as unset feilds is not going to be tested
|
|
|
|
// errs = validate.StructPartial(tPartial, p1)
|
|
|
|
errs = validate.StructPartial(tPartial, p1...) |
|
|
|
// Equal(t, errs, nil)
|
|
|
|
Equal(t, errs, nil) |
|
|
|
|
|
|
|
|
|
|
|
// errs = validate.StructExcept(tPartial, p2)
|
|
|
|
errs = validate.StructExcept(tPartial, p2...) |
|
|
|
// Equal(t, errs, nil)
|
|
|
|
Equal(t, errs, nil) |
|
|
|
|
|
|
|
|
|
|
|
// // ANON CASE the response here is strange, it clearly does what it is being told to
|
|
|
|
// ANON CASE the response here is strange, it clearly does what it is being told to
|
|
|
|
// errs = validate.StructExcept(tPartial.Anonymous, p4)
|
|
|
|
errs = validate.StructExcept(tPartial.Anonymous, p4...) |
|
|
|
// AssertError(t, errs, ".A", "A", "required")
|
|
|
|
Equal(t, errs, nil) |
|
|
|
|
|
|
|
|
|
|
|
// // will fail as unset feild is tested
|
|
|
|
// will fail as unset feild is tested
|
|
|
|
// errs = validate.StructPartial(tPartial, p2)
|
|
|
|
errs = validate.StructPartial(tPartial, p2...) |
|
|
|
// AssertError(t, errs, "TestPartial.Anonymous.A", "A", "required")
|
|
|
|
NotEqual(t, errs, nil) |
|
|
|
|
|
|
|
AssertError(t, errs, "TestPartial.Anonymous.A", "A", "required") |
|
|
|
// errs = validate.StructExcept(tPartial, p1)
|
|
|
|
|
|
|
|
// AssertError(t, errs, "TestPartial.Anonymous.A", "A", "required")
|
|
|
|
errs = validate.StructExcept(tPartial, p1...) |
|
|
|
|
|
|
|
NotEqual(t, errs, nil) |
|
|
|
// // reset nested struct and unset struct in slice
|
|
|
|
AssertError(t, errs, "TestPartial.Anonymous.A", "A", "required") |
|
|
|
// tPartial.Anonymous.A = "Required"
|
|
|
|
|
|
|
|
// tPartial.SubSlice[0].Test = ""
|
|
|
|
// reset nested struct and unset struct in slice
|
|
|
|
|
|
|
|
tPartial.Anonymous.A = "Required" |
|
|
|
// // these will pass as unset item is NOT tested
|
|
|
|
tPartial.SubSlice[0].Test = "" |
|
|
|
// errs = validate.StructPartial(tPartial, p1)
|
|
|
|
|
|
|
|
// Equal(t, errs, nil)
|
|
|
|
// these will pass as unset item is NOT tested
|
|
|
|
|
|
|
|
errs = validate.StructPartial(tPartial, p1...) |
|
|
|
// errs = validate.StructExcept(tPartial, p2)
|
|
|
|
Equal(t, errs, nil) |
|
|
|
// Equal(t, errs, nil)
|
|
|
|
|
|
|
|
|
|
|
|
errs = validate.StructExcept(tPartial, p2...) |
|
|
|
// // these will fail as unset item IS tested
|
|
|
|
Equal(t, errs, nil) |
|
|
|
// errs = validate.StructExcept(tPartial, p1)
|
|
|
|
|
|
|
|
// AssertError(t, errs, "TestPartial.SubSlice[0].Test", "Test", "required")
|
|
|
|
// these will fail as unset item IS tested
|
|
|
|
// Equal(t, len(errs), 1)
|
|
|
|
errs = validate.StructExcept(tPartial, p1...) |
|
|
|
|
|
|
|
AssertError(t, errs, "TestPartial.SubSlice[0].Test", "Test", "required") |
|
|
|
// errs = validate.StructPartial(tPartial, p2)
|
|
|
|
Equal(t, len(errs), 1) |
|
|
|
// //Equal(t, errs, nil)
|
|
|
|
|
|
|
|
// AssertError(t, errs, "TestPartial.SubSlice[0].Test", "Test", "required")
|
|
|
|
errs = validate.StructPartial(tPartial, p2...) |
|
|
|
// Equal(t, len(errs), 1)
|
|
|
|
NotEqual(t, errs, nil) |
|
|
|
|
|
|
|
AssertError(t, errs, "TestPartial.SubSlice[0].Test", "Test", "required") |
|
|
|
// // Unset second slice member concurrently to test dive behavior:
|
|
|
|
Equal(t, len(errs), 1) |
|
|
|
// tPartial.SubSlice[1].Test = ""
|
|
|
|
|
|
|
|
|
|
|
|
// Unset second slice member concurrently to test dive behavior:
|
|
|
|
// errs = validate.StructPartial(tPartial, p1)
|
|
|
|
tPartial.SubSlice[1].Test = "" |
|
|
|
// Equal(t, errs, nil)
|
|
|
|
|
|
|
|
|
|
|
|
errs = validate.StructPartial(tPartial, p1...) |
|
|
|
// // Case note:
|
|
|
|
Equal(t, errs, nil) |
|
|
|
// // were bypassing dive here? by setting a single item?
|
|
|
|
|
|
|
|
// // im not sure anyone would or should do this, I cant think of a reason
|
|
|
|
// NOTE: When specifying nested items, it is still the users responsibility
|
|
|
|
// // why they would but you never know. As for describing this behavior in
|
|
|
|
// to specify the dive tag, the library does not override this.
|
|
|
|
// // documentation I would be at a loss as to do it
|
|
|
|
errs = validate.StructExcept(tPartial, p2...) |
|
|
|
// // especialy concidering the next test
|
|
|
|
NotEqual(t, errs, nil) |
|
|
|
// errs = validate.StructExcept(tPartial, p2)
|
|
|
|
AssertError(t, errs, "TestPartial.SubSlice[1].Test", "Test", "required") |
|
|
|
// Equal(t, errs, nil)
|
|
|
|
|
|
|
|
// //AssertError(t, errs, "TestPartial.SubSlice[1].Test", "Test", "required")
|
|
|
|
errs = validate.StructExcept(tPartial, p1...) |
|
|
|
|
|
|
|
Equal(t, len(errs), 2) |
|
|
|
// // test sub validation:
|
|
|
|
AssertError(t, errs, "TestPartial.SubSlice[0].Test", "Test", "required") |
|
|
|
// // this is diving
|
|
|
|
AssertError(t, errs, "TestPartial.SubSlice[1].Test", "Test", "required") |
|
|
|
// errs = validate.StructExcept(tPartial, p1)
|
|
|
|
|
|
|
|
// AssertError(t, errs, "TestPartial.SubSlice[0].Test", "Test", "required")
|
|
|
|
errs = validate.StructPartial(tPartial, p2...) |
|
|
|
// AssertError(t, errs, "TestPartial.SubSlice[1].Test", "Test", "required")
|
|
|
|
NotEqual(t, errs, nil) |
|
|
|
// Equal(t, len(errs), 2)
|
|
|
|
Equal(t, len(errs), 1) |
|
|
|
|
|
|
|
AssertError(t, errs, "TestPartial.SubSlice[0].Test", "Test", "required") |
|
|
|
// errs = validate.StructPartial(tPartial, p2)
|
|
|
|
|
|
|
|
// //Equal(t, errs, nil)
|
|
|
|
// reset struct in slice, and unset struct in slice in unset posistion
|
|
|
|
// AssertError(t, errs, "TestPartial.SubSlice[0].Test", "Test", "required")
|
|
|
|
tPartial.SubSlice[0].Test = "Required" |
|
|
|
// Equal(t, len(errs), 1)
|
|
|
|
|
|
|
|
|
|
|
|
// these will pass as the unset item is NOT tested
|
|
|
|
// // reset struct in slice, and unset struct in slice in unset posistion
|
|
|
|
errs = validate.StructPartial(tPartial, p1...) |
|
|
|
// tPartial.SubSlice[0].Test = "Required"
|
|
|
|
Equal(t, errs, nil) |
|
|
|
|
|
|
|
|
|
|
|
// // these will pass as the unset item is NOT tested
|
|
|
|
errs = validate.StructPartial(tPartial, p2...) |
|
|
|
// errs = validate.StructPartial(tPartial, p1)
|
|
|
|
Equal(t, errs, nil) |
|
|
|
// Equal(t, errs, nil)
|
|
|
|
|
|
|
|
|
|
|
|
// testing for missing item by exception, yes it dives and fails
|
|
|
|
// errs = validate.StructPartial(tPartial, p2)
|
|
|
|
errs = validate.StructExcept(tPartial, p1...) |
|
|
|
// Equal(t, errs, nil)
|
|
|
|
NotEqual(t, errs, nil) |
|
|
|
|
|
|
|
Equal(t, len(errs), 1) |
|
|
|
// // testing for missing item by exception, yes it dives and fails
|
|
|
|
AssertError(t, errs, "TestPartial.SubSlice[1].Test", "Test", "required") |
|
|
|
// errs = validate.StructExcept(tPartial, p1)
|
|
|
|
|
|
|
|
// AssertError(t, errs, "TestPartial.SubSlice[1].Test", "Test", "required")
|
|
|
|
errs = validate.StructExcept(tPartial, p2...) |
|
|
|
// Equal(t, len(errs), 1)
|
|
|
|
NotEqual(t, errs, nil) |
|
|
|
|
|
|
|
AssertError(t, errs, "TestPartial.SubSlice[1].Test", "Test", "required") |
|
|
|
// // See above case note... this is a variation on the above
|
|
|
|
|
|
|
|
// // when all taken into account it seems super strange!
|
|
|
|
tPartial.SubSlice[1].Test = "Required" |
|
|
|
// errs = validate.StructExcept(tPartial, p2)
|
|
|
|
|
|
|
|
// Equal(t, errs, nil)
|
|
|
|
tPartial.Anonymous.SubAnonStruct[0].Test = "" |
|
|
|
// //AssertError(t, errs, "TestPartial.SubSlice[1].Test", "Test", "required")
|
|
|
|
// these will pass as the unset item is NOT tested
|
|
|
|
|
|
|
|
errs = validate.StructPartial(tPartial, p1...) |
|
|
|
// tPartial.SubSlice[1].Test = "Required"
|
|
|
|
Equal(t, errs, nil) |
|
|
|
|
|
|
|
|
|
|
|
// tPartial.Anonymous.SubAnonStruct[0].Test = ""
|
|
|
|
errs = validate.StructPartial(tPartial, p2...) |
|
|
|
// // these will pass as the unset item is NOT tested
|
|
|
|
Equal(t, errs, nil) |
|
|
|
// errs = validate.StructPartial(tPartial, p1)
|
|
|
|
|
|
|
|
// Equal(t, errs, nil)
|
|
|
|
errs = validate.StructExcept(tPartial, p1...) |
|
|
|
|
|
|
|
NotEqual(t, errs, nil) |
|
|
|
// errs = validate.StructPartial(tPartial, p2)
|
|
|
|
AssertError(t, errs, "TestPartial.Anonymous.SubAnonStruct[0].Test", "Test", "required") |
|
|
|
// Equal(t, errs, nil)
|
|
|
|
|
|
|
|
|
|
|
|
errs = validate.StructExcept(tPartial, p2...) |
|
|
|
// errs = validate.StructExcept(tPartial, p1)
|
|
|
|
NotEqual(t, errs, nil) |
|
|
|
// AssertError(t, errs, "TestPartial.Anonymous.SubAnonStruct[0].Test", "Test", "required")
|
|
|
|
AssertError(t, errs, "TestPartial.Anonymous.SubAnonStruct[0].Test", "Test", "required") |
|
|
|
|
|
|
|
|
|
|
|
// // See above case note... this is a variation on the above
|
|
|
|
|
|
|
|
// // when all taken into account it seems super strange!
|
|
|
|
|
|
|
|
// errs = validate.StructExcept(tPartial, p2)
|
|
|
|
|
|
|
|
// Equal(t, errs, nil)
|
|
|
|
|
|
|
|
// //AssertError(t, errs, "TestPartial.Anonymous.SubAnonStruct[0].Test", "Test", "required")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|