Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
3d3df097
Commit
3d3df097
authored
Apr 04, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dry up next_time_from. Move cron_parser_spec to appropriate location.
parent
914bef67
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
105 additions
and
111 deletions
+105
-111
lib/gitlab/ci/cron_parser.rb
lib/gitlab/ci/cron_parser.rb
+1
-5
spec/lib/ci/cron_parser_spec.rb
spec/lib/ci/cron_parser_spec.rb
+0
-106
spec/lib/gitlab/ci/cron_parser_spec.rb
spec/lib/gitlab/ci/cron_parser_spec.rb
+104
-0
No files found.
lib/gitlab/ci/cron_parser.rb
View file @
3d3df097
...
@@ -11,11 +11,7 @@ module Gitlab
...
@@ -11,11 +11,7 @@ module Gitlab
def
next_time_from
(
time
)
def
next_time_from
(
time
)
cron_line
=
try_parse_cron
(
@cron
,
@cron_time_zone
)
cron_line
=
try_parse_cron
(
@cron
,
@cron_time_zone
)
if
cron_line
.
present?
cron_line
.
next_time
(
time
).
in_time_zone
(
Time
.
zone
)
if
cron_line
.
present?
cron_line
.
next_time
(
time
).
in_time_zone
(
Time
.
zone
)
else
nil
end
end
end
def
validation
def
validation
...
...
spec/lib/ci/cron_parser_spec.rb
deleted
100644 → 0
View file @
914bef67
require
'spec_helper'
module
Ci
describe
CronParser
,
lib:
true
do
shared_examples_for
"returns time in the future"
do
it
{
is_expected
.
to
be
>
Time
.
now
}
end
describe
'#next_time_from'
do
subject
{
described_class
.
new
(
cron
,
cron_time_zone
).
next_time_from
(
Time
.
now
)
}
context
'when cron and cron_time_zone are valid'
do
context
'when specific time'
do
let
(
:cron
)
{
'3 4 5 6 *'
}
let
(
:cron_time_zone
)
{
'UTC'
}
it_behaves_like
"returns time in the future"
it
'returns exact time'
do
expect
(
subject
.
min
).
to
eq
(
3
)
expect
(
subject
.
hour
).
to
eq
(
4
)
expect
(
subject
.
day
).
to
eq
(
5
)
expect
(
subject
.
month
).
to
eq
(
6
)
end
end
context
'when specific day of week'
do
let
(
:cron
)
{
'* * * * 0'
}
let
(
:cron_time_zone
)
{
'UTC'
}
it_behaves_like
"returns time in the future"
it
'returns exact day of week'
do
expect
(
subject
.
wday
).
to
eq
(
0
)
end
end
context
'when slash used'
do
let
(
:cron
)
{
'*/10 */6 */10 */10 *'
}
let
(
:cron_time_zone
)
{
'UTC'
}
it_behaves_like
"returns time in the future"
it
'returns specific time'
do
expect
(
subject
.
min
).
to
be_in
([
0
,
10
,
20
,
30
,
40
,
50
])
expect
(
subject
.
hour
).
to
be_in
([
0
,
6
,
12
,
18
])
expect
(
subject
.
day
).
to
be_in
([
1
,
11
,
21
,
31
])
expect
(
subject
.
month
).
to
be_in
([
1
,
11
])
end
end
context
'when range used'
do
let
(
:cron
)
{
'0,20,40 * 1-5 * *'
}
let
(
:cron_time_zone
)
{
'UTC'
}
it_behaves_like
"returns time in the future"
it
'returns specific time'
do
expect
(
subject
.
min
).
to
be_in
([
0
,
20
,
40
])
expect
(
subject
.
day
).
to
be_in
((
1
..
5
).
to_a
)
end
end
context
'when cron_time_zone is US/Pacific'
do
let
(
:cron
)
{
'0 0 * * *'
}
let
(
:cron_time_zone
)
{
'US/Pacific'
}
it_behaves_like
"returns time in the future"
it
'converts time in server time zone'
do
expect
(
subject
.
hour
).
to
eq
(
7
)
end
end
end
context
'when cron and cron_time_zone are invalid'
do
let
(
:cron
)
{
'invalid_cron'
}
let
(
:cron_time_zone
)
{
'invalid_cron_time_zone'
}
it
'returns nil'
do
is_expected
.
to
be_nil
end
end
end
describe
'#validation'
do
it
'returns results'
do
is_valid_cron
,
is_valid_cron_time_zone
=
described_class
.
new
(
'* * * * *'
,
'Europe/Istanbul'
).
validation
expect
(
is_valid_cron
).
to
eq
(
true
)
expect
(
is_valid_cron_time_zone
).
to
eq
(
true
)
end
it
'returns results'
do
is_valid_cron
,
is_valid_cron_time_zone
=
described_class
.
new
(
'*********'
,
'Europe/Istanbul'
).
validation
expect
(
is_valid_cron
).
to
eq
(
false
)
expect
(
is_valid_cron_time_zone
).
to
eq
(
true
)
end
it
'returns results'
do
is_valid_cron
,
is_valid_cron_time_zone
=
described_class
.
new
(
'* * * * *'
,
'Invalid-zone'
).
validation
expect
(
is_valid_cron
).
to
eq
(
true
)
expect
(
is_valid_cron_time_zone
).
to
eq
(
false
)
end
end
end
end
spec/lib/gitlab/ci/cron_parser_spec.rb
0 → 100644
View file @
3d3df097
require
'spec_helper'
describe
Gitlab
::
Ci
::
CronParser
do
shared_examples_for
"returns time in the future"
do
it
{
is_expected
.
to
be
>
Time
.
now
}
end
describe
'#next_time_from'
do
subject
{
described_class
.
new
(
cron
,
cron_time_zone
).
next_time_from
(
Time
.
now
)
}
context
'when cron and cron_time_zone are valid'
do
context
'when specific time'
do
let
(
:cron
)
{
'3 4 5 6 *'
}
let
(
:cron_time_zone
)
{
'UTC'
}
it_behaves_like
"returns time in the future"
it
'returns exact time'
do
expect
(
subject
.
min
).
to
eq
(
3
)
expect
(
subject
.
hour
).
to
eq
(
4
)
expect
(
subject
.
day
).
to
eq
(
5
)
expect
(
subject
.
month
).
to
eq
(
6
)
end
end
context
'when specific day of week'
do
let
(
:cron
)
{
'* * * * 0'
}
let
(
:cron_time_zone
)
{
'UTC'
}
it_behaves_like
"returns time in the future"
it
'returns exact day of week'
do
expect
(
subject
.
wday
).
to
eq
(
0
)
end
end
context
'when slash used'
do
let
(
:cron
)
{
'*/10 */6 */10 */10 *'
}
let
(
:cron_time_zone
)
{
'UTC'
}
it_behaves_like
"returns time in the future"
it
'returns specific time'
do
expect
(
subject
.
min
).
to
be_in
([
0
,
10
,
20
,
30
,
40
,
50
])
expect
(
subject
.
hour
).
to
be_in
([
0
,
6
,
12
,
18
])
expect
(
subject
.
day
).
to
be_in
([
1
,
11
,
21
,
31
])
expect
(
subject
.
month
).
to
be_in
([
1
,
11
])
end
end
context
'when range used'
do
let
(
:cron
)
{
'0,20,40 * 1-5 * *'
}
let
(
:cron_time_zone
)
{
'UTC'
}
it_behaves_like
"returns time in the future"
it
'returns specific time'
do
expect
(
subject
.
min
).
to
be_in
([
0
,
20
,
40
])
expect
(
subject
.
day
).
to
be_in
((
1
..
5
).
to_a
)
end
end
context
'when cron_time_zone is US/Pacific'
do
let
(
:cron
)
{
'0 0 * * *'
}
let
(
:cron_time_zone
)
{
'US/Pacific'
}
it_behaves_like
"returns time in the future"
it
'converts time in server time zone'
do
expect
(
subject
.
hour
).
to
eq
(
7
)
end
end
end
context
'when cron and cron_time_zone are invalid'
do
let
(
:cron
)
{
'invalid_cron'
}
let
(
:cron_time_zone
)
{
'invalid_cron_time_zone'
}
it
'returns nil'
do
is_expected
.
to
be_nil
end
end
end
describe
'#validation'
do
it
'returns results'
do
is_valid_cron
,
is_valid_cron_time_zone
=
described_class
.
new
(
'* * * * *'
,
'Europe/Istanbul'
).
validation
expect
(
is_valid_cron
).
to
eq
(
true
)
expect
(
is_valid_cron_time_zone
).
to
eq
(
true
)
end
it
'returns results'
do
is_valid_cron
,
is_valid_cron_time_zone
=
described_class
.
new
(
'*********'
,
'Europe/Istanbul'
).
validation
expect
(
is_valid_cron
).
to
eq
(
false
)
expect
(
is_valid_cron_time_zone
).
to
eq
(
true
)
end
it
'returns results'
do
is_valid_cron
,
is_valid_cron_time_zone
=
described_class
.
new
(
'* * * * *'
,
'Invalid-zone'
).
validation
expect
(
is_valid_cron
).
to
eq
(
true
)
expect
(
is_valid_cron_time_zone
).
to
eq
(
false
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment