mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-26 07:46:21 +02:00
tests/nixos/fetch-git: Testsupport for private repos
This commit is contained in:
parent
0bd9e10aea
commit
ed975e953c
1 changed files with 30 additions and 6 deletions
|
@ -1,12 +1,32 @@
|
||||||
{ lib, ... }:
|
{ lib, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib) mkOption types;
|
inherit (lib)
|
||||||
|
mkIf
|
||||||
|
mkOption
|
||||||
|
types
|
||||||
|
;
|
||||||
|
|
||||||
|
boolPyLiteral = b: if b then "True" else "False";
|
||||||
|
|
||||||
testCaseExtension = { config, ... }: {
|
testCaseExtension = { config, ... }: {
|
||||||
|
options = {
|
||||||
|
repo.enable = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = true;
|
||||||
|
description = "Whether to provide a repo variable - automatic repo creation.";
|
||||||
|
};
|
||||||
|
repo.private = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = "Whether the repo should be private.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
config = mkIf config.repo.enable {
|
||||||
setupScript = ''
|
setupScript = ''
|
||||||
repo = Repo("${config.name}")
|
repo = Repo("${config.name}", private=${boolPyLiteral config.repo.private})
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
|
@ -16,16 +36,20 @@ in
|
||||||
};
|
};
|
||||||
config = {
|
config = {
|
||||||
setupScript = ''
|
setupScript = ''
|
||||||
|
def boolToJSON(b):
|
||||||
|
return "true" if b else "false"
|
||||||
|
|
||||||
class Repo:
|
class Repo:
|
||||||
"""
|
"""
|
||||||
A class to create a git repository on the gitea server and locally.
|
A class to create a git repository on the gitea server and locally.
|
||||||
"""
|
"""
|
||||||
def __init__(self, name):
|
def __init__(self, name, private=False):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.path = "/tmp/repos/" + name
|
self.path = "/tmp/repos/" + name
|
||||||
self.remote = "http://gitea:3000/test/" + name
|
self.remote = "http://gitea:3000/test/" + name
|
||||||
self.remote_ssh = "ssh://gitea/root/" + name
|
self.remote_ssh = "ssh://gitea/root/" + name
|
||||||
self.git = f"git -C {self.path}"
|
self.git = f"git -C {self.path}"
|
||||||
|
self.private = private
|
||||||
self.create()
|
self.create()
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
|
@ -37,7 +61,7 @@ in
|
||||||
gitea.succeed(f"""
|
gitea.succeed(f"""
|
||||||
curl --fail -X POST http://{gitea_admin}:{gitea_admin_password}@gitea:3000/api/v1/user/repos \
|
curl --fail -X POST http://{gitea_admin}:{gitea_admin_password}@gitea:3000/api/v1/user/repos \
|
||||||
-H 'Accept: application/json' -H 'Content-Type: application/json' \
|
-H 'Accept: application/json' -H 'Content-Type: application/json' \
|
||||||
-d {shlex.quote( f'{{"name":"{self.name}", "default_branch": "main"}}' )}
|
-d {shlex.quote( f'{{"name":"{self.name}", "default_branch": "main", "private": {boolToJSON(self.private)}}}' )}
|
||||||
""")
|
""")
|
||||||
# setup git remotes on client
|
# setup git remotes on client
|
||||||
client.succeed(f"""
|
client.succeed(f"""
|
||||||
|
|
Loading…
Reference in a new issue