Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
3437d8b8
Commit
3437d8b8
authored
Mar 28, 2018
by
Hemant Kumar
Committed by
Di Xu
Apr 11, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use relative path for creating socket files
parent
1db33917
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
15 deletions
+36
-15
mount_linux_test.go
pkg/util/mount/mount_linux_test.go
+36
-15
No files found.
pkg/util/mount/mount_linux_test.go
View file @
3437d8b8
...
@@ -1183,7 +1183,7 @@ func TestBindSubPath(t *testing.T) {
...
@@ -1183,7 +1183,7 @@ func TestBindSubPath(t *testing.T) {
expectError
:
false
,
expectError
:
false
,
},
},
{
{
name
:
"
subpath-mounting
-unix-socket"
,
name
:
"
mount
-unix-socket"
,
prepare
:
func
(
base
string
)
([]
string
,
string
,
string
,
error
)
{
prepare
:
func
(
base
string
)
([]
string
,
string
,
string
,
error
)
{
volpath
,
subpathMount
:=
getTestPaths
(
base
)
volpath
,
subpathMount
:=
getTestPaths
(
base
)
mounts
:=
[]
string
{
subpathMount
}
mounts
:=
[]
string
{
subpathMount
}
...
@@ -1195,9 +1195,9 @@ func TestBindSubPath(t *testing.T) {
...
@@ -1195,9 +1195,9 @@ func TestBindSubPath(t *testing.T) {
return
nil
,
""
,
""
,
err
return
nil
,
""
,
""
,
err
}
}
testSocketFile
:=
filepath
.
Join
(
volpath
,
"mount_test.sock"
)
socketFile
,
socketCreateError
:=
createSocketFile
(
volpath
)
_
,
err
:=
net
.
Listen
(
"unix"
,
testSocketFile
)
return
mounts
,
volpath
,
testSocketFile
,
er
r
return
mounts
,
volpath
,
socketFile
,
socketCreateErro
r
},
},
expectError
:
false
,
expectError
:
false
,
},
},
...
@@ -1228,6 +1228,7 @@ func TestBindSubPath(t *testing.T) {
...
@@ -1228,6 +1228,7 @@ func TestBindSubPath(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
err
.
Error
())
t
.
Fatalf
(
err
.
Error
())
}
}
mounts
,
volPath
,
subPath
,
err
:=
test
.
prepare
(
base
)
mounts
,
volPath
,
subPath
,
err
:=
test
.
prepare
(
base
)
if
err
!=
nil
{
if
err
!=
nil
{
os
.
RemoveAll
(
base
)
os
.
RemoveAll
(
base
)
...
@@ -1478,29 +1479,29 @@ func TestSafeOpen(t *testing.T) {
...
@@ -1478,29 +1479,29 @@ func TestSafeOpen(t *testing.T) {
true
,
true
,
},
},
{
{
"mount
ing
-unix-socket"
,
"mount-unix-socket"
,
func
(
base
string
)
error
{
func
(
base
string
)
error
{
testSocketFile
:=
filepath
.
Join
(
base
,
"mount_test.sock"
)
socketFile
,
socketError
:=
createSocketFile
(
base
)
_
,
err
:=
net
.
Listen
(
"unix"
,
testSocketFile
)
if
er
r
!=
nil
{
if
socketErro
r
!=
nil
{
return
fmt
.
Errorf
(
"Error preparing socket file %s with %v"
,
testSocketFile
,
er
r
)
return
fmt
.
Errorf
(
"Error preparing socket file %s with %v"
,
socketFile
,
socketErro
r
)
}
}
return
nil
return
nil
},
},
"m
ount_tes
t.sock"
,
"mt.sock"
,
false
,
false
,
},
},
{
{
"mounting-unix-socket-in-middle"
,
"mounting-unix-socket-in-middle"
,
func
(
base
string
)
error
{
func
(
base
string
)
error
{
testSocketFile
:=
filepath
.
Join
(
base
,
"mount_test.sock"
)
testSocketFile
,
socketError
:=
createSocketFile
(
base
)
_
,
err
:=
net
.
Listen
(
"unix"
,
testSocketFile
)
if
er
r
!=
nil
{
if
socketErro
r
!=
nil
{
return
fmt
.
Errorf
(
"Error preparing socket file %s with %v"
,
testSocketFile
,
er
r
)
return
fmt
.
Errorf
(
"Error preparing socket file %s with %v"
,
testSocketFile
,
socketErro
r
)
}
}
return
nil
return
nil
},
},
"m
ount_tes
t.sock/bar"
,
"mt.sock/bar"
,
true
,
true
,
},
},
}
}
...
@@ -1511,6 +1512,7 @@ func TestSafeOpen(t *testing.T) {
...
@@ -1511,6 +1512,7 @@ func TestSafeOpen(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
err
.
Error
())
t
.
Fatalf
(
err
.
Error
())
}
}
test
.
prepare
(
base
)
test
.
prepare
(
base
)
pathToCreate
:=
filepath
.
Join
(
base
,
test
.
path
)
pathToCreate
:=
filepath
.
Join
(
base
,
test
.
path
)
fd
,
err
:=
doSafeOpen
(
pathToCreate
,
base
)
fd
,
err
:=
doSafeOpen
(
pathToCreate
,
base
)
...
@@ -1529,6 +1531,25 @@ func TestSafeOpen(t *testing.T) {
...
@@ -1529,6 +1531,25 @@ func TestSafeOpen(t *testing.T) {
}
}
}
}
func
createSocketFile
(
socketDir
string
)
(
string
,
error
)
{
testSocketFile
:=
filepath
.
Join
(
socketDir
,
"mt.sock"
)
// Switch to volume path and create the socket file
// socket file can not have length of more than 108 character
// and hence we must use relative path
oldDir
,
_
:=
os
.
Getwd
()
err
:=
os
.
Chdir
(
socketDir
)
if
err
!=
nil
{
return
""
,
err
}
defer
func
()
{
os
.
Chdir
(
oldDir
)
}()
_
,
socketCreateError
:=
net
.
Listen
(
"unix"
,
"mt.sock"
)
return
testSocketFile
,
socketCreateError
}
func
TestFindExistingPrefix
(
t
*
testing
.
T
)
{
func
TestFindExistingPrefix
(
t
*
testing
.
T
)
{
defaultPerm
:=
os
.
FileMode
(
0750
)
defaultPerm
:=
os
.
FileMode
(
0750
)
tests
:=
[]
struct
{
tests
:=
[]
struct
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment