Skip to content

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

Merged
merged 6 commits into from
Mar 12, 2018

Conversation

gmessner
Copy link
Collaborator

@lamdav

  1. Added bean test for ProtectedBranch in TestGitLabApiBeans and fixed issues exposed by the bean test (AccessLevel was a String, not an Integer).
  2. Added all known properties to the example-test-gitlab4j.properties file with comments and added logic to the test classes to skip tests that do not have the required property values set.

@gmessner gmessner force-pushed the feature/protected-branch-and-example-test-properties branch from 3eafed8 to d4906b7 Compare March 12, 2018 06:59
@gmessner gmessner mentioned this pull request Mar 12, 2018
Copy link
Contributor

@lamdav lamdav left a 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:

  1. Consider stubbing out the example test properties similar to above fields or removing stubs in general to maintain consistency.
  2. Consider using isEmpty() over manually checking string length > 0.
  3. ProtectedBranch test may now have unintended results.

# To test using GitLab4J-API with a proxy, set the following properties
TEST_PROXY_URI=
TEST_PROXY_USERNAME=
TEST_PROXY_PASSWORD=
Copy link
Contributor

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?

Copy link
Collaborator Author

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=

Copy link
Collaborator Author

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.

Copy link
Contributor

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.

Copy link
Collaborator Author

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);
Copy link
Contributor

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.

Copy link
Collaborator Author

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.

Copy link
Contributor

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.

Copy link
Collaborator Author

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) {
Copy link
Contributor

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()) { ... }

Copy link
Collaborator Author

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)));
Copy link
Contributor

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

isEmpty

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See my response above.

@lamdav
Copy link
Contributor

lamdav commented Mar 12, 2018

@gmessner
LGTM

@gmessner
Copy link
Collaborator Author

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.

@gmessner gmessner merged commit 2267922 into master Mar 12, 2018
@gmessner gmessner deleted the feature/protected-branch-and-example-test-properties branch March 12, 2018 19:23
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