package cmd import ( "context" "path" "path/filepath" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) 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{}) require.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{}) require.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"}) require.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"}) require.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") require.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{}) require.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"}) require.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"}) require.NoError(t, err) }