|
1 | 1 | import inspect |
2 | 2 | import os |
3 | 3 | import pytest |
4 | | -import unittest |
5 | 4 |
|
6 | 5 |
|
7 | 6 | current_dir: str = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) |
8 | 7 | if os.environ['HOME'] == "/app": |
9 | 8 | current_dir = "/app/tests" |
10 | 9 |
|
| 10 | +project_path: str = os.path.abspath(f"{current_dir}/..") |
11 | 11 | script: str = os.path.abspath(f"{current_dir}/../toolbox.sh") |
12 | 12 |
|
| 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 | + |
13 | 20 | 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" |
15 | 94 | 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