mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-03-02 18:00:18 +00:00
Doing `act --local-repository test/self-ref@main=/folder-path/self-ref` caused a null pointer exception while fetching a non mapped entry, due to missing remote fallback. Reviewed-on: https://gitea.com/actions-oss/act-cli/pulls/29 Co-authored-by: Christopher Homberger <christopher.homberger@web.de> Co-committed-by: Christopher Homberger <christopher.homberger@web.de>
110 lines
3.4 KiB
Go
110 lines
3.4 KiB
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"path"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestReadSecrets(t *testing.T) {
|
|
secrets := map[string]string{}
|
|
ret := readEnvsEx(path.Join("testdata", "secrets.yml"), secrets, true)
|
|
assert.True(t, ret)
|
|
assert.Equal(t, `line1
|
|
line2
|
|
line3
|
|
`, secrets["MYSECRET"])
|
|
}
|
|
|
|
func TestReadEnv(t *testing.T) {
|
|
secrets := map[string]string{}
|
|
ret := readEnvs(path.Join("testdata", "secrets.yml"), secrets)
|
|
assert.True(t, ret)
|
|
assert.Equal(t, `line1
|
|
line2
|
|
line3
|
|
`, secrets["mysecret"])
|
|
}
|
|
|
|
func TestListOptions(t *testing.T) {
|
|
rootCmd := createRootCommand(context.Background(), &Input{}, "")
|
|
err := newRunCommand(context.Background(), &Input{
|
|
listOptions: true,
|
|
})(rootCmd, []string{})
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestRun(t *testing.T) {
|
|
rootCmd := createRootCommand(context.Background(), &Input{}, "")
|
|
err := newRunCommand(context.Background(), &Input{
|
|
platforms: []string{"ubuntu-latest=node:16-buster-slim"},
|
|
workdir: "../pkg/runner/testdata/",
|
|
workflowsPath: "./basic/push.yml",
|
|
})(rootCmd, []string{})
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestRunPush(t *testing.T) {
|
|
rootCmd := createRootCommand(context.Background(), &Input{}, "")
|
|
err := newRunCommand(context.Background(), &Input{
|
|
platforms: []string{"ubuntu-latest=node:16-buster-slim"},
|
|
workdir: "../pkg/runner/testdata/",
|
|
workflowsPath: "./basic/push.yml",
|
|
})(rootCmd, []string{"push"})
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestRunPushJsonLogger(t *testing.T) {
|
|
rootCmd := createRootCommand(context.Background(), &Input{}, "")
|
|
err := newRunCommand(context.Background(), &Input{
|
|
platforms: []string{"ubuntu-latest=node:16-buster-slim"},
|
|
workdir: "../pkg/runner/testdata/",
|
|
workflowsPath: "./basic/push.yml",
|
|
jsonLogger: true,
|
|
})(rootCmd, []string{"push"})
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestFlags(t *testing.T) {
|
|
for _, f := range []string{"graph", "list", "bug-report", "man-page"} {
|
|
t.Run("TestFlag-"+f, func(t *testing.T) {
|
|
rootCmd := createRootCommand(context.Background(), &Input{}, "")
|
|
err := rootCmd.Flags().Set(f, "true")
|
|
assert.NoError(t, err)
|
|
err = newRunCommand(context.Background(), &Input{
|
|
platforms: []string{"ubuntu-latest=node:16-buster-slim"},
|
|
workdir: "../pkg/runner/testdata/",
|
|
workflowsPath: "./basic/push.yml",
|
|
})(rootCmd, []string{})
|
|
assert.NoError(t, err)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestWorkflowCall(t *testing.T) {
|
|
rootCmd := createRootCommand(context.Background(), &Input{}, "")
|
|
err := newRunCommand(context.Background(), &Input{
|
|
platforms: []string{"ubuntu-latest=node:16-buster-slim"},
|
|
workdir: "../pkg/runner/testdata/",
|
|
workflowsPath: "./workflow_call_inputs/workflow_call_inputs.yml",
|
|
inputs: []string{"required=required input", "boolean=true"},
|
|
})(rootCmd, []string{"workflow_call"})
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestLocalRepositories(t *testing.T) {
|
|
wd, _ := filepath.Abs("../pkg/runner/testdata/")
|
|
rootCmd := createRootCommand(context.Background(), &Input{}, "")
|
|
err := newRunCommand(context.Background(), &Input{
|
|
githubInstance: "github.com",
|
|
platforms: []string{"ubuntu-latest=node:16-buster-slim"},
|
|
workdir: wd,
|
|
workflowsPath: "./remote-action-composite-action-ref-partial-override/push.yml",
|
|
localRepository: []string{"needs/override@main=" + wd + "/actions-environment-and-context-tests"},
|
|
})(rootCmd, []string{"push"})
|
|
assert.NoError(t, err)
|
|
}
|