forked from sartak/app-nopaste
-
Notifications
You must be signed in to change notification settings - Fork 12
/
004-03-gist.t
66 lines (53 loc) · 1.63 KB
/
004-03-gist.t
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
use strict;
use warnings;
use Test::More 0.88;
use Test::Deep;
use Test::Fatal;
use Path::Tiny;
use App::Nopaste::Service::Gist;
# clear these first to avoid interfering with tests -- and be sure we don't
# accidentally user's credentials into test results!
local $ENV{GITHUB_USER};
local $ENV{GITHUB_PASSWORD};
local $ENV{GITHUB_OAUTH_TOKEN};
ok(App::Nopaste::Service::Gist->available);
ok(!App::Nopaste::Service::Gist->forbid_in_default);
{
local $ENV{GITHUB_OAUTH_TOKEN} = 'foo';
cmp_deeply(
[ App::Nopaste::Service::Gist->_get_auth() ],
[ oauth_token => 'foo' ],
'got OAuth token as credentials',
);
}
{
local $ENV{GITHUB_USER} = 'perl';
local $ENV{GITHUB_PASSWORD} = 'user';
cmp_deeply(
[ App::Nopaste::Service::Gist->_get_auth() ],
[ username => 'perl', password => 'user' ],
'got plaintext user, password as credentials',
);
}
my $has_config_file = -f path('~', '.github');
SKIP:
{
skip '~/.github exists; cannot test missing GITHUB_PASSWORD', 1 if $has_config_file;
local $ENV{GITHUB_USER} = 'perl';
like(
exception { App::Nopaste::Service::Gist->_get_auth() },
qr/Export GITHUB_OAUTH_TOKEN first. For example:/,
'User is warned that a GITHUB_OAUTH_TOKEN is required',
);
}
SKIP:
{
skip '~/.github exists; cannot test missing GITHUB_USER', 1 if $has_config_file;
local $ENV{GITHUB_PASSWORD} = 'user';
like(
exception { App::Nopaste::Service::Gist->_get_auth() },
qr/Export GITHUB_OAUTH_TOKEN first. For example:/,
'User is warned that a GITHUB_OAUTH_TOKEN is required',
);
}
done_testing;