Skip to content

Comments

Added support for profiles#7

Open
MaxS-9779 wants to merge 5 commits intoArtemGet:mainfrom
MaxS-9779:add_profiles
Open

Added support for profiles#7
MaxS-9779 wants to merge 5 commits intoArtemGet:mainfrom
MaxS-9779:add_profiles

Conversation

@MaxS-9779
Copy link

No description provided.

@ArtemGet
Copy link
Owner

@VaryaGet take a look.

@ArtemGet
Copy link
Owner

@MaxS-9779 Build is failing, fix it.

@ArtemGet
Copy link
Owner

#6

Copy link
Owner

@ArtemGet ArtemGet left a comment

Choose a reason for hiding this comment

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

@MaxS-9779 Good, tnx for contributing! I suggest fixing build and comments below. I believe it would be better to create separate pr containing EYml and EYmlStr before doing this.

public EValProf(final String key, final Entry<String> content, final String path) {
super(
() -> {
YamlMapping root;
Copy link
Owner

Choose a reason for hiding this comment

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

I beleive if we have same logic to get value from yaml in two places - there is a reason to create separate class EYml.

);
}

private static YamlNode getProfileNode(final YamlMapping root) {
Copy link
Owner

Choose a reason for hiding this comment

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

As I mentioned above, it is better to create separate classes for this - EYml and EYmlStr

Add more tests;
Devide ex handling;
Avoid type casting
@MaxS-9779
Copy link
Author

@ArtemGet

Copy link
Owner

@ArtemGet ArtemGet left a comment

Choose a reason for hiding this comment

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

result = new EVal(key, parsePath(path, profile)).value();
}
} catch (final EntryException exception) {
result = new EVal(key, content).value();
Copy link
Owner

Choose a reason for hiding this comment

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

Imagine 2 cases of application.yaml:

profile: {PROFILE} //imagine user did not set any env value
age:123

and

age:123 //in this application.yaml user did not specify profile at all. 

In first case we MUST rethrow throw an exception to show user that there is a mistake - env is not set (but it needs to be set in case user specified profile by himself)

In second case we are ok with just returning value from application.yaml (as you did)

So, I would do next:
1)Check either there is a profile mention in config (get it via Yaml parsing similar to how its done in EVal, I suggest to move this logic to EYml, EYmlStr classes first in separate pr)
2)If there is profile mention - get profile name (you must handle exception and rethrow it with custom message)
2.1)get value via EVal with new config path - application-{profile_name}.yaml
3)If there is no profile mention - get value from config path that user passed in constructor.

final String profile;
try {
profile = new EVal("entrys.profile", path).value();
if (profile.isBlank()) {
Copy link
Owner

Choose a reason for hiding this comment

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

Im not sure that this case would be possible.

@MaxS-9779
Copy link
Author

@ArtemGet

@MaxS-9779
Copy link
Author

@ArtemGet

Copy link
Owner

@ArtemGet ArtemGet left a comment

Choose a reason for hiding this comment

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

@MaxS-9779 I strongly recommend:
0)Fix build/checkstyle, all jobs must be green otherwise pull-request will be ignored. If there is any reasonable cause for jobs to be failed - write it down.
1)Move EYaml to separate pull-request, add tests. Pay attention that EYaml must be similar to EJson not EVal.
--- After 1 is done and merged ---
2)Rethink constructor parameters in EValProf to make it testable and reusable, add tests.
3)Rethink exception messages, we must provide user a valuable messages with proper context. There is a huge difference between missing profile value and missing profile mapping at all. There must be tests to check which message user will get in different cases.

*
* @since 0.4.0
*/
public class EYaml extends ESafe<String> {
Copy link
Owner

Choose a reason for hiding this comment

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

Lets move it to separate pr and add tests.


/**
* Configuration properties entry.
* By default gets entries from "src/main/resources/application.yaml"
Copy link
Owner

Choose a reason for hiding this comment

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

I dont think that its a good idea, because we already have EVal etc.
The idea of this class might be the same with the EJson. If you want to get values via expression (as done in EVal and your class) it is possible.

return root;
}

private static String ejected(final YamlNode node) throws EntryException {
Copy link
Owner

Choose a reason for hiding this comment

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

Seems like copy-paste from EVal. But I think you would not need this code anymore (read comments above).

super(
() -> {
final String result;
if (new EContains(new EYaml("entrys.profile", path)).value()) {
Copy link
Owner

Choose a reason for hiding this comment

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

How would you know either entry.profile mapping not exists or just its value is missed?

* @since 0.4.0
*/
@SuppressWarnings({"PMD.AvoidDuplicateLiterals", "PMD.TooManyMethods"})
final class EValProfTest {
Copy link
Owner

Choose a reason for hiding this comment

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

I dont see any positive tests with actually using profile value (because you made constructor that is impossible to unit-test).

@Test
void parsesStringWrap() throws EntryException {
Assertions.assertEquals(
" First line.\n Second line.\n",
Copy link
Owner

Choose a reason for hiding this comment

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

Build fails here.

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.

2 participants