summaryrefslogtreecommitdiffstatshomepage
path: root/test/integration/lib/example.sh
blob: db62f6ed3a8f504fa94749e5c7a9371765bf570d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright (c) 2026 Egor Tensin <egor@tensin.name>
# This file is part of the "cgitize" project.
# For details, see https://github.com/egor-tensin/cgitize
# Distributed under the MIT License.

_sed_config() {
    if [ "$#" -ne 1 ]; then
        log "usage: ${FUNCNAME[0]} EXPR"
        return 1
    fi

    sed -i -E -e "$1" -- "$test_config_path"
}

_test_example_setup_config() {
    test_config_path="$test_root_dir/cgitize.toml"
    log "Config path: $test_config_path"

    cp -- "$tests_dir/../../examples/cgitize.toml" "$test_config_path"

    _sed_config 's@^output_dir = .*$@output_dir = "'"$test_output_dir"'"@'
    test_example_clone_ssh
    test_example_private_skip
}

_check_var() {
    local var
    for var; do
        if [ -z "${!var:+x}" ]; then
            fail "Variable not set: $var"
            return 1
        fi
    done
}

test_example_setup() {
    _check_var \
        CGITIZE_GITHUB_USERNAME \
        CGITIZE_GITHUB_TOKEN \
        CGITIZE_BITBUCKET_EMAIL \
        CGITIZE_BITBUCKET_TOKEN \
        CGITIZE_GITLAB_USERNAME \
        CGITIZE_GITLAB_TOKEN

    test_output_dir="$test_root_dir/output"
    log "Output directory: $test_output_dir"

    _test_example_setup_config
}

test_example_clone_ssh() {
    _sed_config 's/^clone_via_ssh = (true|false)$/clone_via_ssh = true/'
}

test_example_clone_https() {
    _sed_config 's/^clone_via_ssh = (true|false)$/clone_via_ssh = false/'
}

test_example_private_include() {
    _sed_config 's/^private = (true|false)$/private = true/'
}

test_example_private_skip() {
    _sed_config 's/^private = (true|false)$/private = false/'
}