Skip to content

Commit

Permalink
#44: Fixed that CIPrepare creates the log file as a directory (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkilias authored Jul 7, 2023
1 parent 5e7ae75 commit 2d6a535
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 105 deletions.
1 change: 1 addition & 0 deletions doc/changes/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changes

* [1.3.2](changes_1.3.2.md)
* [1.3.1](changes_1.3.1.md)
* [1.3.0](changes_1.3.0.md)
* [1.2.0](changes_1.2.0.md)
Expand Down
23 changes: 23 additions & 0 deletions doc/changes/changes_1.3.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Script-Languages-Container-CI 1.3.2, 2023-07-07

Code name: Bugfix for the Bugfix in 1.3.1

## Summary

This release fixes a bug which was in the Bugfix in 1.3.1

## Bug Fixes

- #44: CIPrepare creates the log file as a directory

## Features / Enhancements

n/a

## Documentation

n/a

## Refactoring

n/a
2 changes: 1 addition & 1 deletion exasol_script_languages_container_ci/lib/ci_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ class CIPrepare:

def prepare(self):
log_path = Path(DEFAULT_OUTPUT_DIRECTORY) / "jobs" / "logs" / "main.log"
log_path.mkdir(parents=True, exist_ok=True)
log_path.parent.mkdir(parents=True, exist_ok=True)
os.environ[luigi_log_config.LOG_ENV_VARIABLE_NAME] = f"{log_path.absolute()}"
206 changes: 113 additions & 93 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "exasol-script-languages-container-ci"
version = "1.3.1"
version = "1.3.2"
description = "Implements CI builds for script-language-container."

license = "MIT"
Expand Down
7 changes: 7 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from inspect import cleandoc
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest import mock
from unittest.mock import patch, MagicMock

import pytest
Expand Down Expand Up @@ -55,6 +56,12 @@ def test_containers_folder(resources_path: Path) -> Path:
return resources_path / "test_containers"


@pytest.fixture()
def mock_settings_env_vars():
with mock.patch.dict(os.environ, {}):
yield


@pytest.fixture(autouse=True)
def tmp_test_dir():
"""
Expand Down
1 change: 0 additions & 1 deletion test/integration_tests/test_ci_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def test(input_docker_build_repository,
test_type = "successful"
flavor_path = str(flavors_path / test_type)
test_container_folder = str(test_containers_folder / test_type)
print("cwd",Path(".").absolute())
with not_raises(Exception):
CIBuild().build(
flavor_path=(flavor_path,),
Expand Down
28 changes: 28 additions & 0 deletions test/integration_tests/test_ci_prepare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import logging
import os
from pathlib import Path

import pytest
from exasol_integration_test_docker_environment.lib.base import luigi_log_config

from exasol_script_languages_container_ci.lib.ci_build import CIBuild
from exasol_script_languages_container_ci.lib.ci_prepare import CIPrepare

def test(flavors_path,
test_containers_folder,
mock_settings_env_vars):
test_type = "successful"
flavor_path = str(flavors_path / test_type)
test_container_folder = str(test_containers_folder / test_type)
CIPrepare().prepare()
CIBuild().build(
flavor_path=(flavor_path,),
rebuild=False,
commit_sha="COMMIT_SHA",
build_docker_repository="input_docker_build_repository",
docker_user=None,
docker_password=None,
test_container_folder=test_container_folder
)
log_path = Path(os.environ[luigi_log_config.LOG_ENV_VARIABLE_NAME])
assert log_path.is_file()
45 changes: 36 additions & 9 deletions test/unit_tests/test_ci_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,46 @@
from exasol_script_languages_container_ci.lib.ci_prepare import CIPrepare


@pytest.fixture(autouse=True)
def mock_settings_env_vars():
with mock.patch.dict(os.environ, {}):
yield


def test_ci_prepare_log_environment_variable_is_set():
EXPECTED_LOG_PARENT_DIRECTORY = Path(DEFAULT_OUTPUT_DIRECTORY) / "jobs" / "logs"
EXPECTED_LOG_FILE = EXPECTED_LOG_PARENT_DIRECTORY / "main.log"


def test_ci_prepare_log_environment_variable_is_set(mock_settings_env_vars):
CIPrepare().prepare()
expected_log_path = str(Path(DEFAULT_OUTPUT_DIRECTORY) / "jobs" / "logs" / "main.log")
assert luigi_log_config.LOG_ENV_VARIABLE_NAME in os.environ \
and os.environ[luigi_log_config.LOG_ENV_VARIABLE_NAME].endswith(expected_log_path)
assert luigi_log_config.LOG_ENV_VARIABLE_NAME in os.environ


def test_ci_prepare_log_path_exists():
def test_ci_prepare_log_environment_variable_is_set_to_the_correct_path(mock_settings_env_vars):
CIPrepare().prepare()
expected_path = str(EXPECTED_LOG_FILE.absolute())
assert os.environ[luigi_log_config.LOG_ENV_VARIABLE_NAME] == expected_path


def test_ci_prepare_log_path_parent_directory_doesnt_exists(mock_settings_env_vars):
CIPrepare().prepare()
assert Path(os.environ[luigi_log_config.LOG_ENV_VARIABLE_NAME]).parent.is_dir()


def test_ci_prepare_log_path_file_doesnt_exist(mock_settings_env_vars):
CIPrepare().prepare()
actual_path = Path(os.environ[luigi_log_config.LOG_ENV_VARIABLE_NAME])
assert not actual_path.exists()


def test_ci_prepare_log_path_parent_directory_exist(mock_settings_env_vars):
EXPECTED_LOG_PARENT_DIRECTORY.mkdir(parents=True)
CIPrepare().prepare()
assert Path(os.environ[luigi_log_config.LOG_ENV_VARIABLE_NAME]).parent == EXPECTED_LOG_PARENT_DIRECTORY.absolute()


def test_ci_prepare_log_path_file_exists(mock_settings_env_vars):
expected_value = "Test"
EXPECTED_LOG_PARENT_DIRECTORY.mkdir(parents=True)
with EXPECTED_LOG_FILE.open("wt") as f:
f.write(expected_value)
CIPrepare().prepare()
actual_path = Path(os.environ[luigi_log_config.LOG_ENV_VARIABLE_NAME])
actual_value = actual_path.read_text()
assert actual_value == expected_value and actual_path == EXPECTED_LOG_FILE.absolute()

0 comments on commit 2d6a535

Please sign in to comment.