Skip to content

Commit

Permalink
tests: add basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
daywalker90 authored and yukibtc committed May 2, 2024
1 parent 395da3f commit 25c3c3e
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
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

0 comments on commit 25c3c3e

Please sign in to comment.