grim/convey
Clone
Summary
Browse
Changes
Graph
ChangeLog the addition of environment to metaplans
2021-12-23, Gary Kramlich
b7459765fff9
ChangeLog the addition of environment to metaplans
// Convey
// Copyright 2016-2018 Gary Kramlich <grim@reaperworld.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package
runtime
import
(
"testing"
"time"
"github.com/stretchr/testify/assert"
"keep.imfreedom.org/grim/convey/environment"
)
func
runPlan
(
path
string
,
p
Plan
,
tasks
map
[
string
]
Task
)
error
{
env
:=
environment
.
New
()
rt
:=
New
(
env
,
""
,
environment
.
New
(),
false
,
false
,
0
*
time
.
Second
)
rt
.
Tasks
=
tasks
defer
rt
.
Shutdown
()
return
p
.
Execute
(
path
,
rt
)
}
func
TestPlanStagesNone
(
t
*
testing
.
T
)
{
p
:=
Plan
{}
err
:=
runPlan
(
"empty"
,
p
,
nil
)
assert
.
NotNil
(
t
,
err
)
}
func
TestPlanStagesSingle
(
t
*
testing
.
T
)
{
data
:=
`
stages:
- tasks:
- count`
p
:=
unmarshal
(
t
,
data
)
count
:=
&
Count
{}
tasks
:=
map
[
string
]
Task
{
"count"
:
count
}
err
:=
runPlan
(
"single"
,
p
,
tasks
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
1
,
count
.
Count
)
}
func
TestPlanStagesMultiple
(
t
*
testing
.
T
)
{
data
:=
`
stages:
- tasks:
- count
- tasks:
- count`
p
:=
unmarshal
(
t
,
data
)
count
:=
&
Count
{}
tasks
:=
map
[
string
]
Task
{
"count"
:
count
}
err
:=
runPlan
(
"multiple"
,
p
,
tasks
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
2
,
count
.
Count
)
}
func
TestPlanStagesRunOnFailure
(
t
*
testing
.
T
)
{
data
:=
`
stages:
- tasks:
- fail
- tasks:
- count
run: on-failure`
p
:=
unmarshal
(
t
,
data
)
count
:=
&
Count
{}
tasks
:=
map
[
string
]
Task
{
"fail"
:
&
Fail
{},
"count"
:
count
,
}
err
:=
runPlan
(
"run-on-failure"
,
p
,
tasks
)
assert
.
NotNil
(
t
,
err
)
assert
.
Equal
(
t
,
1
,
count
.
Count
)
}
func
TestPlanStagesRunOnSuccess
(
t
*
testing
.
T
)
{
data
:=
`
stages:
- tasks:
- fail
- tasks:
- count
run: on-success
`
p
:=
unmarshal
(
t
,
data
)
count
:=
&
Count
{}
tasks
:=
map
[
string
]
Task
{
"fail"
:
&
Fail
{},
"count"
:
count
,
}
err
:=
runPlan
(
"run-on-success"
,
p
,
tasks
)
assert
.
NotNil
(
t
,
err
)
assert
.
Equal
(
t
,
0
,
count
.
Count
)
}
func
TestPlanStagesRunAlways
(
t
*
testing
.
T
)
{
data
:=
`
stages:
- tasks:
- fail
- tasks:
- count
run: always
`
p
:=
unmarshal
(
t
,
data
)
count
:=
&
Count
{}
tasks
:=
map
[
string
]
Task
{
"fail"
:
&
Fail
{},
"count"
:
count
,
}
err
:=
runPlan
(
"run-always"
,
p
,
tasks
)
assert
.
NotNil
(
t
,
err
)
assert
.
Equal
(
t
,
1
,
count
.
Count
)
}
func
TestPlanStagesDisabled
(
t
*
testing
.
T
)
{
data
:=
`
stages:
- tasks:
- fail
enabled: false
- tasks:
- count
`
p
:=
unmarshal
(
t
,
data
)
count
:=
&
Count
{}
tasks
:=
map
[
string
]
Task
{
"fail"
:
&
Fail
{},
"count"
:
count
,
}
err
:=
runPlan
(
"disabled-stage-skipped"
,
p
,
tasks
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
1
,
count
.
Count
)
}
func
TestPlanStagesConcurrent
(
t
*
testing
.
T
)
{
data
:=
`
stages:
- tasks:
- count
- count
concurrent: true
`
p
:=
unmarshal
(
t
,
data
)
count
:=
&
Count
{}
tasks
:=
map
[
string
]
Task
{
"count"
:
count
,
}
err
:=
runPlan
(
"concurrent-stage"
,
p
,
tasks
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
2
,
count
.
Count
)
}