Skip to content

[Rest Api Compatibility] Add transformation for simple text replaces #71118

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

Merged
merged 7 commits into from
Apr 12, 2021

Conversation

pgomulka
Copy link
Contributor

@pgomulka pgomulka commented Mar 31, 2021

This commits adds a simple textual replace transformation for Rest Api Compatibility testing.
It allows to replace simple key-value pairs. For instance used in this PR to replace is_true and is_false.
is_true: old_value with is_true: new_value

This commits adds a simple textual replace transformation for Rest Api
Compatibility testing
@pgomulka pgomulka added v8.0.0 :Delivery/Tooling Developer tooliing and automation labels Mar 31, 2021
@pgomulka pgomulka self-assigned this Mar 31, 2021
@elasticmachine elasticmachine added the Team:Delivery Meta label for Delivery team label Mar 31, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-delivery (Team:Delivery)

@pgomulka pgomulka requested a review from jakelandis March 31, 2021 15:20
Copy link
Contributor

@jakelandis jakelandis left a comment

Choose a reason for hiding this comment

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

Looking good just a few minor requests.

@@ -27,4 +28,8 @@
default String requiredChildKey() {
return null;
}

default boolean matches(JsonNode child) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Javadoc please.

/**
* A transformation to replace the flat textual fields.
*/
public class ReplaceTextual implements RestTestTransformByParentObject {
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be abstract ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can certainly make it abstract, but why?
All the difference will be a constructor parameter, the implementation stays the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

It stems from a minor preference to introduce ReplaceIsTrue and ReplaceIsFalse (I thought I saw before, but must be mis-remebering) , where they are very small subclasses that define a hardcoded keyname. I think this helps abit with readability especially since the number of valid key names is very small. It also prevents someone using an invalid key name (invalid in the sense that is not supported by the testing framework).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not too sure this will help much. I am actually worried that this will lead to class explosion - new class for each keyword.
For the time being, I will change the scope of ReplaceTextual to package (for testing) and create ReplaceIsTrue/False. I think we should to revisit and refactor this back once we have more keywords to support.

Copy link
Contributor

Choose a reason for hiding this comment

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

worried that this will lead to class explosion

I am not too worried about it. There are only a small handful of keys, here are the top level: https://github.com/elastic/elasticsearch/blob/master/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/ExecutableSection.java#L26 and then a few more within those top level ones.

I think we should to revisit and refactor this back once we have more keywords to support.

Agreed, assuming we can avoid contract by String... something like an enum of known keys or the like as part of a contract.

@@ -101,6 +103,28 @@ public void replaceMatch(String subKey, Object value) {
transformations.add(new ReplaceMatch(subKey, MAPPER.convertValue(value, JsonNode.class)));
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a Gradle test for these 2 to YamlRestCompatTestPluginFuncTest / "transform task executes and works as configured" ?

When updating these just add the task configuration to the build file, the thing you want to change to the test.yml. The test should fail and output the result. In the past I just copy/paste that output and ensure that the diff looks correct (e.g. the only thing that changed is what is expected).

@@ -0,0 +1,108 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather then using the match folder, can you create a new folder "text_replace" (or the like).
Also, it might be good to remove some the the "match" for readbility and add test for something like "[key/value]_not_to_replace".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do. I will also need to tweak the test to be more rigid - I missed a case where a key can be key_to_replace, but value is not to be replace. The impl was correct, just a test was not asserting about this.
I have a feeling that we will have to revisit these tests and simplify/make them more readable.


@Override
protected boolean getHumanDebug() {
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

can you flip to false before committing.

Copy link
Contributor

@jakelandis jakelandis left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the iterations.

@pgomulka pgomulka merged commit e025272 into elastic:master Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Delivery/Tooling Developer tooliing and automation >enhancement Team:Delivery Meta label for Delivery team v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants