src: add integration test for remote modes (#484)

This commit is contained in:
Luke Kingland 2021-08-20 03:47:05 +09:00 committed by GitHub
parent ab4ad30e8d
commit 2eae672a67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 0 deletions

View File

@ -146,6 +146,56 @@ func TestRemove(t *testing.T) {
}
}
// TestRemoteRepositories ensures that initializing a Function
// defined in a remote repository finds the template, writes
// the expected files, and retains the expected modes.
// NOTE: this test only succeeds due to an override in
// templates' copyNode which forces mode 755 for directories.
// See https://github.com/go-git/go-git/issues/364
func TestRemoteRepositories(t *testing.T) {
defer within(t, "testdata/example.com/remote")()
// Write the test template from the remote onto root
client := fn.New(
fn.WithRegistry(DefaultRegistry),
fn.WithRepository("https://github.com/boson-project/test-templates"),
)
err := client.Create(fn.Function{
Root: ".",
Runtime: "runtime",
Template: "template",
})
if err != nil {
t.Fatal(err)
}
tests := []struct {
Path string
Perm uint32
Dir bool
}{
{Path: "file", Perm: 0644},
{Path: "dir-a/file", Perm: 0644},
{Path: "dir-b/file", Perm: 0644},
{Path: "dir-b/executable", Perm: 0755},
{Path: "dir-b", Perm: 0755},
{Path: "dir-a", Perm: 0755},
}
// Note that .Perm() are used to only consider the least-signifigant 9 and
// thus not have to consider the directory bit.
for _, test := range tests {
file, err := os.Stat(test.Path)
if err != nil {
t.Fatal(err)
}
t.Logf("%04o repository/%v", file.Mode().Perm(), test.Path)
if file.Mode().Perm() != os.FileMode(test.Perm) {
t.Fatalf("expected 'repository/%v' to have mode %04o, got %04o", test.Path, test.Perm, file.Mode().Perm())
}
}
}
// ***********
// Helpers
// ***********

View File

@ -197,6 +197,8 @@ func copyNode(src, dest string, accessor filesystem) (err error) {
// Ideally we should use the file mode of the src node
// but it seems the git module is reporting directories
// as 0644 instead of 0755. For now, just do it this way.
// See https://github.com/go-git/go-git/issues/364
// Upon resolution, return accessor.Stat(src).Mode()
err = os.MkdirAll(dest, 0755)
if err != nil {
return