Skip to content

Commit

Permalink
test: add unit test cases for custom registry
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidiert committed Nov 12, 2024
1 parent f2ed0c0 commit d73c7e2
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions client/tests/unit/test_clients_with_custom_registry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from time import sleep
from gefyra.types import GefyraClient, GefyraClientState
import pytest
from pytest_kubernetes.providers import AClusterManager


def test_a_create_client(operator: AClusterManager):
k3d = operator
from gefyra.api.clients import add_clients

gclient = add_clients("client-a", kubeconfig=operator.kubeconfig, registry="kuchen.io/gefyra")[0]
assert gclient._config.REGISTRY == "kuchen.io/gefyra"
client_a: GefyraClient = k3d.kubectl(
["-n", "gefyra", "get", "gefyraclients.gefyra.dev", "client-a"]
)
assert client_a["state"] is not None
with pytest.raises(RuntimeError):
gclient.get_client_config(gefyra_server="localhost:31820")
k3d.wait(
"gefyraclients.gefyra.dev/client-a",
"jsonpath=.state=WAITING",
namespace="gefyra",
timeout=20,
)
assert gclient.state is GefyraClientState.WAITING


def test_b_get_client(operator: AClusterManager):
k3d = operator
from gefyra.api.clients import get_client

gclient = get_client("client-a", kubeconfig=operator.kubeconfig)
retries = 10
counter = 0
try:
assert gclient.state is GefyraClientState.WAITING
except AssertionError as e:
if counter >= retries:
raise e
counter += 1
sleep(2)

assert gclient.provider_parameter is None
assert gclient.provider_config is None
k3d.kubectl(["-n", "gefyra", "get", "gefyraclients.gefyra.dev", "client-a"])
config = gclient.get_client_config(gefyra_server="localhost:31820")
assert config.kubernetes_server is not None
assert config.ca_crt is not None
assert config.namespace is not None
assert config.token is not None


def test_c_create_clients(operator: AClusterManager):
k3d = operator
k3d.version()
from gefyra.api.clients import add_clients

for client in ["client-b", "client-c", "client-d", "client-e", "client-f"]:
gclient = add_clients(client, kubeconfig=operator.kubeconfig, registry="kuchen.io/gefyra")[0]
assert gclient._config.REGISTRY == "kuchen.io/gefyra"



def test_d_delete_client(operator: AClusterManager):
k3d = operator
from gefyra.api.clients import delete_client

delete_client("client-f", kubeconfig=operator.kubeconfig)
sleep(2)
with pytest.raises(RuntimeError):
k3d.kubectl(["-n", "gefyra", "get", "gefyraclients.gefyra.dev", "client-f"])

0 comments on commit d73c7e2

Please sign in to comment.