github.com/nektos/act@v0.2.83/cmd/root_test.go (about) 1 package cmd 2 3 import ( 4 "context" 5 "path" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestReadSecrets(t *testing.T) { 12 secrets := map[string]string{} 13 ret := readEnvsEx(path.Join("testdata", "secrets.yml"), secrets, true) 14 assert.True(t, ret) 15 assert.Equal(t, `line1 16 line2 17 line3 18 `, secrets["MYSECRET"]) 19 } 20 21 func TestReadEnv(t *testing.T) { 22 secrets := map[string]string{} 23 ret := readEnvs(path.Join("testdata", "secrets.yml"), secrets) 24 assert.True(t, ret) 25 assert.Equal(t, `line1 26 line2 27 line3 28 `, secrets["mysecret"]) 29 } 30 31 func TestListOptions(t *testing.T) { 32 rootCmd := createRootCommand(context.Background(), &Input{}, "") 33 err := newRunCommand(context.Background(), &Input{ 34 listOptions: true, 35 })(rootCmd, []string{}) 36 assert.NoError(t, err) 37 } 38 39 func TestRun(t *testing.T) { 40 rootCmd := createRootCommand(context.Background(), &Input{}, "") 41 err := newRunCommand(context.Background(), &Input{ 42 platforms: []string{"ubuntu-latest=node:16-buster-slim"}, 43 workdir: "../pkg/runner/testdata/", 44 workflowsPath: "./basic/push.yml", 45 })(rootCmd, []string{}) 46 assert.NoError(t, err) 47 } 48 49 func TestRunPush(t *testing.T) { 50 rootCmd := createRootCommand(context.Background(), &Input{}, "") 51 err := newRunCommand(context.Background(), &Input{ 52 platforms: []string{"ubuntu-latest=node:16-buster-slim"}, 53 workdir: "../pkg/runner/testdata/", 54 workflowsPath: "./basic/push.yml", 55 })(rootCmd, []string{"push"}) 56 assert.NoError(t, err) 57 } 58 59 func TestRunPushJsonLogger(t *testing.T) { 60 rootCmd := createRootCommand(context.Background(), &Input{}, "") 61 err := newRunCommand(context.Background(), &Input{ 62 platforms: []string{"ubuntu-latest=node:16-buster-slim"}, 63 workdir: "../pkg/runner/testdata/", 64 workflowsPath: "./basic/push.yml", 65 jsonLogger: true, 66 })(rootCmd, []string{"push"}) 67 assert.NoError(t, err) 68 } 69 70 func TestFlags(t *testing.T) { 71 for _, f := range []string{"graph", "list", "bug-report", "man-page"} { 72 t.Run("TestFlag-"+f, func(t *testing.T) { 73 rootCmd := createRootCommand(context.Background(), &Input{}, "") 74 err := rootCmd.Flags().Set(f, "true") 75 assert.NoError(t, err) 76 err = newRunCommand(context.Background(), &Input{ 77 platforms: []string{"ubuntu-latest=node:16-buster-slim"}, 78 workdir: "../pkg/runner/testdata/", 79 workflowsPath: "./basic/push.yml", 80 })(rootCmd, []string{}) 81 assert.NoError(t, err) 82 }) 83 } 84 } 85 86 func TestReadArgsFile(t *testing.T) { 87 tables := []struct { 88 path string 89 split bool 90 args []string 91 env map[string]string 92 }{ 93 { 94 path: path.Join("testdata", "simple.actrc"), 95 split: true, 96 args: []string{"--container-architecture=linux/amd64", "--action-offline-mode"}, 97 }, 98 { 99 path: path.Join("testdata", "env.actrc"), 100 split: true, 101 env: map[string]string{ 102 "FAKEPWD": "/fake/test/pwd", 103 "FOO": "foo", 104 }, 105 args: []string{ 106 "--artifact-server-path", "/fake/test/pwd/.artifacts", 107 "--env", "FOO=prefix/foo/suffix", 108 }, 109 }, 110 { 111 path: path.Join("testdata", "split.actrc"), 112 split: true, 113 args: []string{"--container-options", "--volume /foo:/bar --volume /baz:/qux --volume /tmp:/tmp"}, 114 }, 115 } 116 for _, table := range tables { 117 t.Run(table.path, func(t *testing.T) { 118 for k, v := range table.env { 119 t.Setenv(k, v) 120 } 121 args := readArgsFile(table.path, table.split) 122 assert.Equal(t, table.args, args) 123 }) 124 } 125 }