Skip to content

Commit

Permalink
test(validate): further tests for is_detection_event_type custom vali…
Browse files Browse the repository at this point in the history
…dator

Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
  • Loading branch information
leodido committed Jul 30, 2024
1 parent 5dd14ca commit b672385
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions validate/isdetectiontype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,41 @@ func TestIsDetectionTypeValidator(t *testing.T) {
}
require.Equal(t, fieldsWithError, maps.Keys(fields))
}

func TestIsDetectionTypeValidatorDetectingWrongStringRepresentation(t *testing.T) {
invalid := test{
AsEnum: detectiontype.Informational,
AsSnakeCase: "informational",
AsCamelCase: "AaaBbb", // String representation
}
fieldsWithError := []string{
"AsCamelCase",
}
errors := Singleton.Struct(invalid).(ValidationErrors)
fields := map[string]string{}
for _, err := range errors {
errMsg := err.Translate(Translator)
assert.True(t, strings.HasSuffix(errMsg, "a valid detection event type"))
fields[err.Field()] = errMsg
}
require.Equal(t, fieldsWithError, maps.Keys(fields))
}

func TestIsDetectionTypeValidatorDetectingWrongCaseRepresentation(t *testing.T) {
invalid := test{
AsEnum: detectiontype.OsNetworkFingerprint,
AsSnakeCase: "osnetwork_fingerprint",
AsCamelCase: "OsNetworkFingerprint",
}
fieldsWithError := []string{
"AsSnakeCase",
}
errors := Singleton.Struct(invalid).(ValidationErrors)
fields := map[string]string{}
for _, err := range errors {
errMsg := err.Translate(Translator)
assert.True(t, strings.HasSuffix(errMsg, "a valid detection event type"))
fields[err.Field()] = errMsg
}
require.Equal(t, fieldsWithError, maps.Keys(fields))
}

0 comments on commit b672385

Please sign in to comment.