diff --git a/cmd/bindown/cli_test.go b/cmd/bindown/cli_test.go index 5f4ed84..0488dc4 100644 --- a/cmd/bindown/cli_test.go +++ b/cmd/bindown/cli_test.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "os/exec" "path/filepath" "runtime" "strings" @@ -478,3 +479,32 @@ url_checksums: require.NoFileExists(t, filepath.Join(runner.tmpDir, "bin", "foo")) }) } + +func Test_wrapCmd(t *testing.T) { + t.Run("bindown path", func(t *testing.T) { + runner := newCmdRunner(t) + servePath := testdataPath("downloadables/runnable.tar.gz") + ts := testutil.ServeFile(t, servePath, "/runnable/runnable.tar.gz", "") + depURL := ts.URL + "/runnable/runnable.tar.gz" + runner.writeConfigYaml(fmt.Sprintf(` +dependencies: + runnable: + archive_path: bin/runnable.sh + url: %s +url_checksums: + %s: fb2fe41a34b77ee180def0cb9a222d8776a6e581106009b64f35983da291ab6e +`, depURL, depURL)) + outputDir := filepath.Join(runner.tmpDir, "output") + runnable := filepath.Join(outputDir, "runnable") + result := runner.run("wrap", "runnable", "--bindown", testutil.BindownBin(), "--output", runnable) + result.assertState(resultState{stdout: runnable}) + testutil.AssertFile(t, runnable, true, false) + testutil.CheckGoldenDir(t, outputDir, filepath.FromSlash("testdata/golden/wrap/bindown-path")) + + // make sure it runs + cmd := exec.Command("sh", "-c", filepath.ToSlash(runnable)) + out, err := cmd.Output() + require.NoError(t, err) + require.Equal(t, "Hello world", strings.TrimSpace(string(out))) + }) +} diff --git a/cmd/bindown/testdata/golden/wrap/bindown-path/runnable b/cmd/bindown/testdata/golden/wrap/bindown-path/runnable new file mode 100644 index 0000000..1fbacc4 --- /dev/null +++ b/cmd/bindown/testdata/golden/wrap/bindown-path/runnable @@ -0,0 +1,15 @@ +#!/bin/sh +# Code generated by bindown. DO NOT EDIT. + +set -e + +bindown_bin="$( + CDPATH="" cd -- "$(dirname -- "$0")" + + "../../../../../../../../../Users/wroden/repos/WillAbides/bindown/tmp/_test/bindown" install "runnable" \ + --to-cache \ + --configfile "../.bindown.yaml" \ + --cache "../cache" +)" + +exec "$bindown_bin" "$@"