query-services-state for any expected response
parent
cd6d21b5f3
commit
e6cd6dc7a9
|
@ -0,0 +1,43 @@
|
|||
{
|
||||
"data": {
|
||||
"services": {
|
||||
"allServices": [
|
||||
{
|
||||
"id": "bitwarden",
|
||||
"isEnabled": true,
|
||||
"status": "ACTIVE"
|
||||
},
|
||||
{
|
||||
"id": "gitea",
|
||||
"isEnabled": true,
|
||||
"status": "ACTIVE"
|
||||
},
|
||||
{
|
||||
"id": "email",
|
||||
"isEnabled": true,
|
||||
"status": "ACTIVE"
|
||||
},
|
||||
{
|
||||
"id": "nextcloud",
|
||||
"isEnabled": true,
|
||||
"status": "ACTIVE"
|
||||
},
|
||||
{
|
||||
"id": "pleroma",
|
||||
"isEnabled": true,
|
||||
"status": "ACTIVE"
|
||||
},
|
||||
{
|
||||
"id": "ocserv",
|
||||
"isEnabled": true,
|
||||
"status": "ACTIVE"
|
||||
},
|
||||
{
|
||||
"id": "jitsi",
|
||||
"isEnabled": false,
|
||||
"status": "ACTIVE"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
79
flake.nix
79
flake.nix
|
@ -7,21 +7,23 @@
|
|||
let
|
||||
system = "x86_64-linux";
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
lib = nixpkgs.lib;
|
||||
|
||||
# Generate a user-friendly version number. TODO
|
||||
version = (builtins.substring 0 8 self.lastModifiedDate) + self.shortRev;
|
||||
in
|
||||
{
|
||||
packages.${system}.query-all-services =
|
||||
pkgs.runCommandLocal "query-all-services"
|
||||
|
||||
makeTestProgram = { name, script, env-vars }:
|
||||
pkgs.runCommandLocal name
|
||||
{
|
||||
nativeBuildInputs = [ pkgs.makeWrapper ];
|
||||
} ''
|
||||
ls -l
|
||||
install -m755 ${./query-all-services.sh} \
|
||||
-D $out/bin/query-all-services
|
||||
patchShebangs $out/bin/query-all-services
|
||||
wrapProgram $out/bin/query-all-services \
|
||||
install -m755 ${script} \
|
||||
-D $out/bin/${name}
|
||||
patchShebangs $out/bin/${name}
|
||||
wrapProgram $out/bin/${name} \
|
||||
${lib.strings.concatMapStringsSep "\n"
|
||||
({name, value}: "--prefix ${name} : ${value}") env-vars} \
|
||||
--prefix PATH : ${with pkgs; lib.makeBinPath [
|
||||
curl
|
||||
diffutils
|
||||
|
@ -32,44 +34,27 @@
|
|||
gnutar
|
||||
]}
|
||||
'';
|
||||
# packages.${system}.query-all-services =
|
||||
# pkgs.writeShellApplication {
|
||||
# name = "query-all-services.sh";
|
||||
# checkPhase = true;
|
||||
# text =./query-all-services.sh;
|
||||
# runtimeInputs = with pkgs; [
|
||||
# curl
|
||||
# diffutils
|
||||
# gzip
|
||||
# jd-diff-patch
|
||||
# jq
|
||||
# openssh
|
||||
# gnutar
|
||||
# ];
|
||||
# };
|
||||
# packages.${system}.query-all-services =
|
||||
# pkgs.resholve.writeScriptBin "query-all-services.sh" {
|
||||
# inputs = with pkgs; [
|
||||
# curl
|
||||
# diffutils
|
||||
# gzip
|
||||
# jd-diff-patch
|
||||
# jq
|
||||
# openssh
|
||||
# gnutar
|
||||
# ];
|
||||
# interpreter = "${pkgs.bash}/bin/bash";
|
||||
# } ./query-all-services.sh;
|
||||
devShells.${system}.default = pkgs.mkShell {
|
||||
packages = with pkgs; [
|
||||
curl
|
||||
diffutils
|
||||
gzip
|
||||
jd-diff-patch
|
||||
jq
|
||||
openssh
|
||||
gnutar
|
||||
];
|
||||
};
|
||||
in
|
||||
{
|
||||
packages.${system} = lib.attrsets.listToAttrs (map
|
||||
(a@{ name, ... }: lib.attrsets.nameValuePair name (makeTestProgram a))
|
||||
[
|
||||
{
|
||||
name = "query-minimum-services";
|
||||
script = ./query-services-state.sh;
|
||||
env-vars = [{
|
||||
name = "EXPECTED_RESPONSE_FILE";
|
||||
value = ./minimal-services-expected-response.json;
|
||||
}];
|
||||
}
|
||||
{
|
||||
name = "query-all-services";
|
||||
script = ./query-services-state.sh;
|
||||
env-vars = [{
|
||||
name = "EXPECTED_RESPONSE_FILE";
|
||||
value = ./all-services-expected-response.json;
|
||||
}];
|
||||
}
|
||||
]);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
{
|
||||
"data": {
|
||||
"services": {
|
||||
"allServices": [
|
||||
{
|
||||
"id": "bitwarden",
|
||||
"isEnabled": false,
|
||||
"status": "OFF"
|
||||
},
|
||||
{
|
||||
"id": "gitea",
|
||||
"isEnabled": false,
|
||||
"status": "OFF"
|
||||
},
|
||||
{
|
||||
"id": "email",
|
||||
"isEnabled": true,
|
||||
"status": "ACTIVE"
|
||||
},
|
||||
{
|
||||
"id": "nextcloud",
|
||||
"isEnabled": true,
|
||||
"status": "ACTIVE"
|
||||
},
|
||||
{
|
||||
"id": "pleroma",
|
||||
"isEnabled": false,
|
||||
"status": "OFF"
|
||||
},
|
||||
{
|
||||
"id": "ocserv",
|
||||
"isEnabled": false,
|
||||
"status": "OFF"
|
||||
},
|
||||
{
|
||||
"id": "jitsi",
|
||||
"isEnabled": false,
|
||||
"status": "OFF"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
#! /usr/bin/env bash
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
shopt -s inherit_errexit
|
||||
|
||||
: "${DOMAIN:?specify domain name}"
|
||||
readonly AUTH_HEADER="Authorization: Bearer ${API_TOKEN:?not set error}"
|
||||
readonly QUERY='query AllServices {
|
||||
services {
|
||||
allServices {
|
||||
id
|
||||
isEnabled
|
||||
status
|
||||
}
|
||||
}
|
||||
}'
|
||||
|
||||
# shellcheck disable=SC2116
|
||||
# shellcheck disable=SC2086
|
||||
REQUEST=$(cat << EOF
|
||||
{
|
||||
"query": "$(echo $QUERY)",
|
||||
"variables": null,
|
||||
"operationName": "AllServices"
|
||||
}
|
||||
EOF
|
||||
)
|
||||
readonly REQUEST
|
||||
|
||||
# TODO fix jitsi "isEnabled" expected response value
|
||||
EXPECTED_RESPONSE=$(cat << EOF
|
||||
{
|
||||
"data": {
|
||||
"services": {
|
||||
"allServices": [
|
||||
{
|
||||
"id": "bitwarden",
|
||||
"isEnabled": true,
|
||||
"status": "ACTIVE"
|
||||
},
|
||||
{
|
||||
"id": "gitea",
|
||||
"isEnabled": true,
|
||||
"status": "ACTIVE"
|
||||
},
|
||||
{
|
||||
"id": "email",
|
||||
"isEnabled": true,
|
||||
"status": "ACTIVE"
|
||||
},
|
||||
{
|
||||
"id": "nextcloud",
|
||||
"isEnabled": true,
|
||||
"status": "ACTIVE"
|
||||
},
|
||||
{
|
||||
"id": "pleroma",
|
||||
"isEnabled": true,
|
||||
"status": "ACTIVE"
|
||||
},
|
||||
{
|
||||
"id": "ocserv",
|
||||
"isEnabled": true,
|
||||
"status": "ACTIVE"
|
||||
},
|
||||
{
|
||||
"id": "jitsi",
|
||||
"isEnabled": false,
|
||||
"status": "ACTIVE"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
)
|
||||
readonly EXPECTED_RESPONSE
|
||||
|
||||
received_response="$(curl --show-error -s "https://api.$DOMAIN/graphql" \
|
||||
--compressed \
|
||||
-H 'Content-Type: application/json' \
|
||||
--data-raw "$REQUEST" -k -H "$AUTH_HEADER" | jq --sort-keys)"
|
||||
|
||||
jq <<<"$received_response"
|
||||
|
||||
if diff -w -u --color <(printf "%s\n" "$EXPECTED_RESPONSE") <(printf "%s\n" "$received_response") 2>/dev/null
|
||||
then
|
||||
echo -e "\e[1;32mOK"
|
||||
else
|
||||
echo -e "\e[1;31mFAIL: response does not match!"
|
||||
jd -color <(printf "%s" "$EXPECTED_RESPONSE") <(printf "%s" "$received_response")
|
||||
exit 1
|
||||
fi
|
|
@ -0,0 +1,47 @@
|
|||
#! /usr/bin/env bash
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
shopt -s inherit_errexit
|
||||
|
||||
: "${DOMAIN:?specify domain name}"
|
||||
readonly AUTH_HEADER="Authorization: Bearer ${API_TOKEN:?not set error}"
|
||||
readonly QUERY='query AllServices {
|
||||
services {
|
||||
allServices {
|
||||
id
|
||||
isEnabled
|
||||
status
|
||||
}
|
||||
}
|
||||
}'
|
||||
: "${EXPECTED_RESPONSE_FILE:?not set error}"
|
||||
|
||||
# shellcheck disable=SC2116
|
||||
# shellcheck disable=SC2086
|
||||
REQUEST=$(cat << EOF
|
||||
{
|
||||
"query": "$(echo $QUERY)",
|
||||
"variables": null,
|
||||
"operationName": "AllServices"
|
||||
}
|
||||
EOF
|
||||
)
|
||||
readonly REQUEST
|
||||
|
||||
received_response="$(curl --show-error -s "https://api.$DOMAIN/graphql" \
|
||||
--compressed \
|
||||
-H 'Content-Type: application/json' \
|
||||
--data-raw "$REQUEST" -k -H "$AUTH_HEADER" | jq --sort-keys)"
|
||||
|
||||
jq <<<"$received_response"
|
||||
|
||||
if diff -w -u --color "$EXPECTED_RESPONSE_FILE" <(printf "%s\n" "$received_response") 2>/dev/null
|
||||
then
|
||||
echo -e "\e[1;32mOK"
|
||||
else
|
||||
echo -e "\e[1;31mFAIL: response does not match!"
|
||||
jd -color "$EXPECTED_RESPONSE_FILE" <(printf "%s" "$received_response")
|
||||
exit 1
|
||||
fi
|
Loading…
Reference in New Issue