2020-02-12 07:38:30 +00:00
|
|
|
package runner
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2021-05-15 21:11:16 +00:00
|
|
|
"github.com/nektos/act/pkg/common"
|
|
|
|
"github.com/sirupsen/logrus/hooks/test"
|
2020-02-12 07:38:30 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSetEnv(t *testing.T) {
|
2021-01-12 06:39:43 +00:00
|
|
|
a := assert.New(t)
|
2020-02-12 07:38:30 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
rc := new(RunContext)
|
|
|
|
handler := rc.commandHandler(ctx)
|
|
|
|
|
|
|
|
handler("::set-env name=x::valz\n")
|
2021-01-12 06:39:43 +00:00
|
|
|
a.Equal("valz", rc.Env["x"])
|
2020-02-12 07:38:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSetOutput(t *testing.T) {
|
2021-01-12 06:39:43 +00:00
|
|
|
a := assert.New(t)
|
2020-02-12 07:38:30 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
rc := new(RunContext)
|
2020-02-14 08:41:20 +00:00
|
|
|
rc.StepResults = make(map[string]*stepResult)
|
2020-02-12 07:38:30 +00:00
|
|
|
handler := rc.commandHandler(ctx)
|
|
|
|
|
2020-02-14 08:41:20 +00:00
|
|
|
rc.CurrentStep = "my-step"
|
|
|
|
rc.StepResults[rc.CurrentStep] = &stepResult{
|
|
|
|
Outputs: make(map[string]string),
|
|
|
|
}
|
2020-02-12 07:38:30 +00:00
|
|
|
handler("::set-output name=x::valz\n")
|
2021-01-12 06:39:43 +00:00
|
|
|
a.Equal("valz", rc.StepResults["my-step"].Outputs["x"])
|
2020-11-02 13:40:46 +00:00
|
|
|
|
|
|
|
handler("::set-output name=x::percent2%25\n")
|
2021-01-12 06:39:43 +00:00
|
|
|
a.Equal("percent2%", rc.StepResults["my-step"].Outputs["x"])
|
2020-11-02 13:40:46 +00:00
|
|
|
|
|
|
|
handler("::set-output name=x::percent2%25%0Atest\n")
|
2021-01-12 06:39:43 +00:00
|
|
|
a.Equal("percent2%\ntest", rc.StepResults["my-step"].Outputs["x"])
|
2020-11-02 13:40:46 +00:00
|
|
|
|
|
|
|
handler("::set-output name=x::percent2%25%0Atest another3%25test\n")
|
2021-01-12 06:39:43 +00:00
|
|
|
a.Equal("percent2%\ntest another3%test", rc.StepResults["my-step"].Outputs["x"])
|
2020-11-02 13:40:46 +00:00
|
|
|
|
|
|
|
handler("::set-output name=x%3A::percent2%25%0Atest\n")
|
2021-01-12 06:39:43 +00:00
|
|
|
a.Equal("percent2%\ntest", rc.StepResults["my-step"].Outputs["x:"])
|
2020-11-02 13:40:46 +00:00
|
|
|
|
|
|
|
handler("::set-output name=x%3A%2C%0A%25%0D%3A::percent2%25%0Atest\n")
|
2021-01-12 06:39:43 +00:00
|
|
|
a.Equal("percent2%\ntest", rc.StepResults["my-step"].Outputs["x:,\n%\r:"])
|
2020-02-12 07:38:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddpath(t *testing.T) {
|
2021-01-12 06:39:43 +00:00
|
|
|
a := assert.New(t)
|
2020-02-12 07:38:30 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
rc := new(RunContext)
|
|
|
|
handler := rc.commandHandler(ctx)
|
|
|
|
|
2020-02-12 07:55:20 +00:00
|
|
|
handler("::add-path::/zoo\n")
|
2021-01-12 06:39:43 +00:00
|
|
|
a.Equal("/zoo", rc.ExtraPath[0])
|
2020-02-12 07:38:30 +00:00
|
|
|
|
2020-02-13 19:47:38 +00:00
|
|
|
handler("::add-path::/boo\n")
|
2021-01-12 06:39:43 +00:00
|
|
|
a.Equal("/boo", rc.ExtraPath[1])
|
2020-02-12 07:38:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestStopCommands(t *testing.T) {
|
2021-01-12 06:39:43 +00:00
|
|
|
a := assert.New(t)
|
2020-02-12 07:38:30 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
rc := new(RunContext)
|
|
|
|
handler := rc.commandHandler(ctx)
|
|
|
|
|
|
|
|
handler("::set-env name=x::valz\n")
|
2021-01-12 06:39:43 +00:00
|
|
|
a.Equal("valz", rc.Env["x"])
|
2020-02-12 07:38:30 +00:00
|
|
|
handler("::stop-commands::my-end-token\n")
|
|
|
|
handler("::set-env name=x::abcd\n")
|
2021-01-12 06:39:43 +00:00
|
|
|
a.Equal("valz", rc.Env["x"])
|
2020-02-12 07:38:30 +00:00
|
|
|
handler("::my-end-token::\n")
|
|
|
|
handler("::set-env name=x::abcd\n")
|
2021-01-12 06:39:43 +00:00
|
|
|
a.Equal("abcd", rc.Env["x"])
|
2020-02-12 07:38:30 +00:00
|
|
|
}
|
2020-02-24 20:48:12 +00:00
|
|
|
|
|
|
|
func TestAddpathADO(t *testing.T) {
|
2021-01-12 06:39:43 +00:00
|
|
|
a := assert.New(t)
|
2020-02-24 20:48:12 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
rc := new(RunContext)
|
|
|
|
handler := rc.commandHandler(ctx)
|
|
|
|
|
|
|
|
handler("##[add-path]/zoo\n")
|
2021-01-12 06:39:43 +00:00
|
|
|
a.Equal("/zoo", rc.ExtraPath[0])
|
2020-02-24 20:48:12 +00:00
|
|
|
|
|
|
|
handler("##[add-path]/boo\n")
|
2021-01-12 06:39:43 +00:00
|
|
|
a.Equal("/boo", rc.ExtraPath[1])
|
2020-02-24 20:48:12 +00:00
|
|
|
}
|
2021-05-15 21:11:16 +00:00
|
|
|
|
|
|
|
func TestAddmask(t *testing.T) {
|
|
|
|
logger, hook := test.NewNullLogger()
|
|
|
|
|
|
|
|
a := assert.New(t)
|
|
|
|
ctx := context.Background()
|
|
|
|
loggerCtx := common.WithLogger(ctx, logger)
|
|
|
|
|
|
|
|
rc := new(RunContext)
|
|
|
|
handler := rc.commandHandler(loggerCtx)
|
|
|
|
handler("::add-mask::my-secret-value\n")
|
|
|
|
|
|
|
|
a.NotEqual(" \U00002699 *my-secret-value", hook.LastEntry().Message)
|
|
|
|
}
|