2020-02-12 01:38:30 -06:00
|
|
|
package runner
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2021-05-15 16:11:16 -05:00
|
|
|
"github.com/sirupsen/logrus/hooks/test"
|
2020-02-12 01:38:30 -06:00
|
|
|
"github.com/stretchr/testify/assert"
|
2021-06-23 13:09:27 -05:00
|
|
|
|
|
|
|
"github.com/nektos/act/pkg/common"
|
2020-02-12 01:38:30 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSetEnv(t *testing.T) {
|
2021-01-12 00:39:43 -06:00
|
|
|
a := assert.New(t)
|
2020-02-12 01:38:30 -06:00
|
|
|
ctx := context.Background()
|
|
|
|
rc := new(RunContext)
|
|
|
|
handler := rc.commandHandler(ctx)
|
|
|
|
|
|
|
|
handler("::set-env name=x::valz\n")
|
2021-01-12 00:39:43 -06:00
|
|
|
a.Equal("valz", rc.Env["x"])
|
2020-02-12 01:38:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSetOutput(t *testing.T) {
|
2021-01-12 00:39:43 -06:00
|
|
|
a := assert.New(t)
|
2020-02-12 01:38:30 -06:00
|
|
|
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")
|
2021-01-12 00:39:43 -06:00
|
|
|
a.Equal("valz", rc.StepResults["my-step"].Outputs["x"])
|
2020-11-02 07:40:46 -06:00
|
|
|
|
|
|
|
handler("::set-output name=x::percent2%25\n")
|
2021-01-12 00:39:43 -06:00
|
|
|
a.Equal("percent2%", rc.StepResults["my-step"].Outputs["x"])
|
2020-11-02 07:40:46 -06:00
|
|
|
|
|
|
|
handler("::set-output name=x::percent2%25%0Atest\n")
|
2021-01-12 00:39:43 -06:00
|
|
|
a.Equal("percent2%\ntest", rc.StepResults["my-step"].Outputs["x"])
|
2020-11-02 07:40:46 -06:00
|
|
|
|
|
|
|
handler("::set-output name=x::percent2%25%0Atest another3%25test\n")
|
2021-01-12 00:39:43 -06:00
|
|
|
a.Equal("percent2%\ntest another3%test", rc.StepResults["my-step"].Outputs["x"])
|
2020-11-02 07:40:46 -06:00
|
|
|
|
|
|
|
handler("::set-output name=x%3A::percent2%25%0Atest\n")
|
2021-01-12 00:39:43 -06:00
|
|
|
a.Equal("percent2%\ntest", rc.StepResults["my-step"].Outputs["x:"])
|
2020-11-02 07:40:46 -06:00
|
|
|
|
|
|
|
handler("::set-output name=x%3A%2C%0A%25%0D%3A::percent2%25%0Atest\n")
|
2021-01-12 00:39:43 -06:00
|
|
|
a.Equal("percent2%\ntest", rc.StepResults["my-step"].Outputs["x:,\n%\r:"])
|
2020-02-12 01:38:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddpath(t *testing.T) {
|
2021-01-12 00:39:43 -06:00
|
|
|
a := assert.New(t)
|
2020-02-12 01:38:30 -06:00
|
|
|
ctx := context.Background()
|
|
|
|
rc := new(RunContext)
|
|
|
|
handler := rc.commandHandler(ctx)
|
|
|
|
|
2020-02-12 01:55:20 -06:00
|
|
|
handler("::add-path::/zoo\n")
|
2021-01-12 00:39:43 -06:00
|
|
|
a.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")
|
2021-01-12 00:39:43 -06:00
|
|
|
a.Equal("/boo", rc.ExtraPath[1])
|
2020-02-12 01:38:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestStopCommands(t *testing.T) {
|
2021-12-09 09:10:56 -06:00
|
|
|
logger, hook := test.NewNullLogger()
|
|
|
|
|
2021-01-12 00:39:43 -06:00
|
|
|
a := assert.New(t)
|
2021-12-09 09:10:56 -06:00
|
|
|
ctx := common.WithLogger(context.Background(), logger)
|
2020-02-12 01:38:30 -06:00
|
|
|
rc := new(RunContext)
|
|
|
|
handler := rc.commandHandler(ctx)
|
|
|
|
|
|
|
|
handler("::set-env name=x::valz\n")
|
2021-01-12 00:39:43 -06:00
|
|
|
a.Equal("valz", rc.Env["x"])
|
2020-02-12 01:38:30 -06:00
|
|
|
handler("::stop-commands::my-end-token\n")
|
|
|
|
handler("::set-env name=x::abcd\n")
|
2021-01-12 00:39:43 -06:00
|
|
|
a.Equal("valz", rc.Env["x"])
|
2020-02-12 01:38:30 -06:00
|
|
|
handler("::my-end-token::\n")
|
|
|
|
handler("::set-env name=x::abcd\n")
|
2021-01-12 00:39:43 -06:00
|
|
|
a.Equal("abcd", rc.Env["x"])
|
2021-12-09 09:10:56 -06:00
|
|
|
|
|
|
|
messages := make([]string, 0)
|
|
|
|
for _, entry := range hook.AllEntries() {
|
|
|
|
messages = append(messages, entry.Message)
|
|
|
|
}
|
|
|
|
|
|
|
|
a.Contains(messages, " \U00002699 ::set-env name=x::abcd\n")
|
2020-02-12 01:38:30 -06:00
|
|
|
}
|
2020-02-24 14:48:12 -06:00
|
|
|
|
|
|
|
func TestAddpathADO(t *testing.T) {
|
2021-01-12 00:39:43 -06:00
|
|
|
a := assert.New(t)
|
2020-02-24 14:48:12 -06:00
|
|
|
ctx := context.Background()
|
|
|
|
rc := new(RunContext)
|
|
|
|
handler := rc.commandHandler(ctx)
|
|
|
|
|
|
|
|
handler("##[add-path]/zoo\n")
|
2021-01-12 00:39:43 -06:00
|
|
|
a.Equal("/zoo", rc.ExtraPath[0])
|
2020-02-24 14:48:12 -06:00
|
|
|
|
|
|
|
handler("##[add-path]/boo\n")
|
2021-01-12 00:39:43 -06:00
|
|
|
a.Equal("/boo", rc.ExtraPath[1])
|
2020-02-24 14:48:12 -06:00
|
|
|
}
|
2021-05-15 16:11:16 -05: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)
|
|
|
|
}
|