2021-09-09 11:12:25 -07:00
|
|
|
//go:build !windows
|
2021-03-17 04:49:30 -07:00
|
|
|
|
2019-03-13 04:14:30 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestExecuteCommand(t *testing.T) {
|
2021-01-10 02:52:59 -08:00
|
|
|
env := &environment{}
|
2021-08-01 06:25:15 -07:00
|
|
|
debug := false
|
|
|
|
env.init(&args{
|
|
|
|
Debug: &debug,
|
|
|
|
})
|
2021-11-26 01:37:33 -08:00
|
|
|
var props properties = map[Property]interface{}{
|
|
|
|
Command: "echo hello",
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
|
|
|
c := &command{
|
|
|
|
props: props,
|
|
|
|
env: env,
|
|
|
|
}
|
|
|
|
enabled := c.enabled()
|
|
|
|
assert.True(t, enabled)
|
2021-01-05 04:05:37 -08:00
|
|
|
assert.Equal(t, "hello", c.string())
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestExecuteMultipleCommandsOrFirst(t *testing.T) {
|
2021-01-10 02:52:59 -08:00
|
|
|
env := &environment{}
|
2021-08-01 06:25:15 -07:00
|
|
|
debug := false
|
|
|
|
env.init(&args{
|
|
|
|
Debug: &debug,
|
|
|
|
})
|
2021-11-26 01:37:33 -08:00
|
|
|
var props properties = map[Property]interface{}{
|
|
|
|
Command: "exit 1 || echo hello",
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
|
|
|
c := &command{
|
|
|
|
props: props,
|
|
|
|
env: env,
|
|
|
|
}
|
|
|
|
enabled := c.enabled()
|
|
|
|
assert.True(t, enabled)
|
2021-01-05 04:05:37 -08:00
|
|
|
assert.Equal(t, "hello", c.string())
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestExecuteMultipleCommandsOrSecond(t *testing.T) {
|
2021-01-10 02:52:59 -08:00
|
|
|
env := &environment{}
|
2021-08-01 06:25:15 -07:00
|
|
|
debug := false
|
|
|
|
env.init(&args{
|
|
|
|
Debug: &debug,
|
|
|
|
})
|
2021-11-26 01:37:33 -08:00
|
|
|
var props properties = map[Property]interface{}{
|
|
|
|
Command: "echo hello || echo world",
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
|
|
|
c := &command{
|
|
|
|
props: props,
|
|
|
|
env: env,
|
|
|
|
}
|
|
|
|
enabled := c.enabled()
|
|
|
|
assert.True(t, enabled)
|
2021-01-05 04:05:37 -08:00
|
|
|
assert.Equal(t, "hello", c.string())
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestExecuteMultipleCommandsAnd(t *testing.T) {
|
2021-01-10 02:52:59 -08:00
|
|
|
env := &environment{}
|
2021-08-01 06:25:15 -07:00
|
|
|
debug := false
|
|
|
|
env.init(&args{
|
|
|
|
Debug: &debug,
|
|
|
|
})
|
2021-11-26 01:37:33 -08:00
|
|
|
var props properties = map[Property]interface{}{
|
|
|
|
Command: "echo hello && echo world",
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
|
|
|
c := &command{
|
|
|
|
props: props,
|
|
|
|
env: env,
|
|
|
|
}
|
|
|
|
enabled := c.enabled()
|
|
|
|
assert.True(t, enabled)
|
2021-01-05 04:05:37 -08:00
|
|
|
assert.Equal(t, "helloworld", c.string())
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestExecuteSingleCommandEmpty(t *testing.T) {
|
2021-01-10 02:52:59 -08:00
|
|
|
env := &environment{}
|
2021-08-01 06:25:15 -07:00
|
|
|
debug := false
|
|
|
|
env.init(&args{
|
|
|
|
Debug: &debug,
|
|
|
|
})
|
2021-11-26 01:37:33 -08:00
|
|
|
var props properties = map[Property]interface{}{
|
|
|
|
Command: "",
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
|
|
|
c := &command{
|
|
|
|
props: props,
|
|
|
|
env: env,
|
|
|
|
}
|
|
|
|
enabled := c.enabled()
|
|
|
|
assert.False(t, enabled)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestExecuteSingleCommandNoCommandProperty(t *testing.T) {
|
2021-01-10 02:52:59 -08:00
|
|
|
env := &environment{}
|
2021-08-01 06:25:15 -07:00
|
|
|
debug := false
|
|
|
|
env.init(&args{
|
|
|
|
Debug: &debug,
|
|
|
|
})
|
2021-11-26 01:37:33 -08:00
|
|
|
var props properties
|
2019-03-13 04:14:30 -07:00
|
|
|
c := &command{
|
|
|
|
props: props,
|
|
|
|
env: env,
|
|
|
|
}
|
|
|
|
enabled := c.enabled()
|
|
|
|
assert.True(t, enabled)
|
|
|
|
assert.Equal(t, "no command specified", c.value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestExecuteMultipleCommandsAndDisabled(t *testing.T) {
|
2021-01-10 02:52:59 -08:00
|
|
|
env := &environment{}
|
2021-08-01 06:25:15 -07:00
|
|
|
debug := false
|
|
|
|
env.init(&args{
|
|
|
|
Debug: &debug,
|
|
|
|
})
|
2021-11-26 01:37:33 -08:00
|
|
|
var props properties = map[Property]interface{}{
|
|
|
|
Command: "echo && echo",
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
|
|
|
c := &command{
|
|
|
|
props: props,
|
|
|
|
env: env,
|
|
|
|
}
|
|
|
|
enabled := c.enabled()
|
|
|
|
assert.False(t, enabled)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestExecuteMultipleCommandsOrDisabled(t *testing.T) {
|
2021-01-10 02:52:59 -08:00
|
|
|
env := &environment{}
|
2021-08-01 06:25:15 -07:00
|
|
|
debug := false
|
|
|
|
env.init(&args{
|
|
|
|
Debug: &debug,
|
|
|
|
})
|
2021-11-26 01:37:33 -08:00
|
|
|
var props properties = map[Property]interface{}{
|
|
|
|
Command: "echo|| echo",
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
|
|
|
c := &command{
|
|
|
|
props: props,
|
|
|
|
env: env,
|
|
|
|
}
|
|
|
|
enabled := c.enabled()
|
|
|
|
assert.False(t, enabled)
|
|
|
|
}
|