Skip to content

Commit

Permalink
Add tests, set permission default constants
Browse files Browse the repository at this point in the history
  • Loading branch information
surminus committed Aug 14, 2023
1 parent b48ed4a commit aacbd6b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions resources/directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestDirectory(t *testing.T) {
assert.NoError(t, err)

assert.Equal(t, true, viaduct.DirExists(d.Path))
assert.Equal(t, true, viaduct.MatchChmod(d.Path, DefaultDirectoryPermissions))

err = os.RemoveAll(d.Path)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions resources/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestFile(t *testing.T) {
assert.NoError(t, err)

assert.Equal(t, true, viaduct.FileExists(f.Path))
assert.Equal(t, true, viaduct.MatchChmod(f.Path, DefaultFilePermissions))
assert.Equal(t, f.Content, viaduct.FileContents(f.Path))

err = os.Remove(f.Path)
Expand Down
1 change: 1 addition & 0 deletions resources/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestGit(t *testing.T) {
assert.NoError(t, err)

assert.Equal(t, true, viaduct.DirExists(filepath.Join(g.Path, ".git")))
assert.Equal(t, true, viaduct.MatchChmod(g.Path, DefaultDirectoryPermissions))

// Use the same test for cloning and deleting so we don't waste time
// cloning twice
Expand Down
10 changes: 8 additions & 2 deletions resources/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"fmt"
"io/fs"
"os"
"os/user"
"strconv"
Expand Down Expand Up @@ -33,14 +34,19 @@ const (
pfile ptype = "file"
)

const (
DefaultDirectoryPermissions fs.FileMode = os.ModeDir | 0o755
DefaultFilePermissions fs.FileMode = 0o644
)

func (p *permissions) preflightPermissions(t ptype) error {
if p.Mode == 0 {
if t == pdir {
p.Mode = os.ModeDir | 0755
p.Mode = DefaultDirectoryPermissions
}

if t == pfile {
p.Mode = 0o644
p.Mode = DefaultFilePermissions
}
} else {
if t == pdir {
Expand Down

0 comments on commit aacbd6b

Please sign in to comment.