forked from paketo-buildpacks/dotnet-core-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymlinker_test.go
100 lines (83 loc) · 3.17 KB
/
symlinker_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package dotnetcoreruntime_test
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
dotnetcoreruntime "github.com/paketo-buildpacks/dotnet-core-runtime"
"github.com/sclevine/spec"
. "github.com/onsi/gomega"
)
func testSymlinker(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
symlinker dotnetcoreruntime.Symlinker
workingDir string
layerPath string
)
it.Before(func() {
var err error
workingDir, err = ioutil.TempDir("", "working-dir")
Expect(err).NotTo(HaveOccurred())
layerPath, err = ioutil.TempDir("", "layer-path")
Expect(err).NotTo(HaveOccurred())
symlinker = dotnetcoreruntime.NewSymlinker()
})
it.After(func() {
Expect(os.RemoveAll(workingDir)).To(Succeed())
Expect(os.RemoveAll(layerPath)).To(Succeed())
})
context("Link", func() {
it("creates a .dotnet_root dir in workspace with symlink to layerpath", func() {
err := symlinker.Link(workingDir, layerPath)
Expect(err).NotTo(HaveOccurred())
Expect(filepath.Join(workingDir, ".dotnet_root", "shared")).To(BeADirectory())
fi, err := os.Lstat(filepath.Join(workingDir, ".dotnet_root", "shared", "Microsoft.NETCore.App"))
Expect(err).NotTo(HaveOccurred())
Expect(fi.Mode() & os.ModeSymlink).ToNot(BeZero())
fi, err = os.Lstat(filepath.Join(workingDir, ".dotnet_root", "host"))
Expect(err).NotTo(HaveOccurred())
Expect(fi.Mode() & os.ModeSymlink).ToNot(BeZero())
link, err := os.Readlink(filepath.Join(workingDir, ".dotnet_root", "shared", "Microsoft.NETCore.App"))
Expect(err).NotTo(HaveOccurred())
Expect(link).To(Equal(filepath.Join(layerPath, "shared", "Microsoft.NETCore.App")))
link, err = os.Readlink(filepath.Join(workingDir, ".dotnet_root", "host"))
Expect(err).NotTo(HaveOccurred())
Expect(link).To(Equal(filepath.Join(layerPath, "host")))
})
context("error cases", func() {
context("when the '.dotnet_root/shared' dir can not be created", func() {
it.Before(func() {
Expect(os.Chmod(filepath.Join(workingDir), 0000)).To(Succeed())
})
it("errors", func() {
err := symlinker.Link(workingDir, layerPath)
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(ContainSubstring("permission denied")))
})
})
context("when the shared directory symlink can not be created", func() {
it.Before(func() {
Expect(os.MkdirAll(filepath.Join(workingDir, ".dotnet_root", "shared"), os.ModePerm)).To(Succeed())
Expect(os.Chmod(filepath.Join(workingDir, ".dotnet_root", "shared"), 0000)).To(Succeed())
})
it("errors", func() {
err := symlinker.Link(workingDir, layerPath)
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(ContainSubstring("permission denied")))
})
})
context("when the host directory symlink can not be created", func() {
it.Before(func() {
Expect(os.MkdirAll(filepath.Join(workingDir, ".dotnet_root"), os.ModePerm)).To(Succeed())
Expect(os.Chmod(filepath.Join(workingDir, ".dotnet_root"), 0000)).To(Succeed())
})
it("errors", func() {
err := symlinker.Link(workingDir, layerPath)
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(ContainSubstring("permission denied")))
})
})
})
})
}