Skip to content

Commit

Permalink
fix(loki-tests): set the container & log message to be random.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aazme committed Nov 4, 2024
1 parent 2d6516a commit b02bd78
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
9 changes: 7 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# tests/conftest.py
import pytest
import random
import string

def generate_random_string(length=8):
return ''.join(random.choices(string.ascii_letters + string.digits, k=length))

@pytest.fixture
def setup_alpine_container(host):
"""Sets up a test Alpine container and yields its name and log message."""
container_name = "test-log-container"
log_message = "Test log message for Loki"
container_name = generate_random_string()
log_message = generate_random_string()

# Run an alpine container on the target host and generate a log message
host.run(f"docker run --name {container_name} alpine sh -c 'echo \"{log_message}\"; sleep 5'")
Expand Down
11 changes: 3 additions & 8 deletions tests/test_loki_integration.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
# tests/test_loki_integration.py
import json
import time
import testinfra
import random
import string
from pytest import fail

def generate_random_string(length=8):
return ''.join(random.choices(string.ascii_letters + string.digits, k=length))

def test_alpine_log_delivery_to_loki(host, setup_alpine_container):
"""Test that logs from a test Alpine container are delivered to Loki."""
# Generate random container name and log message
container_name = generate_random_string()
log_message = generate_random_string()
# Extract container details from the fixture
container_name, log_message = setup_alpine_container

loki_host = "localhost" # Adjust if Loki is on a different host
loki_port = "3100"
Expand Down

0 comments on commit b02bd78

Please sign in to comment.