Skip to content

Commit

Permalink
test(#738): add unit tests for client file writing
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidiert committed Jan 16, 2025
1 parent fe3c557 commit bff7498
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/gefyra/api/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def connect( # noqa: C901
cargo_endpoint_host=gclient_conf.gefyra_server.split(":")[0],
cargo_endpoint_port=gclient_conf.gefyra_server.split(":")[1],
cargo_container_name=f"gefyra-cargo-{connection_name}",
wireguard_mtu=gclient_conf.wiregard_mtu or mtu,
wireguard_mtu=gclient_conf.wireguard_mtu or mtu,
)

gclient = handle_get_gefyraclient(config, gclient_conf.client_id)
Expand Down
4 changes: 2 additions & 2 deletions client/gefyra/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class GefyraClientConfig:
ca_crt: str
gefyra_server: str
registry: Optional[str]
wiregard_mtu: Optional[str]
wireguard_mtu: Optional[str]

@property
def json(self):
Expand Down Expand Up @@ -178,7 +178,7 @@ def get_client_config(
ca_crt=self.service_account["ca.crt"],
gefyra_server=gefyra_server,
registry=registry,
wiregard_mtu=str(wireguard_mtu),
wireguard_mtu=str(wireguard_mtu),
)
else:
raise ClientConfigurationError(
Expand Down
94 changes: 94 additions & 0 deletions client/tests/unit/test_client_file_manipulations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import json
from gefyra.api.clients import write_client_file
from gefyra.types import GefyraClient
from pytest_kubernetes.providers import AClusterManager



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

add_clients("client-a", kubeconfig=operator.kubeconfig)
client_a: GefyraClient = k3d.kubectl(
["-n", "gefyra", "get", "gefyraclients.gefyra.dev", "client-a"]
)

assert client_a["state"] is not None

k3d.wait(
"gefyraclients.gefyra.dev/client-a",
"jsonpath=.state=WAITING",
namespace="gefyra",
timeout=20,
)

# connect client
k3d.kubectl(
[
"-n",
"gefyra",
"patch",
"gefyraclient",
"client-a",
"--type='merge'",
"--patch='"
+ json.dumps({"providerParameter": {"subnet": "192.168.101.0/24"}})
+ "'",
]
)

k3d.wait(
"gefyraclients.gefyra.dev/client-a",
"jsonpath=.state=ACTIVE",
namespace="gefyra",
timeout=20,
)

client_file_str = write_client_file(
client_id="client-a",
host="localhost",
port="31820",
kubeconfig=k3d.kubeconfig,
kubecontext=k3d.context
)

client_file_json = json.loads(client_file_str)

print(client_file_json)

assert client_file_json["wireguard_mtu"] == "1340"


def test_a_write_client_file_with_registry_and_mtu(operator: AClusterManager):
k3d = operator

client_a: GefyraClient = k3d.kubectl(
["-n", "gefyra", "get", "gefyraclients.gefyra.dev", "client-a"]
)

assert client_a["state"] is not None

k3d.wait(
"gefyraclients.gefyra.dev/client-a",
"jsonpath=.state=ACTIVE",
namespace="gefyra",
timeout=20,
)

client_file_str = write_client_file(
client_id="client-a",
host="localhost",
port="31820",
kubeconfig=k3d.kubeconfig,
kubecontext=k3d.context,
registry="kuchen.io/gefyra",
wireguard_mtu=570
)

client_file_json = json.loads(client_file_str)

print(client_file_json)

assert client_file_json["wireguard_mtu"] == "570"
assert client_file_json["registry"] == "kuchen.io/gefyra"

0 comments on commit bff7498

Please sign in to comment.