mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-28 00:22:13 +00:00
elasticmq-server-bin: add passthru.tests.elasticmqTest
simply starts an elasticmq server with a queue "foobar", attempts to put a message to it from python then checks it arrives
This commit is contained in:
parent
3c0cf469a1
commit
9c773516d7
|
@ -1,34 +1,40 @@
|
|||
{ lib, stdenv, fetchurl, jdk, jre, makeWrapper }:
|
||||
{ lib, stdenv, fetchurl, jdk, jre, makeWrapper, runCommand, python3Packages, writeText }:
|
||||
|
||||
stdenv.mkDerivation rec {
|
||||
pname = "elasticmq-server";
|
||||
version = "0.15.7";
|
||||
let
|
||||
elasticmq-server = stdenv.mkDerivation rec {
|
||||
pname = "elasticmq-server";
|
||||
version = "0.15.7";
|
||||
|
||||
src = fetchurl {
|
||||
url = "https://s3-eu-west-1.amazonaws.com/softwaremill-public/${pname}-${version}.jar";
|
||||
sha256 = "01jmb6rwh570f2y30b2if5fhcbpdnb2vkxylp9xa09c0x7a2vv4q";
|
||||
src = fetchurl {
|
||||
url = "https://s3-eu-west-1.amazonaws.com/softwaremill-public/${pname}-${version}.jar";
|
||||
sha256 = "01jmb6rwh570f2y30b2if5fhcbpdnb2vkxylp9xa09c0x7a2vv4q";
|
||||
};
|
||||
|
||||
# don't do anything?
|
||||
unpackPhase = "${jdk}/bin/jar xf $src favicon.png";
|
||||
|
||||
nativeBuildInputs = [ makeWrapper ];
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin $out/share/elasticmq-server
|
||||
|
||||
cp $src $out/share/elasticmq-server/elasticmq-server.jar
|
||||
|
||||
# TODO: how to add extraArgs? current workaround is to use JAVA_TOOL_OPTIONS environment to specify properties
|
||||
makeWrapper ${jre}/bin/java $out/bin/elasticmq-server \
|
||||
--add-flags "-jar $out/share/elasticmq-server/elasticmq-server.jar"
|
||||
'';
|
||||
|
||||
meta = with lib; {
|
||||
homepage = "https://github.com/softwaremill/elasticmq";
|
||||
description = "Message queueing system with Java, Scala and Amazon SQS-compatible interfaces";
|
||||
license = licenses.asl20;
|
||||
platforms = platforms.unix;
|
||||
maintainers = with maintainers; [ peterromfeldhk ];
|
||||
};
|
||||
};
|
||||
|
||||
# don't do anything?
|
||||
unpackPhase = "${jdk}/bin/jar xf $src favicon.png";
|
||||
|
||||
nativeBuildInputs = [ makeWrapper ];
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin $out/share/elasticmq-server
|
||||
|
||||
cp $src $out/share/elasticmq-server/elasticmq-server.jar
|
||||
|
||||
# TODO: how to add extraArgs? current workaround is to use JAVA_TOOL_OPTIONS environment to specify properties
|
||||
makeWrapper ${jre}/bin/java $out/bin/elasticmq-server \
|
||||
--add-flags "-jar $out/share/elasticmq-server/elasticmq-server.jar"
|
||||
'';
|
||||
|
||||
meta = with lib; {
|
||||
homepage = "https://github.com/softwaremill/elasticmq";
|
||||
description = "Message queueing system with Java, Scala and Amazon SQS-compatible interfaces";
|
||||
license = licenses.asl20;
|
||||
platforms = platforms.unix;
|
||||
maintainers = with maintainers; [ peterromfeldhk ];
|
||||
in elasticmq-server.overrideAttrs (_: {
|
||||
passthru.tests.elasticmqTest = import ./elasticmq-test.nix {
|
||||
inherit elasticmq-server runCommand python3Packages writeText;
|
||||
};
|
||||
}
|
||||
})
|
||||
|
|
47
pkgs/servers/elasticmq-server-bin/elasticmq-test.nix
Normal file
47
pkgs/servers/elasticmq-server-bin/elasticmq-test.nix
Normal file
|
@ -0,0 +1,47 @@
|
|||
{ elasticmq-server, python3Packages, runCommand, writeText}:
|
||||
|
||||
runCommand "${elasticmq-server.name}-tests" (let
|
||||
commonPy = ''
|
||||
import boto3
|
||||
client = boto3.resource(
|
||||
"sqs",
|
||||
endpoint_url="http://localhost:9324",
|
||||
region_name="elasticmq",
|
||||
aws_secret_access_key="x",
|
||||
aws_access_key_id="x",
|
||||
use_ssl=False,
|
||||
)
|
||||
queue = client.get_queue_by_name(QueueName="foobar")
|
||||
'';
|
||||
in {
|
||||
buildInputs = with python3Packages; [ python boto3 ];
|
||||
emqConfig = writeText "emq-test.conf" ''
|
||||
generate-node-address = true
|
||||
|
||||
queues {
|
||||
foobar {}
|
||||
}
|
||||
'';
|
||||
putMessagePy = writeText "put_message.py" ''
|
||||
${commonPy}
|
||||
queue.send_message(MessageBody="bazqux")
|
||||
'';
|
||||
checkMessagePy = writeText "check_message.py" ''
|
||||
${commonPy}
|
||||
messages = queue.receive_messages()
|
||||
print(f"Received {messages!r}")
|
||||
assert len(messages) == 1
|
||||
assert messages[0].body == "bazqux"
|
||||
'';
|
||||
}) ''
|
||||
JAVA_TOOL_OPTIONS="-Dconfig.file=$emqConfig" ${elasticmq-server}/bin/elasticmq-server &
|
||||
SERVER_PID=$!
|
||||
sleep 10
|
||||
|
||||
python $putMessagePy
|
||||
python $checkMessagePy
|
||||
touch $out
|
||||
|
||||
# needed on darwin
|
||||
kill $SERVER_PID
|
||||
''
|
Loading…
Reference in a new issue