Skip to content

Commit

Permalink
Start adding tests
Browse files Browse the repository at this point in the history
Signed-off-by: Mikayla Thompson <thomika@amazon.com>
  • Loading branch information
mikaylathompson committed May 15, 2024
1 parent 6f0c2ae commit 4534f6c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Cluster():
def __init__(self, config: Dict) -> None:
v = Validator(SCHEMA)
if not v.validate(config):
raise ValueError(f"Invalid config file for cluster: {v.errors}")
raise ValueError("Invalid config file for cluster", v.errors)

self.endpoint = config["endpoint"]
if self.endpoint.startswith("https"):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import pytest
from console_link.models.cluster import Cluster

# Define a valid cluster configuration
valid_cluster_config = {
'endpoint': "https://opensearchtarget:9200",
'allow_insecure': True,
'authorization': {
'type': "basic",
'details': {
'username': "admin",
'password': "myStrongPassword123!"
}
}
}


def test_valid_cluster_config():
cluster = Cluster(valid_cluster_config)
assert isinstance(cluster, Cluster)


def test_invalid_auth_type_refused():
invalid_auth_type = {
'endpoint': "https://opensearchtarget:9200",
'authorization': {
'type': "invalid_type",
}
}
with pytest.raises(ValueError) as excinfo:
Cluster(invalid_auth_type)
assert "Invalid config file for cluster" in excinfo.value.args[0]
assert excinfo.value.args[1]['authorization'] == [{'type': ['unallowed value invalid_type']}]


def test_missing_endpoint_refused():
missing_endpoint = {
'allow_insecure': True,
'authorization': {
'type': "basic",
'details': {
'username': "XXXXX",
'password': "XXXXXXXXXXXXXXXXXXX!"
}
}
}
with pytest.raises(ValueError) as excinfo:
Cluster(missing_endpoint)
assert "Invalid config file for cluster" in excinfo.value.args[0]
assert excinfo.value.args[1]['endpoint'] == ['required field']

0 comments on commit 4534f6c

Please sign in to comment.