grim/convey
Clone
Summary
Browse
Changes
Graph
We need to clean up the workspace directory even while testing
2019-10-27, Gary Kramlich
c5c5a718819f
We need to clean up the workspace directory even while testing
// 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
docker
import
(
"testing"
"github.com/go-yaml/yaml"
"github.com/stretchr/testify/assert"
cYaml
"hg.sr.ht/~grim/convey/yaml"
)
func
TestBuildDockerfileRequired
(
t
*
testing
.
T
)
{
b
:=
&
Build
{
Tag
:
"foo"
}
assert
.
EqualError
(
t
,
b
.
Valid
(),
errNoDockerFile
.
Error
())
}
func
TestBuildTagRequired
(
t
*
testing
.
T
)
{
b
:=
&
Build
{
Dockerfile
:
"Dockerfile"
}
assert
.
EqualError
(
t
,
b
.
Valid
(),
errNoTag
.
Error
())
}
func
TestBuild
(
t
*
testing
.
T
)
{
b
:=
&
Build
{
Dockerfile
:
"Dockerfile"
,
Tag
:
"tag"
,
}
assert
.
Nil
(
t
,
b
.
Valid
())
}
func
TestBuildUnmarshalNormal
(
t
*
testing
.
T
)
{
data
:=
`dockerfile: dockerfile
files:
- filename1
tag: tag
labels:
- label1
arguments:
- argument1
`
b
:=
Build
{}
err
:=
yaml
.
Unmarshal
([]
byte
(
data
),
&
b
)
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
b
.
Valid
())
assert
.
Equal
(
t
,
b
.
Dockerfile
,
"dockerfile"
)
assert
.
Equal
(
t
,
b
.
Files
,
cYaml
.
StringOrSlice
{
"filename1"
})
assert
.
Equal
(
t
,
b
.
Tag
,
"tag"
)
assert
.
Equal
(
t
,
b
.
Labels
,
cYaml
.
StringOrSlice
{
"label1"
})
assert
.
Equal
(
t
,
b
.
Arguments
,
cYaml
.
StringOrSlice
{
"argument1"
})
}
func
TestBuildUnmarshalMissingDockerfile
(
t
*
testing
.
T
)
{
data
:=
`tag: tag`
b
:=
Build
{}
err
:=
yaml
.
Unmarshal
([]
byte
(
data
),
&
b
)
assert
.
Nil
(
t
,
err
)
assert
.
EqualError
(
t
,
b
.
Valid
(),
errNoDockerFile
.
Error
())
}
func
TestBuildUnmarshalMissingTag
(
t
*
testing
.
T
)
{
data
:=
`dockerfile: dockerfile`
b
:=
Build
{}
err
:=
yaml
.
Unmarshal
([]
byte
(
data
),
&
b
)
assert
.
Nil
(
t
,
err
)
assert
.
EqualError
(
t
,
b
.
Valid
(),
errNoTag
.
Error
())
}