grim/convey
Clone
Summary
Browse
Changes
Graph
expose the Run* variables so they can be used in testing and stuff
2019-10-27, Gary Kramlich
2d7b4a79a769
expose the Run* variables so they can be used in testing and stuff
// 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
script
import
(
"testing"
"github.com/stretchr/testify/assert"
"bitbucket.org/rw_grim/convey/aws"
"bitbucket.org/rw_grim/convey/docker"
cYaml
"bitbucket.org/rw_grim/convey/yaml"
)
func
TestEmpty
(
t
*
testing
.
T
)
{
parsedTasks
,
err
:=
Parse
(
""
,
""
,
[]
string
{})
assert
.
Nil
(
t
,
err
)
assert
.
Empty
(
t
,
parsedTasks
)
}
func
TestSimple
(
t
*
testing
.
T
)
{
commands
:=
[]
string
{
"#!/bin/sh"
,
"false"
,
}
parsedTasks
,
err
:=
Parse
(
""
,
""
,
commands
)
assert
.
Nil
(
t
,
err
)
assert
.
Len
(
t
,
parsedTasks
,
1
)
assert
.
IsType
(
t
,
parsedTasks
[
0
],
&
docker
.
Run
{})
}
func
TestSubShellUnknown
(
t
*
testing
.
T
)
{
commands
:=
[]
string
{
"$(true)"
}
parsedTasks
,
err
:=
Parse
(
""
,
""
,
commands
)
assert
.
Nil
(
t
,
err
)
assert
.
Len
(
t
,
parsedTasks
,
1
)
assert
.
IsType
(
t
,
parsedTasks
[
0
],
&
docker
.
Run
{})
run
:=
parsedTasks
[
0
].(
*
docker
.
Run
)
assert
.
Equal
(
t
,
run
.
Script
,
cYaml
.
StringOrSlice
([]
string
{
"$(true)"
}))
}
func
TestBackTicksUnknown
(
t
*
testing
.
T
)
{
commands
:=
[]
string
{
"`true`"
}
parsedTasks
,
err
:=
Parse
(
""
,
""
,
commands
)
assert
.
Nil
(
t
,
err
)
assert
.
Len
(
t
,
parsedTasks
,
1
)
assert
.
IsType
(
t
,
parsedTasks
[
0
],
&
docker
.
Run
{})
run
:=
parsedTasks
[
0
].(
*
docker
.
Run
)
assert
.
Equal
(
t
,
run
.
Script
,
cYaml
.
StringOrSlice
([]
string
{
"`true`"
}))
}
func
TestDockerThenScript
(
t
*
testing
.
T
)
{
commands
:=
[]
string
{
"docker push foo"
,
"pwd"
,
}
parsedTasks
,
err
:=
Parse
(
""
,
""
,
commands
)
assert
.
Nil
(
t
,
err
)
assert
.
Len
(
t
,
parsedTasks
,
2
)
assert
.
IsType
(
t
,
parsedTasks
[
0
],
&
docker
.
Push
{})
assert
.
IsType
(
t
,
parsedTasks
[
1
],
&
docker
.
Run
{})
}
func
TestScriptThenDocker
(
t
*
testing
.
T
)
{
commands
:=
[]
string
{
"pwd"
,
"docker push foo"
,
}
parsedTasks
,
err
:=
Parse
(
""
,
""
,
commands
)
assert
.
Nil
(
t
,
err
)
assert
.
Len
(
t
,
parsedTasks
,
2
)
assert
.
IsType
(
t
,
parsedTasks
[
0
],
&
docker
.
Run
{})
assert
.
IsType
(
t
,
parsedTasks
[
1
],
&
docker
.
Push
{})
}
func
TestMixed
(
t
*
testing
.
T
)
{
commands
:=
[]
string
{
"pwd"
,
"docker push foo"
,
"pwd"
,
}
parsedTasks
,
err
:=
Parse
(
""
,
""
,
commands
)
assert
.
Nil
(
t
,
err
)
assert
.
Len
(
t
,
parsedTasks
,
3
)
assert
.
IsType
(
t
,
parsedTasks
[
0
],
&
docker
.
Run
{})
assert
.
IsType
(
t
,
parsedTasks
[
1
],
&
docker
.
Push
{})
assert
.
IsType
(
t
,
parsedTasks
[
2
],
&
docker
.
Run
{})
}
func
TestAWSECRGetLogin
(
t
*
testing
.
T
)
{
commands
:=
[]
string
{
"aws ecr get-login"
,
"aws ecr get-login --region us-west-2"
,
"$(aws ecr get-login)"
,
"`aws ecr get-login`"
,
}
parsedTasks
,
err
:=
Parse
(
""
,
""
,
commands
)
assert
.
Nil
(
t
,
err
)
assert
.
Len
(
t
,
parsedTasks
,
4
)
assert
.
IsType
(
t
,
parsedTasks
[
0
],
&
aws
.
ECRGetLogin
{})
assert
.
IsType
(
t
,
parsedTasks
[
1
],
&
aws
.
ECRGetLogin
{})
assert
.
IsType
(
t
,
parsedTasks
[
2
],
&
aws
.
ECRGetLogin
{})
assert
.
IsType
(
t
,
parsedTasks
[
3
],
&
aws
.
ECRGetLogin
{})
}