Skip to content

Commit d77d4ba

Browse files
committed
Add ignore socket test
Signed-off-by: Derek McGowan <[email protected]>
1 parent 6f0d280 commit d77d4ba

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

archive/tar_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,22 @@ func TestDiffTar(t *testing.T) {
10061006
fstest.CreateDir("/d3/", 0755),
10071007
),
10081008
},
1009+
{
1010+
name: "IgnoreSockets",
1011+
validators: []tarEntryValidator{
1012+
fileEntry("f2", []byte("content"), 0644),
1013+
// There should be _no_ socket here, despite the fstest.CreateSocket below
1014+
fileEntry("f3", []byte("content"), 0644),
1015+
},
1016+
a: fstest.Apply(
1017+
fstest.CreateFile("/f1", []byte("content"), 0644),
1018+
),
1019+
b: fstest.Apply(
1020+
fstest.CreateFile("/f2", []byte("content"), 0644),
1021+
fstest.CreateSocket("/s0", 0644),
1022+
fstest.CreateFile("/f3", []byte("content"), 0644),
1023+
),
1024+
},
10091025
}
10101026

10111027
for _, at := range tests {

fs/fstest/file.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package fstest
22

33
import (
44
"io/ioutil"
5+
"net"
56
"os"
67
"path/filepath"
78
"time"
@@ -107,6 +108,19 @@ func Link(oldname, newname string) Applier {
107108
// }
108109
//}
109110

111+
// CreateSocket returns a file applier which creates a unix socket
112+
func CreateSocket(name string, perm os.FileMode) Applier {
113+
return applyFn(func(root string) error {
114+
fullPath := filepath.Join(root, name)
115+
ln, err := net.Listen("unix", fullPath)
116+
if err != nil {
117+
return err
118+
}
119+
defer ln.Close()
120+
return os.Chmod(fullPath, perm)
121+
})
122+
}
123+
110124
// Apply returns a new applier from the given appliers
111125
func Apply(appliers ...Applier) Applier {
112126
return applyFn(func(root string) error {

fs/fstest/testsuite.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ var (
7474
Symlink("libnothing.so", "/usr/local/lib/libnothing.so.2"),
7575
CreateDir("/home", 0755),
7676
CreateDir("/home/derek", 0700),
77+
CreateDir("/var/run/socket", 0700),
7778
)
7879

7980
// basicTest covers basic operations

0 commit comments

Comments
 (0)