Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: add basic test #11

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -x
script_dir=$(dirname -- "$(readlink -f -- "$0")")
cargo_toml_path="$script_dir/../Cargo.toml"

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
cargo build --manifest-path="$cargo_toml_path"
16 changes: 16 additions & 0 deletions tests/test_cln_ntfy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/python

from pyln.testing.fixtures import * # noqa: F403
from util import get_plugin # noqa: F401


def test_basic(node_factory, get_plugin): # noqa: F811
node = node_factory.get_node(
options={
"plugin": get_plugin,
"ntfy-url": "https://ntfy.sh",
"ntfy-topic": "cln-alerts",
"ntfy-username": "username",
"ntfy-password": "password",
}
)
42 changes: 42 additions & 0 deletions tests/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import logging
import os
import random
import string
from pathlib import Path

import pytest

RUST_PROFILE = os.environ.get("RUST_PROFILE", "debug")
COMPILED_PATH = Path.cwd() / "target" / RUST_PROFILE / "cln-ntfy"
DOWNLOAD_PATH = Path.cwd() / "tests" / "cln-ntfy"


@pytest.fixture
def get_plugin(directory):
if COMPILED_PATH.is_file():
return COMPILED_PATH
elif DOWNLOAD_PATH.is_file():
return DOWNLOAD_PATH
else:
raise ValueError("No files were found.")


def generate_random_label():
label_length = 8
random_label = "".join(
random.choice(string.ascii_letters) for _ in range(label_length)
)
return random_label


def generate_random_number():
return random.randint(1, 20_000_000_000_000_00_000)


def pay_with_thread(rpc, bolt11):
LOGGER = logging.getLogger(__name__)
try:
rpc.dev_pay(bolt11, dev_use_shadow=False)
except Exception as e:
LOGGER.debug(f"Error paying payment hash:{e}")
pass
Loading