Skip to content

Commit

Permalink
chore: revert "test(functional): simplify token creation"
Browse files Browse the repository at this point in the history
This reverts commit 67ab24f.
  • Loading branch information
nejch authored and JohnVillalovos committed Jul 26, 2022
1 parent b661003 commit 4b798fc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
27 changes: 25 additions & 2 deletions tests/functional/conftest.py
Expand Up @@ -60,6 +60,27 @@ def reset_gitlab(gl: gitlab.Gitlab) -> None:
helpers.safe_delete(user, hard_delete=True)


def set_token(container, fixture_dir):
logging.info("Creating API token.")
set_token_rb = fixture_dir / "set_token.rb"

with open(set_token_rb, "r", encoding="utf-8") as f:
set_token_command = f.read().strip()

rails_command = [
"docker",
"exec",
container,
"gitlab-rails",
"runner",
set_token_command,
]
output = check_output(rails_command).decode().strip()
logging.info("Finished creating API token.")

return output


def pytest_report_collectionfinish(config, startdir, items):
return [
"",
Expand Down Expand Up @@ -146,7 +167,7 @@ def _wait(timeout=30, step=0.5):


@pytest.fixture(scope="session")
def gitlab_config(check_is_alive, docker_ip, docker_services, temp_dir):
def gitlab_config(check_is_alive, docker_ip, docker_services, temp_dir, fixture_dir):
config_file = temp_dir / "python-gitlab.cfg"
port = docker_services.port_for("gitlab", 80)

Expand All @@ -163,13 +184,15 @@ def gitlab_config(check_is_alive, docker_ip, docker_services, temp_dir):
f"GitLab container is now ready after {minutes} minute(s), {seconds} seconds"
)

token = set_token("gitlab-test", fixture_dir=fixture_dir)

config = f"""[global]
default = local
timeout = 60
[local]
url = http://{docker_ip}:{port}
private_token = python-gitlab-token
private_token = {token}
api_version = 4"""

with open(config_file, "w", encoding="utf-8") as f:
Expand Down
3 changes: 1 addition & 2 deletions tests/functional/fixtures/docker-compose.yml
Expand Up @@ -35,9 +35,8 @@ services:
entrypoint:
- /bin/sh
- -c
- ruby /create_license.rb && chmod 644 /opt/gitlab/embedded/service/gitlab-rails/db/fixtures/production/* && /assets/wrapper
- ruby /create_license.rb && /assets/wrapper
volumes:
- ${PWD}/tests/functional/fixtures/set_token.rb:/opt/gitlab/embedded/service/gitlab-rails/db/fixtures/production/003_set_token.rb
- ${PWD}/tests/functional/fixtures/create_license.rb:/create_license.rb
ports:
- '8080:80'
Expand Down

0 comments on commit 4b798fc

Please sign in to comment.