-
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
Changes from 3 commits
c2186d4
44eb844
d4906b7
1db1f77
cac5f11
5847870
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,33 @@ | ||
# Rename this file to test-gitlab4j.properties with proper property values. | ||
# To test GitLab4J-API you must have access to a gitlab server. | ||
# | ||
# Copy this file to test-gitlab4j.properties and update the property | ||
# values to match the gitlab server you are testing against. | ||
# | ||
# The TEST_PRIVATE_TOKEN and TEST_USERNAME should belong to an admin user | ||
# | ||
|
||
# The following values must be set or testing will fail | ||
TEST_NAMESPACE=some-namespace | ||
TEST_PROJECT_NAME=some-project-name | ||
TEST_HOST_URL=some-gitlab-url | ||
TEST_PRIVATE_TOKEN=some-private-token | ||
TEST_PRIVATE_TOKEN=admin-private-token | ||
TEST_ACCESS_TOKEN=some-access-token | ||
TEST_USERNAME=admin-user | ||
|
||
# To test the GroupApi, set these to an existing group and group-project, and group member | ||
TEST_GROUP= | ||
TEST_GROUP_PROJECT= | ||
TEST_GROUP_MEMBER_USERNAME= | ||
|
||
# To test oauth2Login, set these properties | ||
TEST_LOGIN_USERNAME= | ||
TEST_LOGIN_PASSWORD= | ||
|
||
# To test sudo capability provide a username to sudo as | ||
TEST_SUDO_AS_USERNAME= | ||
|
||
# To test using GitLab4J-API with a proxy, set the following properties | ||
TEST_PROXY_URI= | ||
TEST_PROXY_USERNAME= | ||
TEST_PROXY_PASSWORD= | ||
|
Original file line number | Diff line number | Diff line 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 commentThe reason will be displayed to describe this comment to others. Learn more. Suggest using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. @lamdav |
||
|
||
// Setup a GitLabApi instance to use a proxy | ||
Map<String, Object> clientConfig = ProxyClientConfig.createProxyClientConfig(TEST_PROXY_URI, TEST_PROXY_USERNAME, TEST_PROXY_PASSWORD); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,10 +83,12 @@ public static void setup() { | |
problems += "Problem fetching test group, error=" + gle.getMessage() + "\n"; | ||
} | ||
|
||
try { | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. See my response above |
||
try { | ||
testUser = gitLabApi.getUserApi().getUser(TEST_GROUP_MEMBER_USERNAME); | ||
} catch (GitLabApiException gle) { | ||
problems += "Problem fetching test user, error=" + gle.getMessage() + "\n"; | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
package org.gitlab4j.api; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assume.assumeTrue; | ||
|
||
import java.util.List; | ||
|
||
import org.gitlab4j.api.models.Branch; | ||
import org.gitlab4j.api.models.Project; | ||
import org.gitlab4j.api.models.ProtectedBranch; | ||
|
@@ -10,13 +16,6 @@ | |
import org.junit.Test; | ||
import org.junit.runners.MethodSorters; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assume.assumeTrue; | ||
|
||
/** | ||
* In order for these tests to run you must set the following properties in test-gitlab4j.properties | ||
* | ||
|
@@ -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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Made another change to this. After the revert to protectedBranch the |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,11 +27,11 @@ | |
|
||
/** | ||
* In order for these tests to run you must set the following properties in test-gitlab4j.properties | ||
* | ||
* | ||
* TEST_HOST_URL | ||
* TEST_PRIVATE_TOKEN | ||
* TEST_USERNAME | ||
* | ||
* | ||
* If any of the above are NULL, all tests in this class will be skipped. | ||
* | ||
* TEST_SUDO_AS_USERNAME | ||
|
@@ -56,7 +56,11 @@ public class TestUserApi { | |
TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); | ||
TEST_USERNAME = TestUtils.getProperty("TEST_USERNAME"); | ||
TEST_SUDO_AS_USERNAME = TestUtils.getProperty("TEST_SUDO_AS_USERNAME"); | ||
TEST_SSH_KEY = TestUtils.getProperty("TEST_SSH_KEY"); | ||
TEST_SSH_KEY = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCvbkmGRaANy2nmLrfYa9LkjMqjs9twYZXQKUPK18j" + | ||
"BWmNgnAm818IikxjfFit3Gqnnh9zdNzlzUYs2osmfdHwRLeFY3hKVR6WckGYVroQuV5ArUA4+oME+IIQ2soCv/" + | ||
"vNWfEmp2N1mpBTwi2mIYKurCKv6UpIpGK9D+ezNk5H0waVTK8EvZ/ey69Nu7C7RsbTYeyi5WY/jaUG5JbsEeKY" + | ||
"IW/2DIlUts7gcB2hzXtt7r7+6DLx82Vb+S2jPZu2JQaB4zfgS7LQgzHUy1aAAgUUpuAbvWzuGHKO0p551Ru4qi" + | ||
"tyXN2+OUVXcYAsuIIdGGB0wLvTDgiOOSZWnSE+sg6XX [email protected]"; | ||
} | ||
|
||
private static final String TEST_IMPERSONATION_TOKEN_NAME = "token1"; | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my response above. |
||
|
||
try { | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "develop", | ||
"push_access_levels": [ | ||
{ | ||
"access_level": 40, | ||
"access_level_description": "Masters" | ||
}, | ||
{ | ||
"access_level": 30, | ||
"access_level_description": "Developer access" | ||
} | ||
], | ||
"merge_access_levels": [ | ||
{ | ||
"access_level": 40, | ||
"access_level_description": "Masters" | ||
}, | ||
{ | ||
"access_level": 30, | ||
"access_level_description": "Developer access" | ||
} | ||
] | ||
} |
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:
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.