grim/convey
Clone
Summary
Browse
Changes
Graph
required_version should be required-version to match other attributes.
2018-02-18, Gary Kramlich
b4e7049d5ec1
required_version should be required-version to match other attributes.
// 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/aphistic/sweet"
junit
"github.com/aphistic/sweet-junit"
.
"github.com/onsi/gomega"
"bitbucket.org/rw_grim/convey/aws"
"bitbucket.org/rw_grim/convey/docker"
"bitbucket.org/rw_grim/convey/tasks"
)
type
scriptSuite
struct
{}
func
TestMain
(
m
*
testing
.
M
)
{
RegisterFailHandler
(
sweet
.
GomegaFail
)
sweet
.
Run
(
m
,
func
(
s
*
sweet
.
S
)
{
s
.
RegisterPlugin
(
junit
.
NewPlugin
())
s
.
AddSuite
(
&
scriptSuite
{})
})
}
func
(
s
*
scriptSuite
)
TestEmpty
(
t
sweet
.
T
)
{
parsedTasks
,
err
:=
Parse
(
""
,
""
,
[]
string
{})
Expect
(
err
).
To
(
BeNil
())
Expect
(
parsedTasks
).
To
(
BeEquivalentTo
([]
tasks
.
Task
{}))
}
func
(
s
*
scriptSuite
)
TestSimple
(
t
sweet
.
T
)
{
commands
:=
[]
string
{
"#!/bin/sh"
,
"false"
,
}
parsedTasks
,
err
:=
Parse
(
""
,
""
,
commands
)
Expect
(
err
).
To
(
BeNil
())
Expect
(
len
(
parsedTasks
)).
To
(
Equal
(
1
))
Expect
(
parsedTasks
[
0
]).
To
(
BeAssignableToTypeOf
(
&
docker
.
Run
{}))
}
func
(
s
*
scriptSuite
)
TestSubShellUnknown
(
t
sweet
.
T
)
{
commands
:=
[]
string
{
"$(true)"
}
parsedTasks
,
err
:=
Parse
(
""
,
""
,
commands
)
Expect
(
err
).
To
(
BeNil
())
Expect
(
len
(
parsedTasks
)).
To
(
Equal
(
1
))
Expect
(
parsedTasks
[
0
]).
To
(
BeAssignableToTypeOf
(
&
docker
.
Run
{}))
run
:=
parsedTasks
[
0
].(
*
docker
.
Run
)
Expect
(
run
.
Script
).
To
(
BeEquivalentTo
([]
string
{
"$(true)"
}))
}
func
(
s
*
scriptSuite
)
TestBackTicksUnknown
(
t
sweet
.
T
)
{
commands
:=
[]
string
{
"`true`"
}
parsedTasks
,
err
:=
Parse
(
""
,
""
,
commands
)
Expect
(
err
).
To
(
BeNil
())
Expect
(
len
(
parsedTasks
)).
To
(
Equal
(
1
))
Expect
(
parsedTasks
[
0
]).
To
(
BeAssignableToTypeOf
(
&
docker
.
Run
{}))
run
:=
parsedTasks
[
0
].(
*
docker
.
Run
)
Expect
(
run
.
Script
).
To
(
BeEquivalentTo
([]
string
{
"`true`"
}))
}
func
(
s
*
scriptSuite
)
TestDockerThenScript
(
t
sweet
.
T
)
{
commands
:=
[]
string
{
"docker push foo"
,
"pwd"
,
}
parsedTasks
,
err
:=
Parse
(
""
,
""
,
commands
)
Expect
(
err
).
To
(
BeNil
())
Expect
(
len
(
parsedTasks
)).
To
(
Equal
(
2
))
Expect
(
parsedTasks
[
0
]).
To
(
BeAssignableToTypeOf
(
&
docker
.
Push
{}))
Expect
(
parsedTasks
[
1
]).
To
(
BeAssignableToTypeOf
(
&
docker
.
Run
{}))
}
func
(
s
*
scriptSuite
)
TestScriptThenDocker
(
t
sweet
.
T
)
{
commands
:=
[]
string
{
"pwd"
,
"docker push foo"
,
}
parsedTasks
,
err
:=
Parse
(
""
,
""
,
commands
)
Expect
(
err
).
To
(
BeNil
())
Expect
(
len
(
parsedTasks
)).
To
(
Equal
(
2
))
Expect
(
parsedTasks
[
0
]).
To
(
BeAssignableToTypeOf
(
&
docker
.
Run
{}))
Expect
(
parsedTasks
[
1
]).
To
(
BeAssignableToTypeOf
(
&
docker
.
Push
{}))
}
func
(
s
*
scriptSuite
)
TestMixed
(
t
sweet
.
T
)
{
commands
:=
[]
string
{
"pwd"
,
"docker push foo"
,
"pwd"
,
}
parsedTasks
,
err
:=
Parse
(
""
,
""
,
commands
)
Expect
(
err
).
To
(
BeNil
())
Expect
(
len
(
parsedTasks
)).
To
(
Equal
(
3
))
Expect
(
parsedTasks
[
0
]).
To
(
BeAssignableToTypeOf
(
&
docker
.
Run
{}))
Expect
(
parsedTasks
[
1
]).
To
(
BeAssignableToTypeOf
(
&
docker
.
Push
{}))
Expect
(
parsedTasks
[
2
]).
To
(
BeAssignableToTypeOf
(
&
docker
.
Run
{}))
}
func
(
s
*
scriptSuite
)
TestAWSECRGetLogin
(
t
sweet
.
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
)
Expect
(
err
).
To
(
BeNil
())
Expect
(
len
(
parsedTasks
)).
To
(
Equal
(
4
))
Expect
(
parsedTasks
[
0
]).
To
(
BeAssignableToTypeOf
(
&
aws
.
ECRGetLogin
{}))
Expect
(
parsedTasks
[
1
]).
To
(
BeAssignableToTypeOf
(
&
aws
.
ECRGetLogin
{}))
Expect
(
parsedTasks
[
2
]).
To
(
BeAssignableToTypeOf
(
&
aws
.
ECRGetLogin
{}))
Expect
(
parsedTasks
[
3
]).
To
(
BeAssignableToTypeOf
(
&
aws
.
ECRGetLogin
{}))
}