Skip to content

Commit 88a8b79

Browse files
committed
add tests to close issues
1 parent 0eccb0a commit 88a8b79

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

scaleway/scaleway/instance/v1/tests/test_instance_sdk.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import pytest
55

6+
from scaleway.instance.v1 import IpType
67
from scaleway.instance.v1.custom_api import InstanceUtilsV1API
78
from scaleway_async.instance.v1 import AttachServerVolumeRequestVolumeType
89
from scaleway_core.client import Client
@@ -18,6 +19,8 @@
1819
commercial_type = "DEV1-S"
1920
zone = "fr-par-1"
2021

22+
# mypy: ignore-errors
23+
2124
@pytest.fixture(scope="module")
2225
@scw_vcr.use_cassette
2326
def instance_block_api() -> tuple[InstanceUtilsV1API, BlockV1Alpha1API]:
@@ -81,7 +84,7 @@ def test_attach_additionnal_volume(instance_block_api: tuple[InstanceUtilsV1API,
8184
def test_list_server(instance_block_api: tuple[InstanceUtilsV1API, BlockV1Alpha1API]) -> None:
8285
instance_api, block_api = instance_block_api
8386
servers = instance_api.list_servers(zone=zone)
84-
assert len(servers.servers) == 1
87+
assert len(servers.servers) >= 1
8588
assert servers.servers[0].name == server_name
8689

8790
@scw_vcr.use_cassette
@@ -99,10 +102,15 @@ def test_create_new_server(instance_block_api: tuple[InstanceUtilsV1API, BlockV1
99102
assert server.server.id is not None
100103
assert server.server.name == server_name
101104

102-
servers = instance_api.list_servers(zone=zone)
103-
assert len(servers.servers) == 2
105+
servers = instance_api.list_servers_all(zone=zone)
106+
assert len(servers) >= 2
104107

105108
instance_api.delete_server(server_id=server.server.id, zone=zone)
106109

107110

111+
@scw_vcr.use_cassette
112+
def test_create_ip(instance_block_api: tuple[InstanceUtilsV1API, BlockV1Alpha1API]) -> None:
113+
instance_api, block_api = instance_block_api
114+
ip = instance_api.create_ip(type_=IpType.ROUTED_IPV6).ip
115+
assert ip.id is not None
108116

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from typing import Any, Generator
2+
3+
import pytest
4+
5+
from scaleway.k8s.v1 import K8SV1API, CNI
6+
from scaleway.vpc.v2 import VpcV2API, PrivateNetwork
7+
from scaleway_core.api import ScalewayException
8+
from scaleway_core.client import Client
9+
from vcr_config import scw_vcr
10+
11+
# mypy: ignore-errors
12+
13+
@pytest.fixture(scope="module")
14+
@scw_vcr.use_cassette
15+
def k8s_api() -> K8SV1API:
16+
client = Client.from_config_file_and_env()
17+
k8s_api = K8SV1API(client)
18+
return k8s_api
19+
20+
@pytest.fixture(scope="module")
21+
@scw_vcr.use_cassette
22+
def private_network() -> Generator[PrivateNetwork, Any, None]:
23+
client = Client.from_config_file_and_env()
24+
vpc_api = VpcV2API(client)
25+
vpc = vpc_api.create_vpc(enable_routing=False)
26+
pn = vpc_api.create_private_network(vpc_id=vpc.id, default_route_propagation_enabled=True)
27+
yield pn
28+
vpc_api.delete_vpc(vpc_id=vpc.id)
29+
30+
31+
def safe_wait_for_cluster(k8s_api: K8SV1API, cluster_id: str):
32+
try:
33+
return k8s_api.wait_for_cluster(cluster_id=cluster_id)
34+
except ScalewayException as e:
35+
err_type = getattr(e, "type", None) or getattr(e, "error", None)
36+
if err_type == "not_found" or "not found" in str(e).lower():
37+
return None
38+
raise
39+
40+
@scw_vcr.use_cassette
41+
def test_k8s_cluster_list(k8s_api: K8SV1API, private_network: PrivateNetwork) -> None:
42+
cluster = k8s_api.create_cluster(type_="kapsule", version="1.32.7", cni=CNI.CILIUM, description="", private_network_id=private_network.id)
43+
assert cluster.id is not None
44+
45+
clusters = k8s_api.list_clusters()
46+
assert clusters.total_count >= 1
47+
48+
k8s_api.delete_cluster(cluster_id=cluster.id, with_additional_resources=True)
49+
cluster = safe_wait_for_cluster(k8s_api=k8s_api, cluster_id=cluster.id)
50+
assert cluster is None

0 commit comments

Comments
 (0)