diff --git a/cmd/root_test.go b/cmd/root_test.go index ec95385..ab6f5f2 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -82,3 +82,44 @@ func TestFlags(t *testing.T) { }) } } + +func TestReadArgsFile(t *testing.T) { + tables := []struct { + path string + split bool + args []string + env map[string]string + }{ + { + path: path.Join("testdata", "simple.actrc"), + split: true, + args: []string{"--container-architecture=linux/amd64", "--action-offline-mode"}, + }, + { + path: path.Join("testdata", "env.actrc"), + split: true, + env: map[string]string{ + "FAKEPWD": "/fake/test/pwd", + "FOO": "foo", + }, + args: []string{ + "--artifact-server-path", "/fake/test/pwd/.artifacts", + "--env", "FOO=prefix/foo/suffix", + }, + }, + { + path: path.Join("testdata", "split.actrc"), + split: true, + args: []string{"--container-options", "--volume /foo:/bar --volume /baz:/qux --volume /tmp:/tmp"}, + }, + } + for _, table := range tables { + t.Run(table.path, func(t *testing.T) { + for k, v := range table.env { + t.Setenv(k, v) + } + args := readArgsFile(table.path, table.split) + assert.Equal(t, table.args, args) + }) + } +} diff --git a/cmd/testdata/env.actrc b/cmd/testdata/env.actrc new file mode 100644 index 0000000..4c1add2 --- /dev/null +++ b/cmd/testdata/env.actrc @@ -0,0 +1,2 @@ +--artifact-server-path $FAKEPWD/.artifacts +--env FOO=prefix/${FOO}/suffix diff --git a/cmd/testdata/simple.actrc b/cmd/testdata/simple.actrc new file mode 100644 index 0000000..2786bf7 --- /dev/null +++ b/cmd/testdata/simple.actrc @@ -0,0 +1,2 @@ +--container-architecture=linux/amd64 +--action-offline-mode diff --git a/cmd/testdata/split.actrc b/cmd/testdata/split.actrc new file mode 100644 index 0000000..375ee6b --- /dev/null +++ b/cmd/testdata/split.actrc @@ -0,0 +1 @@ +--container-options --volume /foo:/bar --volume /baz:/qux --volume /tmp:/tmp