-
Notifications
You must be signed in to change notification settings - Fork 474
Feature/protected branch and example test properties #156
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
Feature/protected branch and example test properties #156
Conversation
3eafed8
to
d4906b7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gmessner
Just 3 suggestions:
- Consider stubbing out the example test properties similar to above fields or removing stubs in general to maintain consistency.
- Consider using
isEmpty()
over manually checking string length > 0. - ProtectedBranch test may now have unintended results.
example-test-gitlab4j.properties
Outdated
# To test using GitLab4J-API with a proxy, set the following properties | ||
TEST_PROXY_URI= | ||
TEST_PROXY_USERNAME= | ||
TEST_PROXY_PASSWORD= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we follow the above convention of having some stub string such as some-proxy-password
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you imply, to be consistent it should be one way or the other. Providing a value could lead to some confusion, (are these valid values?), so I suggest we remove all values, something like this:
#
# To test GitLab4J-API, you must have access to a GitLab server.
#
# Copy this file to test-gitlab4j.properties and set the property
# values to match the GitLab server you are testing against.
#
# REQUIRED: The following values must be set or the tests will fail.
# The TEST_PRIVATE_TOKEN and TEST_USERNAME must belong to an admin user.
TEST_PRIVATE_TOKEN=
TEST_ACCESS_TOKEN=
TEST_USERNAME=
TEST_NAMESPACE=
TEST_PROJECT_NAME=
TEST_HOST_URL=
# OPTIONAL: To test the GroupApi, set these to an existing group name and group-project name,
# and the username of a group member
TEST_GROUP=
TEST_GROUP_PROJECT=
TEST_GROUP_MEMBER_USERNAME=
# OPTIONAL: To test oauth2Login, set these properties
TEST_LOGIN_USERNAME=
TEST_LOGIN_PASSWORD=
# OPTIONAL: To test sudo capability provide a username to sudo as
TEST_SUDO_AS_USERNAME=
# OPTIONAL: To test using GitLab4J-API with a proxy, set the following properties
TEST_PROXY_URI=
TEST_PROXY_USERNAME=
TEST_PROXY_PASSWORD=
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll push the above unless you have a very reason to do it differently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with what you said about validity. My comment was more so on picking one convention over another.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured that, I just pushed this change.
@@ -77,6 +77,7 @@ public void testGetVersion() throws GitLabApiException { | |||
@Test | |||
public void testProxyConnection() throws GitLabApiException { | |||
assumeTrue(TEST_PROXY_URI != null && TEST_PROXY_USERNAME != null && TEST_PROXY_PASSWORD != null); | |||
assumeTrue(TEST_PROXY_URI.length() > 0 && TEST_PROXY_USERNAME.length() > 0 && TEST_PROXY_PASSWORD.length() > 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest using TEST_PROXY_URI.isEmpty()
for length checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TEST_PROXY_URI.length() > 0
vs
!TEST_PROXY_URI.isEmpty()
When checking for truth, I prefer to use a statement that results in true, not something that has to be negated to produce true. It's just a personal preference and is used throughout GitLab4J, so to change it in these instances would require a sweep through all the code to be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reasoning sounds good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lamdav
FYI, when checking for empty instead of not empty I should be using isEmpty(), so I have gone through all the tests and replaced str.size() == 0 with str.isEmpty(), just thought I would let you know.
testUser = gitLabApi.getUserApi().getUser(TEST_GROUP_MEMBER_USERNAME); | ||
} catch (GitLabApiException gle) { | ||
problems += "Problem fetching test user, error=" + gle.getMessage() + "\n"; | ||
if (TEST_GROUP_MEMBER_USERNAME != null && TEST_GROUP_MEMBER_USERNAME.length() > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (TEST_GROUP_MEMBER_USERNAME != null && !TEST_GROUP_MEMBER_USERNAME.isEmpty()) { ... }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my response above
@@ -157,6 +156,6 @@ public void testProtectBranch() throws GitLabApiException { | |||
List<ProtectedBranch> branches = gitLabApi.getProtectedBranchesApi().getProtectedBranches(project.getId()); | |||
assertNotNull(branches); | |||
assertTrue(branches.stream() | |||
.anyMatch((protectedBranch) -> protectedBranch.getName().equals(TEST_BRANCH_NAME))); | |||
.anyMatch((protectedBranch) -> branch.getName().equals(TEST_BRANCH_NAME))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct me if I am wrong, but I think this should remain unchanged. I wrote this test to protect an unprotected branch, get a list of protected branches, and verify that the unprotected branch is now part of this list.
By changing the name, the assertion will always return true
as branch
is effectively treated as a final
variable (line 155) and should always be TEST_BRANCH_NAME
by the time (line 159) executes. If it does not, (line 155) should have failed with an exception thrown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how that got changed, fixed and pushed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made another change to this. After the revert to protectedBranch the branch
variable was not referenced, and I realized that the contents of the returned protected branch were never really validated, by validating the name, it took care of the unused reference.
@@ -149,7 +153,7 @@ public void testGetOptionalUser() throws GitLabApiException { | |||
@Test | |||
public void testSudoAsUser() throws GitLabApiException { | |||
|
|||
assumeTrue(TEST_SUDO_AS_USERNAME != null); | |||
assumeTrue(TEST_SUDO_AS_USERNAME != null && TEST_SUDO_AS_USERNAME.length() > 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isEmpty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my response above.
@gmessner |
Thanks for all your feedback on this, and the initial contribution. BTW, I'll get to the RunnerApi submission when I get home from my day job tonight. |
@lamdav