Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit test for disabled field #2224

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions internal/fields/testdata/disabled.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"disabled": {
"id": "42",
"status": "ok"
}
}
6 changes: 6 additions & 0 deletions internal/fields/testdata/enabled_not_mapped.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"enabled": {
"id": "42",
"status": "ok"
}
}
3 changes: 3 additions & 0 deletions internal/fields/testdata/fields/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@
- name: attributes
type: object
object_type: keyword
- name: disabled
type: object
enabled: false
30 changes: 30 additions & 0 deletions internal/fields/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,36 @@ func TestValidate_ObjectTypeWithoutWildcard(t *testing.T) {
})
}

func TestValidate_DisabledParent(t *testing.T) {
validator, err := CreateValidatorForDirectory("testdata",
WithDisabledDependencyManagement())
require.NoError(t, err)
require.NotNil(t, validator)

t.Run("disabled", func(t *testing.T) {
e := readSampleEvent(t, "testdata/disabled.json")
errs := validator.ValidateDocumentBody(e)
require.Empty(t, errs)
})
}

func TestValidate_EnabledNotMappedError(t *testing.T) {
validator, err := CreateValidatorForDirectory("testdata",
WithDisabledDependencyManagement())
require.NoError(t, err)
require.NotNil(t, validator)

t.Run("enabled", func(t *testing.T) {
e := readSampleEvent(t, "testdata/enabled_not_mapped.json")
errs := validator.ValidateDocumentBody(e)
if assert.Len(t, errs, 2) {
for i := 0; i < 2; i++ {
assert.Contains(t, []string{`field "enabled.id" is undefined`, `field "enabled.status" is undefined`}, errs[i].Error())
}
}
})
}

func TestValidate_WithNumericKeywordFields(t *testing.T) {
validator, err := CreateValidatorForDirectory("testdata",
WithNumericKeywordFields([]string{
Expand Down