2020-02-12 01:38:30 -06:00
|
|
|
package runner
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSetEnv(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
ctx := context.Background()
|
|
|
|
rc := new(RunContext)
|
|
|
|
handler := rc.commandHandler(ctx)
|
|
|
|
|
|
|
|
handler("::set-env name=x::valz\n")
|
|
|
|
assert.Equal("valz", rc.Env["x"])
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSetOutput(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
ctx := context.Background()
|
|
|
|
rc := new(RunContext)
|
2020-02-14 02:41:20 -06:00
|
|
|
rc.StepResults = make(map[string]*stepResult)
|
2020-02-12 01:38:30 -06:00
|
|
|
handler := rc.commandHandler(ctx)
|
|
|
|
|
2020-02-14 02:41:20 -06:00
|
|
|
rc.CurrentStep = "my-step"
|
|
|
|
rc.StepResults[rc.CurrentStep] = &stepResult{
|
|
|
|
Outputs: make(map[string]string),
|
|
|
|
}
|
2020-02-12 01:38:30 -06:00
|
|
|
handler("::set-output name=x::valz\n")
|
2020-02-14 02:41:20 -06:00
|
|
|
assert.Equal("valz", rc.StepResults["my-step"].Outputs["x"])
|
2020-02-12 01:38:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddpath(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
ctx := context.Background()
|
|
|
|
rc := new(RunContext)
|
|
|
|
handler := rc.commandHandler(ctx)
|
|
|
|
|
2020-02-12 01:55:20 -06:00
|
|
|
handler("::add-path::/zoo\n")
|
2020-02-13 13:47:38 -06:00
|
|
|
assert.Equal("/zoo", rc.ExtraPath[0])
|
2020-02-12 01:38:30 -06:00
|
|
|
|
2020-02-13 13:47:38 -06:00
|
|
|
handler("::add-path::/boo\n")
|
|
|
|
assert.Equal("/boo", rc.ExtraPath[1])
|
2020-02-12 01:38:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestStopCommands(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
ctx := context.Background()
|
|
|
|
rc := new(RunContext)
|
|
|
|
handler := rc.commandHandler(ctx)
|
|
|
|
|
|
|
|
handler("::set-env name=x::valz\n")
|
|
|
|
assert.Equal("valz", rc.Env["x"])
|
|
|
|
handler("::stop-commands::my-end-token\n")
|
|
|
|
handler("::set-env name=x::abcd\n")
|
|
|
|
assert.Equal("valz", rc.Env["x"])
|
|
|
|
handler("::my-end-token::\n")
|
|
|
|
handler("::set-env name=x::abcd\n")
|
|
|
|
assert.Equal("abcd", rc.Env["x"])
|
|
|
|
}
|
2020-02-24 14:48:12 -06:00
|
|
|
|
|
|
|
func TestAddpathADO(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
ctx := context.Background()
|
|
|
|
rc := new(RunContext)
|
|
|
|
handler := rc.commandHandler(ctx)
|
|
|
|
|
|
|
|
handler("##[add-path]/zoo\n")
|
|
|
|
assert.Equal("/zoo", rc.ExtraPath[0])
|
|
|
|
|
|
|
|
handler("##[add-path]/boo\n")
|
|
|
|
assert.Equal("/boo", rc.ExtraPath[1])
|
|
|
|
}
|