nixosTests.wiki-js: migrate to runTest (#394445)
This commit is contained in:
commit
c50d2e317a
@ -1306,7 +1306,7 @@ in {
|
|||||||
weblate = handleTest ./web-apps/weblate.nix {};
|
weblate = handleTest ./web-apps/weblate.nix {};
|
||||||
whisparr = handleTest ./whisparr.nix {};
|
whisparr = handleTest ./whisparr.nix {};
|
||||||
whoogle-search = handleTest ./whoogle-search.nix {};
|
whoogle-search = handleTest ./whoogle-search.nix {};
|
||||||
wiki-js = handleTest ./wiki-js.nix {};
|
wiki-js = runTest ./wiki-js.nix;
|
||||||
wine = handleTest ./wine.nix {};
|
wine = handleTest ./wine.nix {};
|
||||||
wireguard = handleTest ./wireguard {};
|
wireguard = handleTest ./wireguard {};
|
||||||
wg-access-server = handleTest ./wg-access-server.nix {};
|
wg-access-server = handleTest ./wg-access-server.nix {};
|
||||||
|
|||||||
@ -1,171 +1,169 @@
|
|||||||
import ./make-test-python.nix (
|
{ pkgs, ... }:
|
||||||
{ pkgs, lib, ... }:
|
{
|
||||||
{
|
name = "wiki-js";
|
||||||
name = "wiki-js";
|
meta = with pkgs.lib.maintainers; {
|
||||||
meta = with pkgs.lib.maintainers; {
|
maintainers = [ ma27 ];
|
||||||
maintainers = [ ma27 ];
|
};
|
||||||
|
|
||||||
|
nodes.machine =
|
||||||
|
{ pkgs, ... }:
|
||||||
|
{
|
||||||
|
virtualisation.memorySize = 2047;
|
||||||
|
services.wiki-js = {
|
||||||
|
enable = true;
|
||||||
|
settings.db.host = "/run/postgresql";
|
||||||
|
settings.db.user = "wiki-js";
|
||||||
|
settings.db.db = "wiki-js";
|
||||||
|
settings.logLevel = "debug";
|
||||||
|
};
|
||||||
|
services.postgresql = {
|
||||||
|
enable = true;
|
||||||
|
ensureDatabases = [ "wiki-js" ];
|
||||||
|
ensureUsers = [
|
||||||
|
{
|
||||||
|
name = "wiki-js";
|
||||||
|
ensureDBOwnership = true;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
systemd.services.wiki-js = {
|
||||||
|
requires = [ "postgresql.service" ];
|
||||||
|
after = [ "postgresql.service" ];
|
||||||
|
};
|
||||||
|
environment.systemPackages = with pkgs; [ jq ];
|
||||||
};
|
};
|
||||||
|
|
||||||
nodes.machine =
|
testScript =
|
||||||
{ pkgs, ... }:
|
let
|
||||||
{
|
payloads.finalize = pkgs.writeText "finalize.json" (
|
||||||
virtualisation.memorySize = 2047;
|
builtins.toJSON {
|
||||||
services.wiki-js = {
|
adminEmail = "webmaster@example.com";
|
||||||
enable = true;
|
adminPassword = "notapassword";
|
||||||
settings.db.host = "/run/postgresql";
|
adminPasswordConfirm = "notapassword";
|
||||||
settings.db.user = "wiki-js";
|
siteUrl = "http://localhost:3000";
|
||||||
settings.db.db = "wiki-js";
|
telemetry = false;
|
||||||
settings.logLevel = "debug";
|
}
|
||||||
};
|
);
|
||||||
services.postgresql = {
|
payloads.login = pkgs.writeText "login.json" (
|
||||||
enable = true;
|
builtins.toJSON [
|
||||||
ensureDatabases = [ "wiki-js" ];
|
{
|
||||||
ensureUsers = [
|
operationName = null;
|
||||||
{
|
extensions = { };
|
||||||
name = "wiki-js";
|
query = ''
|
||||||
ensureDBOwnership = true;
|
mutation ($username: String!, $password: String!, $strategy: String!) {
|
||||||
}
|
authentication {
|
||||||
];
|
login(username: $username, password: $password, strategy: $strategy) {
|
||||||
};
|
responseResult {
|
||||||
systemd.services.wiki-js = {
|
succeeded
|
||||||
requires = [ "postgresql.service" ];
|
errorCode
|
||||||
after = [ "postgresql.service" ];
|
slug
|
||||||
};
|
message
|
||||||
environment.systemPackages = with pkgs; [ jq ];
|
__typename
|
||||||
};
|
}
|
||||||
|
jwt
|
||||||
testScript =
|
mustChangePwd
|
||||||
let
|
mustProvideTFA
|
||||||
payloads.finalize = pkgs.writeText "finalize.json" (
|
mustSetupTFA
|
||||||
builtins.toJSON {
|
continuationToken
|
||||||
adminEmail = "webmaster@example.com";
|
redirect
|
||||||
adminPassword = "notapassword";
|
tfaQRImage
|
||||||
adminPasswordConfirm = "notapassword";
|
__typename
|
||||||
siteUrl = "http://localhost:3000";
|
}
|
||||||
telemetry = false;
|
__typename
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
variables = {
|
||||||
|
password = "notapassword";
|
||||||
|
strategy = "local";
|
||||||
|
username = "webmaster@example.com";
|
||||||
|
};
|
||||||
}
|
}
|
||||||
);
|
]
|
||||||
payloads.login = pkgs.writeText "login.json" (
|
);
|
||||||
builtins.toJSON [
|
payloads.content = pkgs.writeText "content.json" (
|
||||||
{
|
builtins.toJSON [
|
||||||
operationName = null;
|
{
|
||||||
extensions = { };
|
extensions = { };
|
||||||
query = ''
|
operationName = null;
|
||||||
mutation ($username: String!, $password: String!, $strategy: String!) {
|
query = ''
|
||||||
authentication {
|
mutation ($content: String!, $description: String!, $editor: String!, $isPrivate: Boolean!, $isPublished: Boolean!, $locale: String!, $path: String!, $publishEndDate: Date, $publishStartDate: Date, $scriptCss: String, $scriptJs: String, $tags: [String]!, $title: String!) {
|
||||||
login(username: $username, password: $password, strategy: $strategy) {
|
pages {
|
||||||
responseResult {
|
create(content: $content, description: $description, editor: $editor, isPrivate: $isPrivate, isPublished: $isPublished, locale: $locale, path: $path, publishEndDate: $publishEndDate, publishStartDate: $publishStartDate, scriptCss: $scriptCss, scriptJs: $scriptJs, tags: $tags, title: $title) {
|
||||||
succeeded
|
responseResult {
|
||||||
errorCode
|
succeeded
|
||||||
slug
|
errorCode
|
||||||
message
|
slug
|
||||||
__typename
|
message
|
||||||
}
|
__typename
|
||||||
jwt
|
}
|
||||||
mustChangePwd
|
page {
|
||||||
mustProvideTFA
|
id
|
||||||
mustSetupTFA
|
updatedAt
|
||||||
continuationToken
|
|
||||||
redirect
|
|
||||||
tfaQRImage
|
|
||||||
__typename
|
__typename
|
||||||
}
|
}
|
||||||
__typename
|
__typename
|
||||||
}
|
}
|
||||||
|
__typename
|
||||||
}
|
}
|
||||||
'';
|
}
|
||||||
variables = {
|
'';
|
||||||
password = "notapassword";
|
variables = {
|
||||||
strategy = "local";
|
content = "# Header\n\nHello world!";
|
||||||
username = "webmaster@example.com";
|
description = "";
|
||||||
};
|
editor = "markdown";
|
||||||
}
|
isPrivate = false;
|
||||||
]
|
isPublished = true;
|
||||||
);
|
locale = "en";
|
||||||
payloads.content = pkgs.writeText "content.json" (
|
path = "home";
|
||||||
builtins.toJSON [
|
publishEndDate = "";
|
||||||
{
|
publishStartDate = "";
|
||||||
extensions = { };
|
scriptCss = "";
|
||||||
operationName = null;
|
scriptJs = "";
|
||||||
query = ''
|
tags = [ ];
|
||||||
mutation ($content: String!, $description: String!, $editor: String!, $isPrivate: Boolean!, $isPublished: Boolean!, $locale: String!, $path: String!, $publishEndDate: Date, $publishStartDate: Date, $scriptCss: String, $scriptJs: String, $tags: [String]!, $title: String!) {
|
title = "Hello world";
|
||||||
pages {
|
};
|
||||||
create(content: $content, description: $description, editor: $editor, isPrivate: $isPrivate, isPublished: $isPublished, locale: $locale, path: $path, publishEndDate: $publishEndDate, publishStartDate: $publishStartDate, scriptCss: $scriptCss, scriptJs: $scriptJs, tags: $tags, title: $title) {
|
}
|
||||||
responseResult {
|
]
|
||||||
succeeded
|
);
|
||||||
errorCode
|
in
|
||||||
slug
|
''
|
||||||
message
|
machine.start()
|
||||||
__typename
|
machine.wait_for_unit("multi-user.target")
|
||||||
}
|
machine.wait_for_open_port(3000)
|
||||||
page {
|
|
||||||
id
|
|
||||||
updatedAt
|
|
||||||
__typename
|
|
||||||
}
|
|
||||||
__typename
|
|
||||||
}
|
|
||||||
__typename
|
|
||||||
}
|
|
||||||
}
|
|
||||||
'';
|
|
||||||
variables = {
|
|
||||||
content = "# Header\n\nHello world!";
|
|
||||||
description = "";
|
|
||||||
editor = "markdown";
|
|
||||||
isPrivate = false;
|
|
||||||
isPublished = true;
|
|
||||||
locale = "en";
|
|
||||||
path = "home";
|
|
||||||
publishEndDate = "";
|
|
||||||
publishStartDate = "";
|
|
||||||
scriptCss = "";
|
|
||||||
scriptJs = "";
|
|
||||||
tags = [ ];
|
|
||||||
title = "Hello world";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
]
|
|
||||||
);
|
|
||||||
in
|
|
||||||
''
|
|
||||||
machine.start()
|
|
||||||
machine.wait_for_unit("multi-user.target")
|
|
||||||
machine.wait_for_open_port(3000)
|
|
||||||
|
|
||||||
machine.succeed("curl -sSf localhost:3000")
|
machine.succeed("curl -sSf localhost:3000")
|
||||||
|
|
||||||
with subtest("Setup"):
|
with subtest("Setup"):
|
||||||
result = machine.succeed(
|
result = machine.succeed(
|
||||||
"curl -sSf localhost:3000/finalize -X POST -d "
|
"curl -sSf localhost:3000/finalize -X POST -d "
|
||||||
+ "@${payloads.finalize} -H 'Content-Type: application/json' "
|
+ "@${payloads.finalize} -H 'Content-Type: application/json' "
|
||||||
+ "| jq .ok | xargs echo"
|
+ "| jq .ok | xargs echo"
|
||||||
)
|
)
|
||||||
assert result.strip() == "true", f"Expected true, got {result}"
|
assert result.strip() == "true", f"Expected true, got {result}"
|
||||||
|
|
||||||
# During the setup the service gets restarted, so we use this
|
# During the setup the service gets restarted, so we use this
|
||||||
# to check if the setup is done.
|
# to check if the setup is done.
|
||||||
machine.wait_until_fails("curl -sSf localhost:3000")
|
machine.wait_until_fails("curl -sSf localhost:3000")
|
||||||
machine.wait_until_succeeds("curl -sSf localhost:3000")
|
machine.wait_until_succeeds("curl -sSf localhost:3000")
|
||||||
|
|
||||||
with subtest("Base functionality"):
|
with subtest("Base functionality"):
|
||||||
auth = machine.succeed(
|
auth = machine.succeed(
|
||||||
"curl -sSf localhost:3000/graphql -X POST "
|
"curl -sSf localhost:3000/graphql -X POST "
|
||||||
+ "-d @${payloads.login} -H 'Content-Type: application/json' "
|
+ "-d @${payloads.login} -H 'Content-Type: application/json' "
|
||||||
+ "| jq '.[0].data.authentication.login.jwt' | xargs echo"
|
+ "| jq '.[0].data.authentication.login.jwt' | xargs echo"
|
||||||
).strip()
|
).strip()
|
||||||
|
|
||||||
assert auth
|
assert auth
|
||||||
|
|
||||||
create = machine.succeed(
|
create = machine.succeed(
|
||||||
"curl -sSf localhost:3000/graphql -X POST "
|
"curl -sSf localhost:3000/graphql -X POST "
|
||||||
+ "-d @${payloads.content} -H 'Content-Type: application/json' "
|
+ "-d @${payloads.content} -H 'Content-Type: application/json' "
|
||||||
+ f"-H 'Authorization: Bearer {auth}' "
|
+ f"-H 'Authorization: Bearer {auth}' "
|
||||||
+ "| jq '.[0].data.pages.create.responseResult.succeeded'|xargs echo"
|
+ "| jq '.[0].data.pages.create.responseResult.succeeded'|xargs echo"
|
||||||
)
|
)
|
||||||
assert create.strip() == "true", f"Expected true, got {create}"
|
assert create.strip() == "true", f"Expected true, got {create}"
|
||||||
|
|
||||||
machine.shutdown()
|
machine.shutdown()
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user