-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: attempt to fix invalid ~/.airbyte permissions (#61)
- Loading branch information
1 parent
7cb08d9
commit a52f0a6
Showing
5 changed files
with
159 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package local | ||
|
||
import ( | ||
"github.com/airbytehq/abctl/internal/cmd/local/paths" | ||
"github.com/google/go-cmp/cmp" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func TestCheckAirbyteDir(t *testing.T) { | ||
origDir := paths.Airbyte | ||
t.Cleanup(func() { | ||
paths.Airbyte = origDir | ||
}) | ||
|
||
t.Run("no directory", func(t *testing.T) { | ||
paths.Airbyte = filepath.Join(t.TempDir(), "does-not-exist") | ||
if err := checkAirbyteDir(); err != nil { | ||
t.Error("unexpected error", err) | ||
} | ||
}) | ||
|
||
t.Run("directory with correct permissions", func(t *testing.T) { | ||
paths.Airbyte = filepath.Join(t.TempDir(), "correct-perms") | ||
if err := os.MkdirAll(paths.Airbyte, 0744); err != nil { | ||
t.Fatal("unable to create test directory", err) | ||
} | ||
if err := os.Chmod(paths.Airbyte, 0744); err != nil { | ||
t.Fatal("unable to change permissions", err) | ||
} | ||
if err := checkAirbyteDir(); err != nil { | ||
t.Error("unexpected error", err) | ||
} | ||
|
||
// permissions should be unchanged | ||
perms, err := os.Stat(paths.Airbyte) | ||
if err != nil { | ||
t.Fatal("unable to check permissions", err) | ||
} | ||
if d := cmp.Diff(0744, int(perms.Mode().Perm())); d != "" { | ||
t.Errorf("permissions mismatch (-want +got):\n%s", d) | ||
} | ||
}) | ||
|
||
t.Run("directory with higher permissions", func(t *testing.T) { | ||
paths.Airbyte = filepath.Join(t.TempDir(), "correct-perms") | ||
if err := os.MkdirAll(paths.Airbyte, 0777); err != nil { | ||
t.Fatal("unable to create test directory", err) | ||
} | ||
if err := os.Chmod(paths.Airbyte, 0777); err != nil { | ||
t.Fatal("unable to change permissions", err) | ||
} | ||
if err := checkAirbyteDir(); err != nil { | ||
t.Error("unexpected error", err) | ||
} | ||
|
||
// permissions should be unchanged | ||
perms, err := os.Stat(paths.Airbyte) | ||
if err != nil { | ||
t.Fatal("unable to check permissions", err) | ||
} | ||
if d := cmp.Diff(0777, int(perms.Mode().Perm())); d != "" { | ||
t.Errorf("permissions mismatch (-want +got):\n%s", d) | ||
} | ||
}) | ||
|
||
t.Run("directory with incorrect permissions", func(t *testing.T) { | ||
paths.Airbyte = filepath.Join(t.TempDir(), "incorrect-perms") | ||
if err := os.MkdirAll(paths.Airbyte, 0200); err != nil { | ||
t.Fatal("unable to create test directory", err) | ||
} | ||
if err := os.Chmod(paths.Airbyte, 0200); err != nil { | ||
t.Fatal("unable to change permissions", err) | ||
} | ||
// although the permissions are incorrect, checkAirbyteDir should fix them | ||
if err := checkAirbyteDir(); err != nil { | ||
t.Fatal("unexpected error", err) | ||
} | ||
|
||
// permissions should be changed | ||
perms, err := os.Stat(paths.Airbyte) | ||
if err != nil { | ||
t.Fatal("unable to check permissions", err) | ||
} | ||
if d := cmp.Diff(0744, int(perms.Mode().Perm())); d != "" { | ||
t.Errorf("permissions mismatch (-want +got):\n%s", d) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters