grim/convey
Clone
Summary
Browse
Changes
Graph
Added tag v0.10.1 for changeset 6fcf770a1b72
2017-09-26, Gary Kramlich
7fd7299d950f
Added tag v0.10.1 for changeset 6fcf770a1b72
/*
* Convey
* Copyright 2016-2017 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
state
import
(
"testing"
"github.com/aphistic/sweet"
junit
"github.com/aphistic/sweet-junit"
.
"github.com/onsi/gomega"
)
type
stateSuite
struct
{}
func
TestMain
(
m
*
testing
.
M
)
{
RegisterFailHandler
(
sweet
.
GomegaFail
)
sweet
.
Run
(
m
,
func
(
s
*
sweet
.
S
)
{
s
.
RegisterPlugin
(
junit
.
NewPlugin
())
s
.
AddSuite
(
&
stateSuite
{})
})
}
func
(
e
*
stateSuite
)
TestMap
(
t
sweet
.
T
)
{
st
:=
&
State
{}
st
.
Environment
=
[]
string
{
"FOO=BAR"
}
mapEnv
:=
func
(
val
string
)
[]
string
{
mapped
,
err
:=
st
.
MapSlice
([]
string
{
val
},
st
.
Environment
)
Expect
(
err
).
To
(
BeNil
())
return
mapped
}
Expect
(
mapEnv
(
"$X"
)).
To
(
Equal
([]
string
{
"$X"
}))
Expect
(
mapEnv
(
"$FOO"
)).
To
(
Equal
([]
string
{
"BAR"
}))
st
.
PushExtendFrame
([]
string
{
"X=A;B;C"
},
[]
string
{
"X"
},
";"
)
Expect
(
mapEnv
(
"$X"
)).
To
(
Equal
([]
string
{
"A"
,
"B"
,
"C"
}))
Expect
(
mapEnv
(
"$FOO"
)).
To
(
Equal
([]
string
{
"BAR"
}))
st
.
PushExtendFrame
([]
string
{
"BAR=B;A;R::B;A;Z"
,
"FOO=SAME"
},
[]
string
{
"BAR"
},
"::"
)
Expect
(
mapEnv
(
"$X"
)).
To
(
Equal
([]
string
{
"A"
,
"B"
,
"C"
}))
Expect
(
mapEnv
(
"$FOO"
)).
To
(
Equal
([]
string
{
"BAR"
}))
Expect
(
mapEnv
(
"$BAR"
)).
To
(
Equal
([]
string
{
"B;A;R"
,
"B;A;Z"
}))
Expect
(
st
.
PopExtendFrame
()).
To
(
BeNil
())
Expect
(
st
.
PopExtendFrame
()).
To
(
BeNil
())
Expect
(
mapEnv
(
"$X"
)).
To
(
Equal
([]
string
{
"$X"
}))
Expect
(
mapEnv
(
"$FOO"
)).
To
(
Equal
([]
string
{
"BAR"
}))
}
func
(
e
*
stateSuite
)
TestPopExtendFrameSize
(
t
sweet
.
T
)
{
st
:=
&
State
{}
st
.
PushExtendFrame
(
nil
,
nil
,
""
)
Expect
(
st
.
ExtendFrames
).
To
(
HaveLen
(
1
))
st
.
PushExtendFrame
(
nil
,
nil
,
""
)
Expect
(
st
.
ExtendFrames
).
To
(
HaveLen
(
2
))
Expect
(
st
.
PopExtendFrame
()).
To
(
BeNil
())
Expect
(
st
.
ExtendFrames
).
To
(
HaveLen
(
1
))
Expect
(
st
.
PopExtendFrame
()).
To
(
BeNil
())
Expect
(
st
.
ExtendFrames
).
To
(
HaveLen
(
0
))
}
func
(
e
*
stateSuite
)
TestPopExtendFrameRestoresEnv
(
t
sweet
.
T
)
{
st
:=
&
State
{}
st
.
Environment
=
[]
string
{
"FOO=BAR"
,
"BAR=BAZ"
}
st
.
PushExtendFrame
([]
string
{
"FOO=BONK"
,
"BAZ=BONK"
},
nil
,
""
)
Expect
(
st
.
Environment
).
To
(
HaveLen
(
3
))
Expect
(
st
.
Environment
).
To
(
ConsistOf
([]
string
{
"FOO=BAR"
,
"BAR=BAZ"
,
"BAZ=BONK"
}))
st
.
PopExtendFrame
()
Expect
(
st
.
Environment
).
To
(
HaveLen
(
2
))
Expect
(
st
.
Environment
).
To
(
ConsistOf
([]
string
{
"FOO=BAR"
,
"BAR=BAZ"
}))
}
func
(
e
*
stateSuite
)
TestPopExtendFrameEmpty
(
t
sweet
.
T
)
{
st
:=
&
State
{}
Expect
(
st
.
PopExtendFrame
()).
To
(
Equal
(
errEmptyExtendStack
))
}
func
(
e
*
stateSuite
)
TestGetName
(
t
sweet
.
T
)
{
Expect
(
getName
(
"foo"
)).
To
(
Equal
(
""
))
Expect
(
getName
(
"$FOO"
)).
To
(
Equal
(
"FOO"
))
Expect
(
getName
(
"${FOO}"
)).
To
(
Equal
(
"FOO"
))
}