Skip to content

Commit a2b28d1

Browse files
committed
add and fix tests
1 parent 0de1841 commit a2b28d1

File tree

9 files changed

+713
-435
lines changed

9 files changed

+713
-435
lines changed

src/gaiaflow/cli/commands/minikube.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ def dockerize(
124124
typer.echo("Please create a project with Gaiaflow before running this command.")
125125
return
126126
if dockerfile_path:
127-
docker_build_mode = "minikube-user"
127+
docker_handler_mode = "minikube-user"
128128
else:
129-
docker_build_mode = "minikube"
129+
docker_handler_mode = "minikube"
130130
imports.MinikubeManager.run(
131131
gaiaflow_path=gaiaflow_path,
132132
user_project_path=user_project_path,
133133
action=imports.ExtendedAction.DOCKERIZE,
134-
docker_build_mode=docker_build_mode,
134+
docker_handler_mode=docker_handler_mode,
135135
image_name=image_name,
136136
dockerfile_path=dockerfile_path,
137137
)

src/gaiaflow/managers/helpers.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -476,18 +476,17 @@ def __init__(self, gaiaflow_path: Path, os_type: str):
476476
self.os_type = os_type
477477

478478
def create_inline(self):
479-
if self.os_type == "linux" or is_wsl():
480-
kube_config = Path.home() / ".kube" / "config"
481-
backup_config = kube_config.with_suffix(".backup")
482-
483-
self._backup_kube_config(kube_config, backup_config)
484-
self._patch_kube_config(kube_config)
485-
self._write_inline(kube_config)
486-
487-
if backup_config.exists():
488-
shutil.copy(backup_config, kube_config)
489-
backup_config.unlink()
490-
log_info("Reverted kube config to original state.")
479+
kube_config = Path.home() / ".kube" / "config"
480+
backup_config = kube_config.with_suffix(".backup")
481+
482+
self._backup_kube_config(kube_config, backup_config)
483+
self._patch_kube_config(kube_config)
484+
self._write_inline(kube_config)
485+
486+
if backup_config.exists():
487+
shutil.copy(backup_config, kube_config)
488+
backup_config.unlink()
489+
log_info("Reverted kube config to original state.")
491490

492491
def _backup_kube_config(self, kube_config: Path, backup_config: Path):
493492
if kube_config.exists():

src/gaiaflow/managers/minikube_manager.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ def stop(self):
139139
def create_kube_config_inline(self):
140140
self.kube_helper.create_inline()
141141

142-
def build_docker_image(self, dockerfile_path: str):
143-
if not dockerfile_path:
142+
def build_docker_image(self, dockerfile_path: str = ""):
143+
if dockerfile_path != "":
144144
dockerfile_path = (
145145
self.gaiaflow_path / "_docker" / "user-package" / "Dockerfile"
146146
)
@@ -201,7 +201,4 @@ def list_images(self):
201201
self.docker_helper.list_images()
202202

203203
def remove_image(self, image_name: str):
204-
self.docker_helper.remove_image(image_name)
205-
206-
def prune_images(self):
207-
self.docker_helper.prune_images()
204+
self.docker_helper.remove_image(image_name)

tests/cli/commands/test_minikube.py

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
ExtendedAction
99
from gaiaflow.cli.commands.minikube import app as prod_app
1010
from gaiaflow.cli.commands.minikube import load_imports
11+
from gaiaflow.managers.helpers import DockerHandlerMode
12+
1113

1214
class TestGaiaflowProdCLI(unittest.TestCase):
1315
def setUp(self):
@@ -32,15 +34,11 @@ def test_start_command(self, mock_load_imports):
3234

3335
result = self.runner.invoke(prod_app, [
3436
"start",
35-
"--path", str(self.test_project_path),
3637
"--force-new"
3738
])
3839

3940
self.assertEqual(result.exit_code, 0)
4041

41-
self.mock_imports.create_gaiaflow_context_path.assert_called_once_with(
42-
self.test_project_path
43-
)
4442
self.mock_imports.gaiaflow_path_exists_in_state.assert_called_once_with(
4543
self.test_gaiaflow_path, True
4644
)
@@ -59,7 +57,6 @@ def test_start_command_exits_when_project_not_exists(self, mock_load_imports):
5957

6058
result = self.runner.invoke(prod_app, [
6159
"start",
62-
"--path", str(self.test_project_path)
6360
])
6461

6562
self.assertEqual(result.exit_code, 0)
@@ -73,7 +70,6 @@ def test_stop_command(self, mock_load_imports):
7370

7471
result = self.runner.invoke(prod_app, [
7572
"stop",
76-
"--path", str(self.test_project_path)
7773
])
7874

7975
self.assertEqual(result.exit_code, 0)
@@ -90,7 +86,6 @@ def test_restart_command(self, mock_load_imports):
9086

9187
result = self.runner.invoke(prod_app, [
9288
"restart",
93-
"--path", str(self.test_project_path),
9489
"--force-new"
9590
])
9691

@@ -100,6 +95,7 @@ def test_restart_command(self, mock_load_imports):
10095
gaiaflow_path=self.test_gaiaflow_path,
10196
user_project_path=self.test_project_path,
10297
action=BaseAction.RESTART,
98+
force_new=True
10399
)
104100

