Skip to content

Commit

Permalink
Mark files executable
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Moss committed May 13, 2022
1 parent 94550ad commit 23f08ea
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
6 changes: 5 additions & 1 deletion hack/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,14 @@ func (c *installCommand) downloadAndVerify(ctx context.Context, dep *dependency)
if err != nil {
return err
}
dest, err := os.Create(path.Join(c.destDir, dep.Name))
filepath := path.Join(c.destDir, dep.Name)
dest, err := os.Create(filepath)
if err != nil {
return err
}
if err := os.Chmod(filepath, 0777); err != nil {
return err
}
if _, err := io.Copy(dest, file); err != nil {
return err
}
Expand Down
37 changes: 37 additions & 0 deletions hack/dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"fmt"
"io"
"net/http"
"os"
"path"
"testing"
)

Expand Down Expand Up @@ -141,6 +143,41 @@ func TestDependencyUpdate(t *testing.T) {
}
}

func TestDownloadAndVerify(t *testing.T) {
dep := dependency{
Name: "test",
Repo: "benmoss/test-resources",
Version: "v1.0.0",
URLTemplate: "https://github.com/{{.Repo}}/releases/download/{{.Version}}/{{.Name}}-{{.Version}}-{{.OS}}-{{.Arch}}",
Checksums: map[string]map[string]checksum{
"darwin": {
"amd64": "d51945f0bca8e1b54025a8a18ffebf885edd09a8731a8955100a9b0f03dbd4c0",
},
},
}
tmpDir, err := os.MkdirTemp("", "hack-test")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpDir)

install := installCommand{
os: "darwin",
arch: "amd64",
destDir: tmpDir,
}
if err := install.downloadAndVerify(context.Background(), &dep); err != nil {
t.Fatal(err)
}
fileInfo, err := os.Stat(path.Join(tmpDir, dep.Name))
if err != nil {
t.Fatal(err)
}
if fileInfo.Mode().Perm() != 0777 {
t.Fatalf("expected file to be executable, got mode %s", fileInfo.Mode().Perm())
}
}

func stringPtr(str string) *string {
return &str
}

0 comments on commit 23f08ea

Please sign in to comment.