Skip to content

Commit

Permalink
add scenario tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldmitry committed Jun 26, 2024
1 parent 97e040d commit ad2da3a
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
80 changes: 80 additions & 0 deletions tests/scenario/test_enabled_receivers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import json
import socket

from charms.tempo_k8s.v2.tracing import (
ProtocolType,
Receiver,
TracingProviderAppData,
TracingRequirerAppData,
)
from scenario import Relation, State

from charm import TempoCoordinatorCharm


def test_receivers_with_no_relations_or_config(context, s3, all_worker):

state = State(leader=True, relations=[s3, all_worker])
state_out = context.run_action("list-receivers", state)
assert state_out.results == {"otlp-http": f"http://{socket.getfqdn()}:4318"}


def test_receivers_with_relations(context, s3, all_worker):
tracing = Relation(
"tracing",
remote_app_data=TracingRequirerAppData(receivers=["otlp_grpc"]).dump(),
)
state = State(leader=True, relations=[s3, all_worker, tracing])
with context.manager(tracing.changed_event, state) as mgr:
charm: TempoCoordinatorCharm = mgr.charm
# extra receivers should only include default otlp_http
assert charm.enabled_receivers == set(["otlp_http"])
out = mgr.run()

tracing_out = out.get_relations(tracing.endpoint)[0]
assert tracing_out.remote_app_data == TracingRequirerAppData(receivers=["otlp_grpc"]).dump()
# provider app data should include endpoints for otlp_grpc and otlp_http
provider_data = json.loads(tracing_out.local_app_data.get("receivers"))
assert len(provider_data) == 2

# run action
action_out = context.run_action("list-receivers", state)
assert action_out.results == {
"otlp-http": f"http://{socket.getfqdn()}:4318",
"otlp-grpc": f"http://{socket.getfqdn()}:4317",
}


def test_receivers_with_relations_and_config(context, s3, all_worker):
tracing = Relation(
"tracing",
local_app_data=TracingProviderAppData(
receivers=[
Receiver(
protocol=ProtocolType(name="otlp_grpc", type="grpc"),
url=f"{socket.getfqdn()}:4317",
),
Receiver(
protocol=ProtocolType(name="otlp_http", type="http"),
url=f"{socket.getfqdn()}:4318",
),
]
).dump(),
remote_app_data=TracingRequirerAppData(receivers=["otlp_grpc"]).dump(),
)
# start with a state that has config changed
state = State(
config={"always_enable_zipkin": True}, leader=True, relations=[s3, all_worker, tracing]
)
with context.manager("config-changed", state) as mgr:
charm: TempoCoordinatorCharm = mgr.charm
# extra receivers should only include default otlp_http
assert charm.enabled_receivers == set(["otlp_http", "zipkin"])

# run action
action_out = context.run_action("list-receivers", state)
assert action_out.results == {
"otlp-http": f"http://{socket.getfqdn()}:4318",
"zipkin": f"http://{socket.getfqdn()}:9411",
"otlp-grpc": f"http://{socket.getfqdn()}:4317",
}
1 change: 0 additions & 1 deletion tests/scenario/test_tempo_clustered.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def test_certs_ready(context, state_with_certs):

def test_cluster_relation(context, state_with_certs, all_worker):
clustered_state = state_with_certs.replace(relations=state_with_certs.relations + [all_worker])

state_out = context.run(all_worker.joined_event, clustered_state)
cluster_out = state_out.get_relations(all_worker.endpoint)[0]
local_app_data = TempoClusterProviderAppData.load(cluster_out.local_app_data)
Expand Down

0 comments on commit ad2da3a

Please sign in to comment.