105101
@patch('gaiaflow.cli.commands.minikube.load_imports')
@@ -108,7 +104,6 @@ def test_dockerize_command(self, mock_load_imports):
108104

109105
result = self.runner.invoke(prod_app, [
110106
"dockerize",
111-
"--path", str(self.test_project_path),
112107
"--image-name", "my-custom-image"
113108
])
114109

@@ -118,8 +113,42 @@ def test_dockerize_command(self, mock_load_imports):
118113
gaiaflow_path=self.test_gaiaflow_path,
119114
user_project_path=self.test_project_path,
120115
action=ExtendedAction.DOCKERIZE,
121-
local=False,
122-
image_name="my-custom-image"
116+
docker_handler_mode=DockerHandlerMode.MINIKUBE,
117+
image_name="my-custom-image", dockerfile_path=None
118+
)
119+
120+
@patch("gaiaflow.cli.commands.minikube.load_imports")
121+
def test_list_images_command(self, mock_load_imports):
122+
mock_load_imports.return_value = self.mock_imports
123+
124+
result = self.runner.invoke(
125+
prod_app, ["list-images"]
126+
)
127+
128+
self.assertEqual(result.exit_code, 0)
129+
130+
self.mock_imports.MinikubeManager.run.assert_called_once_with(
131+
gaiaflow_path=self.test_gaiaflow_path,
132+
user_project_path=self.test_project_path,
133+
action=ExtendedAction.LIST_IMAGES,
134+
docker_handler_mode=DockerHandlerMode.MINIKUBE,
135+
)
136+
137+
@patch("gaiaflow.cli.commands.minikube.load_imports")
138+
def test_remove_image_command(self, mock_load_imports):
139+
mock_load_imports.return_value = self.mock_imports
140+
141+
result = self.runner.invoke(prod_app, ["remove-image", "--image-name",
142+
"my-custom-image"])
143+
144+
self.assertEqual(result.exit_code, 0)
145+
146+
self.mock_imports.MinikubeManager.run.assert_called_once_with(
147+
gaiaflow_path=self.test_gaiaflow_path,
148+
user_project_path=self.test_project_path,
149+
action=ExtendedAction.REMOVE_IMAGE,
150+
docker_handler_mode=DockerHandlerMode.MINIKUBE,
151+
image_name="my-custom-image",
123152
)
124153

125154
@patch('gaiaflow.cli.commands.minikube.load_imports')
@@ -128,7 +157,6 @@ def test_dockerize_command_with_default_image_name(self, mock_load_imports):
128157

129158
result = self.runner.invoke(prod_app, [
130159
"dockerize",
131-
"--path", str(self.test_project_path)
132160
])
133161

134162
self.assertEqual(result.exit_code, 0)
@@ -143,7 +171,6 @@ def test_create_config_command(self, mock_load_imports):
143171

144172
result = self.runner.invoke(prod_app, [
145173
"create-config",
146-
"--path", str(self.test_project_path)
147174
])
148175

149176
self.assertEqual(result.exit_code, 0)
@@ -160,7 +187,6 @@ def test_create_secret_command(self, mock_load_imports):
160187

161188
result = self.runner.invoke(prod_app, [
162189
"create-secret",
163-
"--path", str(self.test_project_path),
164190
"--name", "my-secret",
165191
"--data", "key1=value1",
166192
"--data", "key2=value2"
@@ -186,7 +212,6 @@ def test_cleanup_command(self, mock_load_imports):
186212

187213
result = self.runner.invoke(prod_app, [
188214
"cleanup",
189-
"--path", str(self.test_project_path)
190215
])
191216

192217
self.assertEqual(result.exit_code, 0)
@@ -203,14 +228,13 @@ def test_all_commands_handle_missing_project_gracefully(self, mock_load_imports)
203228
self.mock_imports.gaiaflow_path_exists_in_state.return_value = False
204229

205230
commands_and_args = [
206-
["start", "--path", str(self.test_project_path)],
207-
["stop", "--path", str(self.test_project_path)],
208-
["restart", "--path", str(self.test_project_path)],
209-
["dockerize", "--path", str(self.test_project_path)],
210-
["create-config", "--path", str(self.test_project_path)],
211-
["create-secret", "--path", str(self.test_project_path),
212-
"--name", "test", "--data", "key=value"],
213-
["cleanup", "--path", str(self.test_project_path)],
231+
["start"],
232+
["stop"],
233+
["restart"],
234+
["dockerize"],
235+
["create-config"],
236+
["create-secret", "--name", "test", "--data", "key=value"],
237+
["cleanup"],
214238
]
215239

216240
for command_args in commands_and_args:
@@ -244,7 +268,6 @@ def test_action_objects_comparison(self, mock_load_imports):
244268

245269
result = self.runner.invoke(prod_app, [
246270
"start",
247-
"--path", str(self.test_project_path)
248271
])
249272

250273
self.assertEqual(result.exit_code, 0)

0 commit comments

Comments
 (0)