Skip to content

Commit 4f970de

Browse files
committed
refactor: Remove unneeded temp file usage in tests
1 parent 6595a8e commit 4f970de

File tree

2 files changed

+32
-80
lines changed

2 files changed

+32
-80
lines changed

tests/integration/test_cli_service_accounts.py

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import json
2-
import os
32
import subprocess
43
import uuid
54
from collections import defaultdict
65
from typing import Generator, MutableMapping
76

87
import pytest
98

10-
from spark8t.domain import KubernetesResourceType, PropertyFile
9+
from spark8t.domain import KubernetesResourceType
1110
from spark8t.kube_interface.lightkube import LightKubeInterface
1211
from spark8t.literals import (
1312
HUB_LABEL,
@@ -607,25 +606,13 @@ def test_service_account_add_config(
607606
# add integration hub secret for the test service account
608607
secret_name = f"{HUB_LABEL}-{username}"
609608

610-
property_file = PropertyFile({"key": "value"})
611-
612-
with umask_named_temporary_file(
613-
mode="w",
614-
prefix="spark-dynamic-conf-k8s-",
615-
suffix=".conf",
616-
dir=os.path.expanduser("~"),
617-
) as t:
618-
property_file.write(t.file)
619-
620-
t.flush()
621-
622-
kubeinterface.create(
623-
KubernetesResourceType.SECRET_GENERIC,
624-
secret_name,
625-
namespace=namespace,
626-
dry_run=False,
627-
**{"from-env-file": str(t.name)},
628-
)
609+
kubeinterface.create(
610+
KubernetesResourceType.SECRET_GENERIC,
611+
secret_name,
612+
namespace=namespace,
613+
dry_run=False,
614+
extra_args={"key": "value"},
615+
)
629616

630617
assert kubeinterface.exists(
631618
KubernetesResourceType.SECRET_GENERIC, secret_name, namespace
@@ -676,25 +663,13 @@ def test_service_account_remove_config(
676663
# add integration hub secret for the test service account
677664
secret_name = f"{HUB_LABEL}-{username}"
678665

679-
property_file = PropertyFile({"key": "value"})
680-
681-
with umask_named_temporary_file(
682-
mode="w",
683-
prefix="spark-dynamic-conf-k8s-",
684-
suffix=".conf",
685-
dir=os.path.expanduser("~"),
686-
) as t:
687-
property_file.write(t.file)
688-
689-
t.flush()
690-
691-
kubeinterface.create(
692-
KubernetesResourceType.SECRET_GENERIC,
693-
secret_name,
694-
namespace=namespace,
695-
dry_run=False,
696-
**{"from-env-file": str(t.name)},
697-
)
666+
kubeinterface.create(
667+
KubernetesResourceType.SECRET_GENERIC,
668+
secret_name,
669+
namespace=namespace,
670+
dry_run=False,
671+
extra_args={"key": "value"},
672+
)
698673

699674
assert kubeinterface.exists(
700675
KubernetesResourceType.SECRET_GENERIC, secret_name, namespace

tests/integration/test_kube_interface.py

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import os
21
from time import sleep
32

43
import pytest
54

65
from spark8t.domain import KubernetesResourceType, PropertyFile
76
from spark8t.kube_interface.lightkube import LightKubeInterface
8-
from spark8t.utils import umask_named_temporary_file
97

108

119
@pytest.mark.parametrize(
@@ -38,25 +36,13 @@ def test_create_exists_delete_secret(
3836
) -> None:
3937
secret_name = "my-secret"
4038

41-
property_file = PropertyFile({"key": "value"})
42-
43-
with umask_named_temporary_file(
44-
mode="w",
45-
prefix="spark-dynamic-conf-k8s-",
46-
suffix=".conf",
47-
dir=os.path.expanduser("~"),
48-
) as t:
49-
property_file.write(t.file)
50-
51-
t.flush()
52-
53-
kubeinterface.create(
54-
KubernetesResourceType.SECRET_GENERIC,
55-
secret_name,
56-
namespace=namespace,
57-
dry_run=False,
58-
**{"from-env-file": str(t.name)},
59-
)
39+
kubeinterface.create(
40+
KubernetesResourceType.SECRET_GENERIC,
41+
secret_name,
42+
namespace=namespace,
43+
dry_run=False,
44+
extra_args={"key": "value"},
45+
)
6046

6147
assert kubeinterface.exists(
6248
KubernetesResourceType.SECRET_GENERIC, secret_name, namespace
@@ -74,25 +60,16 @@ def test_delete_secret_content(
7460
) -> None:
7561
secret_name = "my-secret"
7662

77-
property_file = PropertyFile({"key": "value"})
78-
79-
with umask_named_temporary_file(
80-
mode="w",
81-
prefix="spark-dynamic-conf-k8s-",
82-
suffix=".conf",
83-
dir=os.path.expanduser("~"),
84-
) as t:
85-
property_file.write(t.file)
86-
87-
t.flush()
88-
89-
kubeinterface.create(
90-
KubernetesResourceType.SECRET_GENERIC,
91-
secret_name,
92-
namespace=namespace,
93-
dry_run=False,
94-
**{"from-env-file": str(t.name)},
95-
)
63+
secret_content = {"key": "value"}
64+
property_file = PropertyFile(secret_content)
65+
66+
kubeinterface.create(
67+
KubernetesResourceType.SECRET_GENERIC,
68+
secret_name,
69+
namespace=namespace,
70+
dry_run=False,
71+
extra_args=secret_content,
72+
)
9673

9774
assert kubeinterface.exists(
9875
KubernetesResourceType.SECRET_GENERIC, secret_name, namespace

0 commit comments

Comments
 (0)