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

Truncate app name if too long when using ServiceInstanceGuidSuffix #321

Merged
merged 1 commit into from Jan 28, 2020

Conversation

royclarkson
Copy link
Member

Resolves #204

@codecov
Copy link

codecov bot commented Jan 27, 2020

Codecov Report

Merging #321 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #321      +/-   ##
============================================
+ Coverage     86.07%   86.09%   +0.02%     
- Complexity      983      986       +3     
============================================
  Files           105      105              
  Lines          3252     3258       +6     
  Branches        184      185       +1     
============================================
+ Hits           2799     2805       +6     
  Misses          335      335              
  Partials        118      118
Impacted Files Coverage Δ Complexity Δ
.../extensions/targets/ServiceInstanceGuidSuffix.java 100% <100%> (ø) 6 <4> (+3) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fbe1c75...647f84e. Read the comment docs.

Copy link
Contributor

@LittleBaiBai LittleBaiBai left a comment

Choose a reason for hiding this comment

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

Great improvement! Only one nick-picking comment on the test, but nothing blocks the merge.

Comment on lines 142 to 148
private String assembleNameWithGuidSuffix(String appName, String serviceInstanceId) {
return appName + CONCAT_DELIM + serviceInstanceId;
}

private int calculateAvailableLength(String serviceInstanceId) {
return CF_SERVICE_NAME_MAX_LENGTH - CONCAT_DELIM.length() - serviceInstanceId.length();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This essentially the same logic as in the production code. I personally tend to avoid using code logic to write test, so that we can validate the behavior in two different styles. The exact value don't actually matter, we just want to make sure the name ends up being unique and is less than 50 characters. So maybe we only need to make sure the name includes service instance id, has length of 50, and, optionally, starts with part of the service name. Wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, I see your point. Thanks! We do need to validate that case where the resulting name is less than 50 chars as well. While I don't like duplicating code, I do consider the goal of the test to be to validate the expected results. Even if the code to do that is basically the same now, the new name still needs to be determined somehow for comparison. But I'll reduce that duplication and update the PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, it all depends on how we define the goal of this test.

  • If the behavior we are trying to describe here is exactly how we are truncating and concatenate names, then it will be hard to avoid duplicating the logic.
  • If the behavior is just keep it unique and less than 50 chars, then whether it's a - in between or how we truncate are not a behavioral requirements that needs to be tested. To achieve this goal, where the resulting name is less than 50 chars, we could assert that it contains the service instance id and the full service name.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, redesigned the tests. thanks.

@royclarkson royclarkson force-pushed the 204-truncate-app-name-with-guid-suffix branch from c5b4d88 to 2d94b66 Compare January 27, 2020 23:33
@royclarkson royclarkson force-pushed the 204-truncate-app-name-with-guid-suffix branch from 2d94b66 to 647f84e Compare January 28, 2020 16:35
@royclarkson royclarkson merged commit 80f0357 into master Jan 28, 2020
@royclarkson royclarkson deleted the 204-truncate-app-name-with-guid-suffix branch January 28, 2020 19:50
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.

ServiceInstanceGuidSuffix only works with short service names
2 participants