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

Fix: skip fields level while validating #521

Merged
merged 2 commits into from
Jun 18, 2020

Conversation

mtojek
Copy link
Contributor

@mtojek mtojek commented Jun 18, 2020

A bit different implementation of #520 with test coverage.

@elasticmachine
Copy link

💚 Build Succeeded

Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: [Pull request #521 opened]

  • Start Time: 2020-06-18T08:59:56.029+0000

  • Duration: 8 min 26 sec

Test stats 🧪

Test Results
Failed 0
Passed 111
Skipped 0
Total 111

Copy link
Member

@ruflin ruflin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really appreciate the tests!

I'm wondering if as a follow up we should also add two example yaml files to our testdata packages.

@mtojek
Copy link
Contributor Author

mtojek commented Jun 18, 2020

I really appreciate the tests!

I'm wondering if as a follow up we should also add two example yaml files to our testdata packages.

Hm.. we don't have any tests checking failed validation, do we? I think I will open an issue for this.

@mtojek mtojek merged commit 9b38a66 into elastic:master Jun 18, 2020
@jonathan-buttner
Copy link
Contributor

Thanks for taking a look @mtojek I think we're almost there.

I'm still getting this error:

Error: building dataset failed (path: /Users/jbuttner/proj/es/endpoint-package/out/packages/endpoint/0.4.0/dataset/alerts): error building dataset (path: alerts) in package: endpoint: validating required fields failed: validating required fields data failed: finding field failed (searchedName: dataset.type): field 'dataset.type' not found accessing config accessing config
make: *** [run-registry] Error 1

I think this is because fields is an array not a MapStr. When I printed the type I got this: []map[interface{}]interface{}]

So the we'll need tryToMapStr() https://github.com/elastic/package-registry/blob/master/util/mapstr.go#L245 to handle []map[interface{}]interface{}

The test should look like this:

func TestFlattenFieldsData_ObjectWithFields(t *testing.T) {
	data := []MapStr{
		{
			"dataset": MapStr{
				"fields": []MapStr{
					{
						"name": "name",
						"type": "constant_string",
					},
					{
						"name": "type",
						"type": "constant_string",
					},
				},
			},
		},
	}

	flattened := flattenFieldsData(data)
...
}

mtojek pushed a commit to mtojek/package-registry that referenced this pull request Jun 18, 2020
mtojek added a commit that referenced this pull request Jun 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants