-
Notifications
You must be signed in to change notification settings - Fork 229
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
Gitlab container and tests #1335
Conversation
src/main/resources/org/jenkinsci/test/acceptance/docker/fixtures/GitLabContainer/Dockerfile
Outdated
Show resolved
Hide resolved
pom.xml
Outdated
<dependency> | ||
<groupId>com.squareup.okhttp3</groupId> | ||
<artifactId>okhttp</artifactId> | ||
<version>5.0.0-alpha.11</version> |
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.
is there a reason you aren't using the built-in Java HttpClient?
https://www.baeldung.com/java-9-http-client
this avoids adding another dependency, either way probably shouldn't be using an alpha one
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 switched this over to using java HttpClient. There seems to be lots of configuration options for the java http client, please let me know if you think there is one we should have that I am missing.
I really appreciate your feedback and support with this @timja 😃
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.
Leave several comments
Response response = null; | ||
try { | ||
response = client.newCall(request).execute(); | ||
} catch (IOException e) { |
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.
Why this mapping?
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.
What do you mean by 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.
Comment resolved due to switching over to java http client
return response; | ||
} | ||
|
||
public void deleteRepo(String token) throws IOException { |
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.
public void deleteRepo(String token) throws IOException { | |
public void deleteRepo(String repo) throws IOException { |
You do not need the token as there is a getter for it, but you should not assume there is only one repo...
ProjectApi projApi = new ProjectApi(gitlabapi); | ||
|
||
try { | ||
Project project = projApi.getProjects().get(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.
What if more than one test is running in parallel? There will be more than one repo
} | ||
} | ||
|
||
public String createUserToken() throws IOException, InterruptedException { |
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.
public String createUserToken() throws IOException, InterruptedException { | |
public String createUser(String username) throws IOException, InterruptedException { |
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.
This should allow you to create any user you want and return the token for further auth if needed
@@ -0,0 +1,13 @@ | |||
user = User.create(); | |||
user.name = 'test'; |
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.
Hardcoded, what if this is called by tests in parallel? Is gonna fail. Maybe you can try what is described here https://www.codecademy.com/article/ruby-command-line-argv
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.
what if this is called by tests in parallel
then each test should have its own instance of the container so it doesn't matter (unless we are running multiple tests in the same JVM at once which we are not (threading as opposed to forking))
user = User.create(); | ||
user.name = 'test'; | ||
user.username = 'test'; | ||
user.password = 'oparolaoarecare12!'; |
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.
Same as before, this should be an argument comming from the java call
user.password = 'oparolaoarecare12!'; | ||
user.confirmed_at = '01/01/1990'; | ||
user.admin = true; | ||
user.email = '$test@example.com'; |
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.
Ditto
pom.xml
Outdated
<groupId>com.squareup.okhttp3</groupId> | ||
<artifactId>okhttp</artifactId> | ||
<version>5.0.0-alpha.11</version> | ||
</dependency> |
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.
Ignore that this is in here twice - we have Andra and I working on the same PR so just caught in the crossfire. We are removing as moving to http client shortly so ignore for now 🙂
try { | ||
Project project = projApi.getProjects().get(0); | ||
projApi.deleteProject(project.getId()); | ||
} catch (GitLabApiException e) { |
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.
No need to wrap inside a RuntimeException
just throw it and the test will fail if thrown
src/main/java/org/jenkinsci/test/acceptance/docker/fixtures/GitLabContainer.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jenkinsci/test/acceptance/docker/fixtures/GitLabContainer.java
Outdated
Show resolved
Hide resolved
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 this be in draft until there is a test that exercises some functionality in Jenkins provided by the GitLab plugin?
public HttpResponse<String> createRepo(String repoName, String token) throws IOException { | ||
try{ | ||
HttpRequest request = HttpRequest.newBuilder() | ||
.uri(new URI("http://" + getIpAddress() + "/api/v4/projects")) |
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 think this will not work in all scenarious - the web port has not been configured as exposed (@DockerFixture(id = "gitlab-plugin", ports = 22)
) and as such you may not be able to communicate witht the web interface of GitLab depending on your docker setup. IIUC you should add a new mapping for the web port.
Additionally you have getURL()
that you should call to then addon the endpoint rather than repeating yourself.
src/main/java/org/jenkinsci/test/acceptance/docker/fixtures/GitLabContainer.java
Outdated
Show resolved
Hide resolved
|
||
public URL getURL() throws IOException { | ||
// return new URL("http://" + host() + ":" + port()); | ||
return new URL("http://" + getIpAddress()); |
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.
you need to use the ipaddress and port that is mapped here.
src/main/java/org/jenkinsci/test/acceptance/docker/fixtures/GitLabContainer.java
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,13 @@ | |||
user = User.create(); | |||
user.name = 'test'; |
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.
what if this is called by tests in parallel
then each test should have its own instance of the container so it doesn't matter (unless we are running multiple tests in the same JVM at once which we are not (threading as opposed to forking))
.until( () -> { | ||
try { | ||
HttpRequest request = HttpRequest.newBuilder() | ||
.uri(new URI("http://" + getIpAddress())) |
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.
use getURL()
public void waitForReady(CapybaraPortingLayer p) { | ||
int timeout = (int) time.milliseconds(200000); | ||
p.waitFor().withMessage("Waiting for GitLab to come up") | ||
.withTimeout(Duration.ofSeconds(timeout)) // GitLab starts in about 2 minutes |
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.
would be so much more readable with something like
.withTimeout(Duration.ofSeconds(timeout)) // GitLab starts in about 2 minutes | |
.withTimeout(Duration.ofSeconds(60 * 2)) // GitLab starts in about 2 minutes |
or
suggestion
.withTimeout(Duration.ofMinutes(2)) // GitLab starts in about 2 minutes
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.
some incorect use of Elastic time with wait.
src/main/java/org/jenkinsci/test/acceptance/plugins/gitlab_plugin/GitLabServerConfig.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jenkinsci/test/acceptance/docker/fixtures/GitLabContainer.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jenkinsci/test/acceptance/docker/fixtures/GitLabContainer.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jenkinsci/test/acceptance/plugins/gitlab_plugin/GitLabOrganizationFolder.java
Outdated
Show resolved
Hide resolved
user.save!; | ||
|
||
token = user.personal_access_tokens.create(scopes: [:api], name: 'MyToken'); | ||
token.expires_at='01/01/2024'; |
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.
This will be problematic in 4 months.
this.assertExistAndResult(failureJob, false); | ||
|
||
// delete the repo when finished | ||
container.deleteRepo(getPrivateTokenAdmin(), repoName); |
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.
This should be done in a @After
method or in a try { ... } finally {...}
block because if any of the asserts above fails then the repo won't be deleted otherwise.
|
||
private String groupName = "firstgroup"; | ||
|
||
private String JenkinsfileContent = "pipeline {\n" + |
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.
This pipeline is using declarative syntax which should mean you need to declare the pipeline-model-definition
plugin in the @WithPlugins
annotation.
Can we get this merged, please? No blockers apparently and the builder is happy |
@rsandell master is broken - looks like this PR is broken on java21? |
Can this please be looked at quickly? It's breaking all PRs. |
This is from my first look at these failures: #1364 (comment) |
Possible fix #1365 |
Testing done
Submitter checklist