forked from knative/func
-
Notifications
You must be signed in to change notification settings - Fork 0
/
templates_test.go
70 lines (63 loc) · 1.82 KB
/
templates_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package faas
import (
"os"
"path/filepath"
"testing"
)
// TestTemplatesEmbeddedFileMode ensures that files from the embedded templates are
// written with the same mode from whence they came
func TestTemplatesEmbeddedFileMode(t *testing.T) {
var path = "testdata/example.com/www"
err := os.MkdirAll(path, 0744)
if err != nil {
panic(err)
}
defer os.RemoveAll(path)
client := New()
function := Function{Root: path, Runtime: "quarkus", Trigger: "events"}
if err := client.Initialize(function); err != nil {
t.Fatal(err)
}
// The file mode of the embedded mvnw should be -rwxr-xr-x
// See source file at: templates/quarkus/events/mvnw
// Assert mode is preserved
sourceMode := os.FileMode(0755)
dest, err := os.Stat(filepath.Join(path, "mvnw"))
if err != nil {
t.Fatal(err)
}
if dest.Mode() != sourceMode {
t.Fatalf("The dest mode should be %v but was %v", sourceMode, dest.Mode())
}
}
// TestTemplatesExtensibleFileMode ensures that files from a file-system
// derived template is written with mode retained.
func TestTemplatesExtensibleFileMode(t *testing.T) {
var (
path = "testdata/example.com/www"
template = "boson-experimental/http"
templates = "testdata/templates"
)
err := os.MkdirAll(path, 0744)
if err != nil {
panic(err)
}
defer os.RemoveAll(path)
client := New(WithTemplates(templates))
function := Function{Root: path, Runtime: "quarkus", Trigger: template}
if err := client.Initialize(function); err != nil {
t.Fatal(err)
}
// Assert mode is preserved
source, err := os.Stat(filepath.Join("testdata/templates/boson-experimental/quarkus/http/mvnw"))
if err != nil {
t.Fatal(err)
}
dest, err := os.Stat(filepath.Join(path, "mvnw"))
if err != nil {
t.Fatal(err)
}
if dest.Mode() != source.Mode() {
t.Fatalf("The dest mode should be %v but was %v", source.Mode(), dest.Mode())
}
}