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

feat: Add Gitlab CE module #1135

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open

Conversation

Peet-HD
Copy link

@Peet-HD Peet-HD commented Mar 4, 2024

What does this PR do?

Implemented a TestContainer for Gitlab. This can be used to test projects that use the API of gitlab without relying on an actual instance of gitlab.

Why is it important?

This can be super useful to create integration tests for projects that need access to the Gitlab-API. For example this can be used to test a tool that generates an merge request after running a custom pipeline.

How to test this PR

This PR can be tested if someone generates a personal access token and uses it to authenticates against the gitlab testcontainer.

To run this test in your shell:

dotnet test "tests/Testcontainers.Gitlab.Tests/Testcontainers.Gitlab.Tests.csproj"

Copy link

netlify bot commented Mar 4, 2024

Deploy Preview for testcontainers-dotnet ready!

Name Link
🔨 Latest commit 754260a
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-dotnet/deploys/66470a9b53ff470008685b4f
😎 Deploy Preview https://deploy-preview-1135--testcontainers-dotnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@Peet-HD Peet-HD marked this pull request as draft March 4, 2024 15:40
@Peet-HD Peet-HD marked this pull request as ready for review March 4, 2024 16:49
@HofmeisterAn HofmeisterAn added enhancement New feature or request module An official Testcontainers module labels Mar 11, 2024
@HofmeisterAn
Copy link
Collaborator

Sorry for the late response. I will try to review the module next week.

@Peet-HD Peet-HD marked this pull request as draft April 26, 2024 22:05
@Peet-HD Peet-HD marked this pull request as ready for review April 29, 2024 08:42
Copy link
Collaborator

@HofmeisterAn HofmeisterAn left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. I have some questions before I continue the review.

/// <summary>
/// This is the default image for gitlab community edition.
/// </summary>
public const string GitlabImage = "gitlab/gitlab-ce";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we please pin the version?

Copy link
Author

Choose a reason for hiding this comment

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

Sure thing. I tested with the latest image, with is version 16.11.1 .

Comment on lines 57 to 61
.WithWaitStrategy(Wait.ForUnixContainer().UntilFileExists("/etc/gitlab/initial_root_password"))
.WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(80))
.WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(22))
.WithWaitStrategy(Wait.ForUnixContainer().UntilContainerIsHealthy())
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(request => request.ForPath("/users/sign_in").ForStatusCode(HttpStatusCode.OK)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This overrides the previous wait strategies. You need to add the wait strategy once (you can chain the until members though).

Copy link
Author

Choose a reason for hiding this comment

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

I've fixed the WaitStrategy so that the previous strategy will not be overwritten.

/// <returns>Returns the initial root password generated by gitlab.</returns>
private async Task<string> GetInitialRootPassword()
{
var byteArray = await ReadFileAsync("/etc/gitlab/initial_root_password");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Testcontainers allows uploading files before the container starts. Can we upload the initial_root_password file to specify the password? Can we simply use basic authentication? This would make the module simpler and should be enough for testing purposes (I guess).

Copy link
Author

Choose a reason for hiding this comment

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

Yeah I checked last night if there is some easier method to provide a root password and there a sereval ways. You can set the root password with an environment variable named GITLAB_ROOT_PASSWORD (see here for dokumentation). Another way would be to provide a file named root_password.txt in the root directory. This is documented here.

I would strongly prefer to set the root password via an environment variable, would either way would be valid. I try to find some time this week to resolve this.

If you have an preferred implementation than just let me know.

Copy link
Author

Choose a reason for hiding this comment

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

Should be fixed now. I've selected the approach via an environment variable just to keep it simple.

Set version of docker image to 16.11.1
Fixed WaitStrategy so that all conditions are met and are not overwritten by latest condition.
Add support to set the root password for gitlab
@Peet-HD Peet-HD requested a review from HofmeisterAn May 1, 2024 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request module An official Testcontainers module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants