Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jacobsa-fuse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
jacobsa-fuse
Commits
b5e00243
Commit
b5e00243
authored
Mar 24, 2015
by
Aaron Jacobs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow re-using the mount_sample binary across runs.
parent
6729af85
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
37 deletions
+51
-37
samples/subprocess.go
samples/subprocess.go
+51
-37
No files found.
samples/subprocess.go
View file @
b5e00243
...
...
@@ -16,6 +16,7 @@ package samples
import
(
"bytes"
"flag"
"fmt"
"io"
"io/ioutil"
...
...
@@ -29,6 +30,11 @@ import (
"golang.org/x/net/context"
)
var
fToolPath
=
flag
.
String
(
"mount_sample"
,
""
,
"Path to the mount_sample tool. If unset, we will compile it."
)
// A struct that implements common behavior needed by tests in the samples/
// directory where the file system is mounted by a subprocess. Use it as an
// embedded field in your test fixture, calling its SetUp method from your
...
...
@@ -68,50 +74,58 @@ func (t *SubprocessTest) SetUp(ti *ogletest.TestInfo) {
}
}
// Set by buildMountSample.
var
mountSamplePath
string
var
mountSampleErr
error
var
mountSampleOnce
sync
.
Once
// Private state for getToolPath.
var
getToolPath_Path
string
var
getToolPath_Err
error
var
getToolPath_Once
sync
.
Once
// Implementation detail of getToolPath.
func
getToolPathImpl
()
(
toolPath
string
,
err
error
)
{
// Fast path: has the user set the flag?
if
*
fToolPath
!=
""
{
toolPath
=
*
fToolPath
return
}
// Build the mount_sample tool if it has not yet been built for this process.
// Return a path to the binary.
func
buildMountSample
()
(
toolPath
string
,
err
error
)
{
// Build if we haven't yet.
mountSampleOnce
.
Do
(
func
()
{
// Create a temporary directory.
tempDir
,
err
:=
ioutil
.
TempDir
(
""
,
""
)
if
err
!=
nil
{
mountSampleE
rr
=
fmt
.
Errorf
(
"TempDir: %v"
,
err
)
e
rr
=
fmt
.
Errorf
(
"TempDir: %v"
,
err
)
return
}
mountSample
Path
=
path
.
Join
(
tempDir
,
"mount_sample"
)
tool
Path
=
path
.
Join
(
tempDir
,
"mount_sample"
)
// Build the command.
cmd
:=
exec
.
Command
(
"go"
,
"build"
,
"-o"
,
mountSample
Path
,
tool
Path
,
"github.com/jacobsa/fuse/samples/mount_sample"
)
output
,
err
:=
cmd
.
CombinedOutput
()
if
err
!=
nil
{
mountSampleE
rr
=
fmt
.
Errorf
(
e
rr
=
fmt
.
Errorf
(
"mount_sample exited with %v, output:
\n
%s"
,
err
,
string
(
output
))
return
}
})
if
mountSampleErr
!=
nil
{
err
=
mountSampleErr
return
}
}
// Build the mount_sample tool if it has not yet been built for this process.
// Return a path to the binary.
func
getToolPath
()
(
toolPath
string
,
err
error
)
{
// Build if we haven't yet.
getToolPath_Once
.
Do
(
func
()
{
getToolPath_Path
,
getToolPath_Err
=
getToolPathImpl
()
})
toolPath
=
mountSamplePath
toolPath
,
err
=
getToolPath_Path
,
getToolPath_Err
return
}
...
...
@@ -167,9 +181,9 @@ func (t *SubprocessTest) initialize() (err error) {
}
// Build the mount_sample tool.
toolPath
,
err
:=
buildMountSample
()
toolPath
,
err
:=
getToolPath
()
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"
buildMountSample
: %v"
,
err
)
err
=
fmt
.
Errorf
(
"
getToolPath
: %v"
,
err
)
return
}
...
...
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