forked from gomods/athens
/
test_suite.go
51 lines (43 loc) · 1.05 KB
/
test_suite.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
package fs
import (
"github.com/gobuffalo/suite"
"github.com/gomods/athens/pkg/storage"
"github.com/spf13/afero"
)
// TestSuite implements storage.TestSuite interface
type TestSuite struct {
*suite.Model
storage storage.Backend
fs afero.Fs
rootDir string
}
// NewTestSuite creates a common test suite
func NewTestSuite(model *suite.Model) (storage.TestSuite, error) {
memFs := afero.NewOsFs()
r, err := afero.TempDir(memFs, "", "athens-fs-storage-tests")
if err != nil {
return nil, err
}
fsStore, err := NewStorage(r, memFs)
if err != nil {
return nil, err
}
return &TestSuite{
Model: model,
fs: memFs,
rootDir: r,
storage: fsStore,
}, nil
}
// Storage retrieves initialized storage backend
func (ts *TestSuite) Storage() storage.Backend {
return ts.storage
}
// StorageHumanReadableName retrieves readable identifier of the storage
func (ts *TestSuite) StorageHumanReadableName() string {
return "FileSystem"
}
// Cleanup tears down test
func (ts *TestSuite) Cleanup() {
ts.Require().NoError(ts.fs.RemoveAll(ts.rootDir))
}