summaryrefslogtreecommitdiffstats
path: root/test/t/salsa.t
blob: d80978a00fb3cb180a95ad425775305731fd5c0b (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env perl

my $skip;
use File::Temp 'tempdir';
use Test::More;
use strict;

BEGIN {
    eval "use Test::Output;use GitLab::API::v4;";
    $skip = $@ ? 1 : 0;
}

my $pwd = `pwd`;
chomp $pwd;
my ($api, $gitdir);

sub mkDebianDir {
    my $tmpdir = tempdir(CLEANUP => 1);
    chdir $tmpdir;
    $ENV{"GIT_CONFIG_NOGLOBAL"} = 1;
    $ENV{"HOME"} = "";
    system "git init";
    system "git config user.name 'Joe Developer'";
    system 'git config user.email "jd@debian.org"';
    mkdir 'debian';
    open F, ">debian/changelog";
    print F <<EOF;
foobar (0-1) unstable; urgency=low

  * Initial release

 -- Joe Developer <jd\@debian.org>  Mon, 02 Nov 2013 22:21:31 -0100
EOF
    close F;
    open F, ">README.md";
    print F <<EOF;
# Salsa test
EOF
    system "git add *";
    system "git commit -a -m 'Salsa test'";
    system "git checkout -q -b dev";
    chdir $pwd;
    return $tmpdir;
}

sub run {
    my ($result, $out, @list) = @_;
    @ARGV = ('--no-cache', @list);
    my ($res, $salsa);
    combined_like(
        sub {
            $salsa = Devscripts::Salsa->new({ api => $api });
            $salsa->config->git_server_url($gitdir . '/');
            $res = $salsa->run;
        },
        $out,
        "command: " . join(' ', @list));
    ok($res =~ /^$result$/i, " result is $result");
}

sub run_debug {
    my ($result, $out, @list) = @_;
    @ARGV = ('--no-cache', @list);
    my ($res, $salsa);
    $salsa = Devscripts::Salsa->new({ api => $api });
    $salsa->config->git_server_url($gitdir . '/');
    $res = $salsa->run;
}

SKIP: {
    skip "Missing dependencies" if ($skip);
    require './t/salsa.pm';
    $gitdir = tempdir(CLEANUP => 1);
    sleep 1;
    mkdir "$gitdir/me" or die "$gitdir/me: $!";

    $api = api($gitdir);

    use_ok 'Devscripts::Salsa';
    $Devscripts::Output::die_on_error = 0;
    @Devscripts::Config::config_files = ('t/salsa.conf');

    # Search methods
    run(0, qr/Id\s*:\s*11\nUsername\s*:\s*me/s, 'whoami');
    run(0, qr/Id\s*:\s*2099\nName/s,            'search_group', 'js-team');
    run(0, qr/Id\s*:\s*2099\nName/s,            'search_group', 2099);
    run(0, qr/Id.*\nUsername\s*: me/s,          'search_user', 'me');
    run(0, qr/Id.*\nUsername\s*: me/s,          'search_user', 'm');
    run(0, qr/Id.*\nUsername\s*: me/s,          'search_user', 11);

    # Project methods
    my $repo = mkDebianDir;
    run(0, qr/Project .*created/s, '-C', $repo, '--verbose', 'push_repo', '.');
    chdir $pwd;
    $repo = tempdir(CLEANUP => 1);
    run(0, qr/KGB hook added.*Tagpending hook added/s,
        'update_repo', '--kgb', '--irc=debian', '--tagpending', 'foobar');
    run(0, qr/foobar\s*:\s*OK/s,
        'update_safe', '--kgb', '--irc=debian', '--tagpending', 'foobar');
    run(0, qr{Full path\s*:\s*me/foobar}, 'search', 'foobar');
    run(0, qr{Configuring foobar},
        'rename_branch', 'foobar', '--source-branch=dev',
        '--dest-branch=dev2');
}

done_testing;

1;