Skip to content

Commit 85ff7b3

Browse files
🔨 Added fixes to the toolbox.sh script and updated unit tests.
1 parent 96e76ae commit 85ff7b3

File tree

7 files changed

+358
-882
lines changed

7 files changed

+358
-882
lines changed

docs/index.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,38 @@ This toolbox enables you to install the SonarQube dev environment.
66

77
## Index
88

9+
* [build](#build)
10+
* [compile](#compile)
911
* [docker_env_source](#dockerenvsource)
1012
* [docker_build](#dockerbuild)
1113
* [init](#init)
1214
* [start](#start)
1315
* [stop](#stop)
1416
* [clean](#clean)
1517
* [display_logs](#displaylogs)
16-
* [build](#build)
17-
* [compile](#compile)
1818
* [release](#release)
1919
* [release_push](#releasepush)
2020
* [display_help](#displayhelp)
2121

22+
### build
23+
24+
Compile and package source code with maven.
25+
26+
#### Exit codes
27+
28+
* **0**: If successful.
29+
* **1**: If an error was encountered when building source code.
30+
* **2**: If the ecoCode plugin in target directory cannot be found.
31+
32+
### compile
33+
34+
Compile source code with maven.
35+
36+
#### Exit codes
37+
38+
* **0**: If successful.
39+
* **1**: If an error was encountered when compiling the source code.
40+
2241
### docker_env_source
2342

2443
Export environment variables from .default.docker.env file.
@@ -56,8 +75,8 @@ Starting Docker containers.
5675
#### Exit codes
5776

5877
* **0**: If successful.
59-
* **1**: If the ecoCode plugin is not present in the target folder.
60-
* **2**: If an error was encountered retrieving environment variables.
78+
* **1**: If an error was encountered retrieving environment variables.
79+
* **2**: If the ecoCode plugin is not present in the target folder.
6180
* **3**: If an error was encountered during container startup.
6281

6382
### stop
@@ -89,25 +108,6 @@ Display Docker container logs.
89108
* **0**: If successful.
90109
* **1**: If an error was encountered retrieving environment variables.
91110

92-
### build
93-
94-
Compile and package source code with maven.
95-
96-
#### Exit codes
97-
98-
* **0**: If successful.
99-
* **1**: If an error was encountered when building source code.
100-
* **2**: If the ecoCode plugin in target directory cannot be found.
101-
102-
### compile
103-
104-
Compile source code with maven.
105-
106-
#### Exit codes
107-
108-
* **0**: If successful.
109-
* **1**: If an error was encountered when compiling the source code.
110-
111111
### release
112112

113113
Use maven plugin release to prepare locally next release and next SNAPSHOT.
@@ -120,7 +120,7 @@ Use maven plugin release to prepare locally next release and next SNAPSHOT.
120120

121121
### release_push
122122

123-
Create a push and a new branch with commits previously prepared
123+
Create a push and a new branch with commits previously prepared.
124124

125125
#### Exit codes
126126

mkdocs.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

poetry.lock

Lines changed: 5 additions & 721 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ packages = [{include = "tests/*.py"}]
1414

1515
[tool.poetry.dependencies]
1616
python = "^3.12"
17-
mkdocs = "^1.5.3"
18-
mkdocs-material = "^9.5.11"
19-
mkdocs-include-dir-to-nav = "^1.2.0"
2017

2118
[tool.poetry.group.test]
2219
[tool.poetry.group.test.dependencies]

tests/test_toolbox.py

Lines changed: 202 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,215 @@
11
import inspect
22
import os
33
import pytest
4-
import unittest
54

65

76
current_dir: str = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
87
if os.environ['HOME'] == "/app":
98
current_dir = "/app/tests"
109

10+
project_path: str = os.path.abspath(f"{current_dir}/..")
1111
script: str = os.path.abspath(f"{current_dir}/../toolbox.sh")
1212

13+
14+
def test_function_empty(shell):
15+
ret = shell.run(script, "--test")
16+
assert ret.stderr.rstrip() == "No function to execute"
17+
assert ret.returncode == 1
18+
19+
1320
def test_function_not_exist(shell):
14-
ret = shell.run(script, "test_function")
21+
ret = shell.run(script, "test_function", "--test")
22+
assert ret.stderr.rstrip() == "Function with name test_function does not exist"
23+
assert ret.returncode == 2
24+
25+
26+
@pytest.mark.parametrize("color_key, color_value", [
27+
("R","\x1b[0;31m"),
28+
("G", "\x1b[0;32m"),
29+
("B", "\x1b[0;34m"),
30+
("Y", "\x1b[0;33m"),
31+
("W", "\x1b[0;37m"),
32+
("N", "\x1b[0;0m")
33+
])
34+
def test_colors(shell, color_key, color_value):
35+
ret = shell.run(script, "colors", color_key, "--test")
36+
assert ret.stdout.rstrip() == color_value
37+
assert ret.returncode == 0
38+
39+
40+
def test_info(shell):
41+
ret = shell.run(script, "info", "msg_info", "--test")
42+
assert ret.stdout.rstrip() == "msg_info"
43+
assert ret.returncode == 0
44+
45+
46+
def test_debug(shell):
47+
ret = shell.run(script, "debug", "msg_debug", "--test")
48+
assert ret.stdout.rstrip() == "msg_debug"
49+
assert ret.returncode == 0
50+
51+
52+
def test_error(shell):
53+
ret = shell.run(script, "error", "msg_error", "--test")
54+
assert ret.stderr.rstrip() == "msg_error"
55+
assert ret.returncode == 0
56+
57+
58+
def test_build(shell):
59+
ret = shell.run(script, "build", "--test")
60+
assert len(ret.stdout.splitlines()) == 2
61+
assert ret.stdout.splitlines()[0] == "Building source code in the target folder"
62+
assert ret.stdout.splitlines()[1] == "mvn clean package -Dmaven.clean.failOnError=false -DskipTests"
63+
assert ret.returncode == 0
64+
65+
66+
def test_compile(shell):
67+
ret = shell.run(script, "compile", "--test")
68+
assert len(ret.stdout.splitlines()) == 2
69+
assert ret.stdout.splitlines()[0] == "Compile source code"
70+
assert ret.stdout.splitlines()[1] == "mvn clean compile"
71+
assert ret.returncode == 0
72+
73+
74+
def test_docker_env_source_not_exist(shell):
75+
ret = shell.run(script, "docker_env_source", "--test", "--fixture=1")
76+
assert len(ret.stdout.splitlines()) == 1
77+
assert ret.stdout.splitlines()[0] == "source test_docker_env"
78+
assert ret.stderr.rstrip() == "Cannot find test_docker_env"
79+
assert ret.returncode == 1
80+
81+
82+
def test_docker_env_source(shell):
83+
ret = shell.run(script, "docker_env_source", "--test")
84+
assert len(ret.stdout.splitlines()) == 1
85+
assert ret.stdout.splitlines()[0] == f"source {project_path}/.default.docker.env"
86+
assert ret.returncode == 0
87+
88+
89+
def test_docker_build_env_source_not_exist(shell):
90+
ret = shell.run(script, "docker_build", "--test", "--fixture=1")
91+
assert len(ret.stdout.splitlines()) == 1
92+
assert ret.stdout.splitlines()[0] == "source test_docker_env"
93+
assert ret.stderr.rstrip() == "Cannot find test_docker_env"
1594
assert ret.returncode == 1
16-
assert "Function with name test_function does not exist" in ret.stderr
95+
96+
97+
def test_docker_build(shell):
98+
ret = shell.run(script, "docker_build", "--test")
99+
assert len(ret.stdout.splitlines()) == 3
100+
assert ret.stdout.splitlines()[0] == f"source {project_path}/.default.docker.env"
101+
assert ret.stdout.splitlines()[1] == "Build Docker services"
102+
assert ret.stdout.splitlines()[2] == f"docker compose -f {project_path}/docker-compose.yml build"
103+
assert ret.returncode == 0
104+
105+
106+
def test_init_env_source_not_exist(shell):
107+
ret = shell.run(script, "init", "--test", "--fixture=1")
108+
assert len(ret.stdout.splitlines()) == 3
109+
assert ret.stdout.splitlines()[0] == "Building source code in the target folder"
110+
assert ret.stdout.splitlines()[1] == "mvn clean package -Dmaven.clean.failOnError=false -DskipTests"
111+
assert ret.stdout.splitlines()[2] == "source test_docker_env"
112+
assert ret.stderr.rstrip() == "Cannot find test_docker_env"
113+
assert ret.returncode == 2
114+
115+
116+
def test_init(shell):
117+
ret = shell.run(script, "init", "--test")
118+
assert len(ret.stdout.splitlines()) == 5
119+
assert ret.stdout.splitlines()[0] == "Building source code in the target folder"
120+
assert ret.stdout.splitlines()[1] == "mvn clean package -Dmaven.clean.failOnError=false -DskipTests"
121+
assert ret.stdout.splitlines()[2] == f"source {project_path}/.default.docker.env"
122+
assert ret.stdout.splitlines()[3] == "Creating and starting Docker containers"
123+
assert ret.stdout.splitlines()[4] == f"docker compose -f {project_path}/docker-compose.yml up --build -d"
124+
assert ret.returncode == 0
125+
126+
127+
def test_start_env_source_not_exist(shell):
128+
ret = shell.run(script, "start", "--test", "--fixture=1")
129+
assert len(ret.stdout.splitlines()) == 1
130+
assert ret.stdout.splitlines()[0] == "source test_docker_env"
131+
assert ret.stderr.rstrip() == "Cannot find test_docker_env"
132+
assert ret.returncode == 1
133+
134+
135+
def test_start(shell):
136+
ret = shell.run(script, "start", "--test")
137+
assert len(ret.stdout.splitlines()) == 3
138+
assert ret.stdout.splitlines()[0] == f"source {project_path}/.default.docker.env"
139+
assert ret.stdout.splitlines()[1] == "Starting Docker containers"
140+
assert ret.stdout.splitlines()[2] == f"docker compose -f {project_path}/docker-compose.yml start"
141+
assert ret.returncode == 0
142+
143+
144+
def test_stop_env_source_not_exist(shell):
145+
ret = shell.run(script, "stop", "--test", "--fixture=1")
146+
assert len(ret.stdout.splitlines()) == 1
147+
assert ret.stdout.splitlines()[0] == "source test_docker_env"
148+
assert ret.stderr.rstrip() == "Cannot find test_docker_env"
149+
assert ret.returncode == 1
150+
151+
152+
def test_stop(shell):
153+
ret = shell.run(script, "stop", "--test")
154+
assert len(ret.stdout.splitlines()) == 3
155+
assert ret.stdout.splitlines()[0] == f"source {project_path}/.default.docker.env"
156+
assert ret.stdout.splitlines()[1] == "Stopping Docker containers"
157+
assert ret.stdout.splitlines()[2] == f"docker compose -f {project_path}/docker-compose.yml stop"
158+
assert ret.returncode == 0
159+
160+
161+
def test_clean_env_source_not_exist(shell):
162+
ret = shell.run(script, "clean", "--test", "--fixture=1")
163+
assert len(ret.stdout.splitlines()) == 1
164+
assert ret.stdout.splitlines()[0] == "source test_docker_env"
165+
assert ret.stderr.rstrip() == "Cannot find test_docker_env"
166+
assert ret.returncode == 1
167+
168+
169+
def test_clean(shell):
170+
ret = shell.run(script, "clean", "--test")
171+
assert len(ret.stdout.splitlines()) == 3
172+
assert ret.stdout.splitlines()[0] == f"source {project_path}/.default.docker.env"
173+
assert ret.stdout.splitlines()[1] == "Remove Docker containers, networks and volumes"
174+
assert ret.stdout.splitlines()[2] == f"docker compose -f {project_path}/docker-compose.yml down --volumes"
175+
assert ret.returncode == 0
176+
177+
178+
def test_display_logs_env_source_not_exist(shell):
179+
ret = shell.run(script, "display_logs", "--test", "--fixture=1")
180+
assert len(ret.stdout.splitlines()) == 1
181+
assert ret.stdout.splitlines()[0] == "source test_docker_env"
182+
assert ret.stderr.rstrip() == "Cannot find test_docker_env"
183+
assert ret.returncode == 1
184+
185+
186+
def test_display_logs(shell):
187+
ret = shell.run(script, "display_logs", "--test")
188+
assert len(ret.stdout.splitlines()) == 3
189+
assert ret.stdout.splitlines()[0] == f"source {project_path}/.default.docker.env"
190+
assert ret.stdout.splitlines()[1] == "Display Docker container logs"
191+
assert ret.stdout.splitlines()[2] == f"docker compose -f {project_path}/docker-compose.yml logs -f"
192+
assert ret.returncode == 0
193+
194+
195+
def test_release(shell):
196+
ret = shell.run(script, "release", "--test")
197+
assert len(ret.stdout.splitlines()) == 4
198+
assert ret.stdout.splitlines()[0] == "Creation of 2 commits with release and next SNAPSHOT"
199+
assert ret.stdout.splitlines()[1] == "mvn release:prepare -B -ff -DpushChanges=false -DtagNameFormat=@{project.version}"
200+
assert ret.stdout.splitlines()[2] == "Clean temporary files"
201+
assert ret.stdout.splitlines()[3] == "mvn release:clean"
202+
assert ret.returncode == 0
203+
204+
205+
def test_release_push(shell):
206+
ret = shell.run(script, "release_push", "--test")
207+
assert len(ret.stdout.splitlines()) == 1
208+
assert ret.stdout.splitlines()[0] == "Create a push and a new branch with commits previously prepared"
209+
assert ret.returncode == 0
210+
211+
212+
def test_display_help(shell):
213+
ret = shell.run(script, "display_help", "--test")
214+
assert len(ret.stdout.splitlines()) == 19
215+
assert ret.returncode == 0

0 commit comments

Comments
 (0)