Use the names SetUp and TearDown so that ogletest doesn't run them.

geesefs-0-30-9
Aaron Jacobs 2015-03-20 11:07:43 +11:00
parent f099d9868f
commit 0b43e99333
2 changed files with 19 additions and 19 deletions

View File

@ -22,7 +22,6 @@ import (
"syscall" "syscall"
"testing" "testing"
"github.com/jacobsa/fuse"
"github.com/jacobsa/fuse/samples" "github.com/jacobsa/fuse/samples"
"github.com/jacobsa/fuse/samples/hellofs" "github.com/jacobsa/fuse/samples/hellofs"
. "github.com/jacobsa/oglematchers" . "github.com/jacobsa/oglematchers"
@ -39,21 +38,14 @@ type HelloFSTest struct {
samples.SampleTest samples.SampleTest
} }
var _ SetUpInterface = &HelloFSTest{}
var _ TearDownInterface = &HelloFSTest{}
func init() { RegisterTestSuite(&HelloFSTest{}) } func init() { RegisterTestSuite(&HelloFSTest{}) }
func (t *HelloFSTest) SetUp(ti *TestInfo) { func (t *HelloFSTest) SetUp(ti *TestInfo) {
fs := &hellofs.HelloFS{ t.FileSystem = &hellofs.HelloFS{
Clock: &t.Clock, Clock: &t.Clock,
} }
t.SampleTest.Initialize(fs, &fuse.MountConfig{}) t.SampleTest.SetUp(ti)
}
func (t *HelloFSTest) TearDown() {
t.SampleTest.Destroy()
} }
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////

View File

@ -23,14 +23,20 @@ import (
"github.com/googlecloudplatform/gcsfuse/timeutil" "github.com/googlecloudplatform/gcsfuse/timeutil"
"github.com/jacobsa/fuse" "github.com/jacobsa/fuse"
"github.com/jacobsa/ogletest"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
// A struct that implements common behavior needed by tests in the samples/ // A struct that implements common behavior needed by tests in the samples/
// directory. Use it as an anonymous member of your test fixture, calling its // directory. Use it as an embedded field in your test fixture, calling its
// Initialize method from your SetUp method and its Destroy method from your // SetUp method from your SetUp method after setting the FileSystem field.
// TearDown method.
type SampleTest struct { type SampleTest struct {
// The file system under test and the configuration with which it should be
// mounted. These must be set by the user of this type before calling SetUp;
// all the other fields below are set by SetUp itself.
FileSystem fuse.FileSystem
MountConfig fuse.MountConfig
// A context object that can be used for long-running operations. // A context object that can be used for long-running operations.
Ctx context.Context Ctx context.Context
@ -44,10 +50,12 @@ type SampleTest struct {
mfs *fuse.MountedFileSystem mfs *fuse.MountedFileSystem
} }
// Mount the supplied file system and initialize the exported fields of the // Mount the supplied file system and initialize the other exported fields of
// struct. Panics on error. // the struct. Panics on error.
func (t *SampleTest) Initialize(fs fuse.FileSystem, config *fuse.MountConfig) { //
err := t.initialize(fs, config) // REQUIRES: t.FileSystem has been set.
func (t *SampleTest) SetUp(ti *ogletest.TestInfo) {
err := t.initialize(t.FileSystem, &t.MountConfig)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -88,14 +96,14 @@ func (t *SampleTest) initialize(
} }
// Unmount the file system and clean up. Panics on error. // Unmount the file system and clean up. Panics on error.
func (t *SampleTest) Destroy() { func (t *SampleTest) TearDown() {
err := t.destroy() err := t.destroy()
if err != nil { if err != nil {
panic(err) panic(err)
} }
} }
// Like Destroy, but doesn't panic. // Like TearDown, but doesn't panic.
func (t *SampleTest) destroy() (err error) { func (t *SampleTest) destroy() (err error) {
// Was the file system mounted? // Was the file system mounted?
if t.mfs == nil { if t.mfs == nil {