-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_kube_config.py
33 lines (31 loc) · 1.29 KB
/
test_kube_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import yaml
os.environ["CLUSTER_NAME"] = "test-cluster"
import botocore.session
from botocore.stub import Stubber
from overpass.kube import create_kube_config
def test_kubeconfig_creation():
file_path = "/tmp/kubeconfig-test"
eks = botocore.session.get_session().create_client('eks', region_name='eu-west-1')
k8s_response = {'cluster': {
'certificateAuthority': {
'data': "certificate-data"
},
'endpoint': "endpoint-url"
}}
expected_response = {'Kind': 'config', 'apiVersion': 'v1',
'clusters': [
{'cluster': {'certificate-authority-data': 'certificate-data', 'server': 'endpoint-url'},
'name': 'kubernetes'}],
'contexts': [{'context': {'cluster': 'kubernetes', 'user': 'test-user'}, 'name': 'lambda'}],
'current-context': 'lambda', 'users': [{'name': 'test-user', 'user': {'name': 'test-user'}}]}
actual_response = None
with Stubber(eks) as stubber:
stubber.add_response('describe_cluster', k8s_response)
if os.path.exists(file_path):
os.remove(file_path)
create_kube_config(file_path, eks, "test-cluster", user_name="test-user")
with open(file_path) as f:
actual_response = yaml.safe_load(f)
print(actual_response)
assert(expected_response == actual_response)