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
|
let
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
lib = nixpkgs.lib;
|
||||||
|
|
||||||
# Generate a user-friendly version number. TODO
|
# Generate a user-friendly version number. TODO
|
||||||
version = (builtins.substring 0 8 self.lastModifiedDate) + self.shortRev;
|
version = (builtins.substring 0 8 self.lastModifiedDate) + self.shortRev;
|
||||||
in
|
|
||||||
{
|
makeTestProgram = { name, script, env-vars }:
|
||||||
packages.${system}.query-all-services =
|
pkgs.runCommandLocal name
|
||||||
pkgs.runCommandLocal "query-all-services"
|
|
||||||
{
|
{
|
||||||
nativeBuildInputs = [ pkgs.makeWrapper ];
|
nativeBuildInputs = [ pkgs.makeWrapper ];
|
||||||
} ''
|
} ''
|
||||||
ls -l
|
ls -l
|
||||||
install -m755 ${./query-all-services.sh} \
|
install -m755 ${script} \
|
||||||
-D $out/bin/query-all-services
|
-D $out/bin/${name}
|
||||||
patchShebangs $out/bin/query-all-services
|
patchShebangs $out/bin/${name}
|
||||||
wrapProgram $out/bin/query-all-services \
|
wrapProgram $out/bin/${name} \
|
||||||
|
${lib.strings.concatMapStringsSep "\n"
|
||||||
|
({name, value}: "--prefix ${name} : ${value}") env-vars} \
|
||||||
--prefix PATH : ${with pkgs; lib.makeBinPath [
|
--prefix PATH : ${with pkgs; lib.makeBinPath [
|
||||||
curl
|
curl
|
||||||
diffutils
|
diffutils
|
||||||
|
@ -32,44 +34,27 @@
|
||||||
gnutar
|
gnutar
|
||||||
]}
|
]}
|
||||||
'';
|
'';
|
||||||
# packages.${system}.query-all-services =
|
in
|
||||||
# pkgs.writeShellApplication {
|
{
|
||||||
# name = "query-all-services.sh";
|
packages.${system} = lib.attrsets.listToAttrs (map
|
||||||
# checkPhase = true;
|
(a@{ name, ... }: lib.attrsets.nameValuePair name (makeTestProgram a))
|
||||||
# text =./query-all-services.sh;
|
[
|
||||||
# runtimeInputs = with pkgs; [
|
{
|
||||||
# curl
|
name = "query-minimum-services";
|
||||||
# diffutils
|
script = ./query-services-state.sh;
|
||||||
# gzip
|
env-vars = [{
|
||||||
# jd-diff-patch
|
name = "EXPECTED_RESPONSE_FILE";
|
||||||
# jq
|
value = ./minimal-services-expected-response.json;
|
||||||
# openssh
|
}];
|
||||||
# gnutar
|
}
|
||||||
# ];
|
{
|
||||||
# };
|
name = "query-all-services";
|
||||||
# packages.${system}.query-all-services =
|
script = ./query-services-state.sh;
|
||||||
# pkgs.resholve.writeScriptBin "query-all-services.sh" {
|
env-vars = [{
|
||||||
# inputs = with pkgs; [
|
name = "EXPECTED_RESPONSE_FILE";
|
||||||
# curl
|
value = ./all-services-expected-response.json;
|
||||||
# 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
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -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