|
|
|
@ -12286,3 +12286,40 @@ func TestMultiOrOperatorGroup(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestBase58Validation(t *testing.T) { |
|
|
|
|
tests := []struct { |
|
|
|
|
Value string `validate:"base58"` |
|
|
|
|
Expected bool |
|
|
|
|
}{ |
|
|
|
|
{"kpDDATsPB4AR2WmSDUiNuUz8Y9VFqN3WrDqyZTeC3hL", true}, |
|
|
|
|
{"", false}, |
|
|
|
|
{Value: "2TdKEvPTKpDtJo6pwxd79atZFQNWiSUT2T47nF9j5qFI", Expected: false}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
validate := New() |
|
|
|
|
|
|
|
|
|
for i, test := range tests { |
|
|
|
|
errs := validate.Var(test.Value, "base58") |
|
|
|
|
if test.Expected { |
|
|
|
|
if !IsEqual(errs, nil) { |
|
|
|
|
t.Fatalf("Index: %d Var() failed Error: %s", i, errs) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if IsEqual(errs, nil) { |
|
|
|
|
t.Fatalf("Index: %d Var() failed Error: %s", i, errs) |
|
|
|
|
} else { |
|
|
|
|
val := getError(errs, "", "") |
|
|
|
|
if val.Tag() != "base58" { |
|
|
|
|
t.Fatalf("Index: %d Var() failed Error: %s", i, errs) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for i, test := range tests { |
|
|
|
|
errs := validate.Struct(test) |
|
|
|
|
if (test.Expected && errs != nil) || (!test.Expected && errs == nil) { |
|
|
|
|
t.Fatalf("Index: %d Struct() failed Error: %s", i, errs) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|