-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Xavier Lucas <[email protected]>
- Loading branch information
Xavier Lucas
committed
Aug 26, 2016
1 parent
14f860a
commit 12f40fe
Showing
45 changed files
with
6,648 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
language: go | ||
|
||
go: | ||
- 1.6.3 | ||
- 1.7 | ||
- tip | ||
|
||
os: | ||
- linux | ||
- osx | ||
|
||
script: | ||
- go install | ||
before_install: | ||
- go get github.com/mattn/goveralls | ||
- go get golang.org/x/tools/cmd/cover | ||
|
||
install: true | ||
|
||
script: | ||
- go install | ||
- go test -v -covermode=count -coverprofile=profile.cov github.com/ovh/svfs/svfs | ||
- $HOME/gopath/bin/goveralls -coverprofile=profile.cov -service=svfs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Running svfs tests | ||
|
||
When contributing to svfs, you'll have to make sure you contribution doesn't break current features. Always make sure unit and integration tests pass. | ||
|
||
|
||
## Unit tests | ||
|
||
#### Authentication | ||
|
||
In order to test features against a remote Swift storage, tests use your environment for authentication : | ||
|
||
- Set `SVFS_TEST_AUTH` to either `HUBIC`, `OPENRC` or `TOKEN`. | ||
- Set relevant variables as described below. | ||
|
||
#### HubiC | ||
|
||
``` | ||
SVFS_TEST_HUBIC_AUTH | ||
SVFS_TEST_HUBIC_TOKEN | ||
``` | ||
|
||
#### OpenRC | ||
|
||
``` | ||
SVFS_TEST_AUTH_URL | ||
SVFS_TEST_USERNAME | ||
SVFS_TEST_PASSWORD | ||
SVFS_TEST_TENANT_NAME | ||
SVFS_TEST_REGION_NAME | ||
``` | ||
|
||
#### Token and storage URL | ||
|
||
``` | ||
SVFS_TEST_AUTH_TOKEN | ||
SVFS_TEST_STORAGE_URL | ||
``` | ||
|
||
#### Execution | ||
|
||
Run `go test -v github.com/ovh/svfs/svfs`. | ||
|
||
|
||
## Integration tests | ||
|
||
#### Prerequisites | ||
|
||
You must have [Rake](http://rake.rubyforge.org/) installed before running tests, you can install it using `gem install rake`. | ||
|
||
Before running integration tests, you have to set 3 environment variables : | ||
|
||
* `TEST_MOUNTPOINT` : the svfs mountpoint. | ||
* `TEST_SEG_SIZE` : segmented file size value (in megabytes). | ||
* `TEST_NSEG_SIZE` : standard file size value (in megabytes). | ||
|
||
A test container will be created automatically. | ||
|
||
|
||
#### Execution | ||
|
||
Use `rake test` command once you have followed previous instructions. | ||
|
||
#### Writing more tests | ||
|
||
At first, you must follow [contribution guidelines](CONTRIBUTING.md) of SVFS and use the latest version of go. | ||
All integration tests are located in the [test directory](test). If you want to add some, you need consider the [Rakefile](Rakefile) and comment your tests like existing ones. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
package svfs | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/stretchr/testify/suite" | ||
"github.com/xlucas/swift" | ||
) | ||
|
||
type ChangeCacheTestSuite struct { | ||
suite.Suite | ||
key string | ||
item *Object | ||
} | ||
|
||
func (suite *ChangeCacheTestSuite) SetupTest() { | ||
// Reset cache | ||
changeCache = NewSimpleCache() | ||
|
||
// Sample data | ||
suite.item = &Object{ | ||
name: "item", | ||
path: "dir/item", | ||
c: &swift.Container{ | ||
Name: "container", | ||
}, | ||
} | ||
suite.key = changeCache.key(suite.item.c.Name, suite.item.path) | ||
} | ||
|
||
func (suite *ChangeCacheTestSuite) TestAdd() { | ||
changeCache.Add(suite.item.c.Name, suite.item.path, suite.item) | ||
|
||
require.NotNil(suite.T(), changeCache.changes[suite.key]) | ||
assert.Equal(suite.T(), changeCache.changes[suite.key], suite.item) | ||
} | ||
|
||
func (suite *ChangeCacheTestSuite) TestExist() { | ||
suite.TestAdd() | ||
|
||
assert.True(suite.T(), changeCache.Exist(suite.item.c.Name, suite.item.path)) | ||
} | ||
|
||
func (suite *ChangeCacheTestSuite) TestGet() { | ||
suite.TestAdd() | ||
|
||
node := changeCache.Get(suite.item.c.Name, suite.item.path) | ||
|
||
require.NotNil(suite.T(), node) | ||
assert.Equal(suite.T(), node, suite.item) | ||
} | ||
|
||
func (suite *ChangeCacheTestSuite) TestRemove() { | ||
suite.TestAdd() | ||
|
||
changeCache.Remove(suite.item.c.Name, suite.item.path) | ||
|
||
assert.Nil(suite.T(), changeCache.changes[suite.key]) | ||
} | ||
|
||
func TestChangeCacheTestSuite(t *testing.T) { | ||
suite.Run(t, new(ChangeCacheTestSuite)) | ||
} | ||
|
||
type CacheTestSuite struct { | ||
suite.Suite | ||
nodes map[string]Node | ||
key string | ||
item1 *Object | ||
item2 *Object | ||
parent *Directory | ||
} | ||
|
||
func (suite *CacheTestSuite) SetupTest() { | ||
// Cache settings | ||
CacheTimeout = 5 * time.Minute | ||
CacheMaxEntries = -1 | ||
CacheMaxAccess = -1 | ||
|
||
// Reset cache | ||
directoryCache = NewCache() | ||
|
||
// Sample data | ||
suite.nodes = make(map[string]Node) | ||
suite.parent = &Directory{ | ||
name: "dir", | ||
path: "dir/", | ||
c: &swift.Container{ | ||
Name: "container", | ||
}, | ||
} | ||
suite.item1 = &Object{name: "item1"} | ||
suite.item2 = &Object{name: "item2"} | ||
suite.key = directoryCache.key(suite.parent.c.Name, suite.parent.path) | ||
suite.nodes[suite.item1.Name()] = suite.item1 | ||
} | ||
|
||
func (suite *CacheTestSuite) TestAddAll() { | ||
directoryCache.AddAll(suite.parent.c.Name, suite.parent.path, suite.parent, suite.nodes) | ||
|
||
assert.Equal(suite.T(), directoryCache.nodeCount, uint64(1)) | ||
assert.Len(suite.T(), directoryCache.content[suite.key].nodes, 1) | ||
} | ||
|
||
func (suite *CacheTestSuite) TestGetAll() { | ||
suite.TestAddAll() | ||
|
||
cachedParent, cachedNodes := directoryCache.GetAll(suite.parent.c.Name, suite.parent.path) | ||
|
||
assert.Len(suite.T(), cachedNodes, 1) | ||
assert.IsType(suite.T(), &Object{}, cachedNodes[suite.item1.Name()]) | ||
assert.IsType(suite.T(), &Directory{}, cachedParent) | ||
} | ||
|
||
func (suite *CacheTestSuite) TestDeleteAll() { | ||
suite.TestAddAll() | ||
|
||
directoryCache.DeleteAll(suite.parent.c.Name, suite.parent.path) | ||
|
||
assert.Nil(suite.T(), directoryCache.content[suite.key]) | ||
assert.Len(suite.T(), directoryCache.content, 0) | ||
assert.Equal(suite.T(), directoryCache.nodeCount, uint64(0)) | ||
} | ||
|
||
func (suite *CacheTestSuite) TestDelete() { | ||
suite.TestSet() | ||
|
||
var ( | ||
entries = directoryCache.content[suite.key].nodes | ||
nodeCount = len(entries) | ||
) | ||
|
||
for _, node := range []Node{suite.item1, suite.item2} { | ||
nodeCount-- | ||
directoryCache.Delete(suite.parent.c.Name, suite.parent.path, node.Name()) | ||
assert.Nil(suite.T(), entries[node.Name()]) | ||
assert.Len(suite.T(), entries, nodeCount) | ||
} | ||
} | ||
|
||
func (suite *CacheTestSuite) TestGet() { | ||
suite.TestSet() | ||
|
||
for _, node := range []Node{suite.item1, suite.item2} { | ||
cached := directoryCache.Get(suite.parent.c.Name, suite.parent.path, node.Name()) | ||
require.NotNil(suite.T(), cached) | ||
assert.Equal(suite.T(), cached, node) | ||
} | ||
} | ||
|
||
func (suite *CacheTestSuite) TestPeek() { | ||
suite.TestAddAll() | ||
|
||
parent, found := directoryCache.Peek(suite.parent.c.Name, suite.parent.path) | ||
|
||
assert.True(suite.T(), found) | ||
require.NotNil(suite.T(), parent) | ||
assert.Equal(suite.T(), parent, suite.parent) | ||
} | ||
|
||
func (suite *CacheTestSuite) TestSet() { | ||
suite.TestAddAll() | ||
|
||
directoryCache.Set(suite.parent.c.Name, suite.parent.path, suite.item2.name, suite.item2) | ||
|
||
require.NotNil(suite.T(), directoryCache.content[suite.key]) | ||
assert.NotNil(suite.T(), directoryCache.content[suite.key].nodes[suite.item2.name]) | ||
} | ||
|
||
func TestCacheTestSuite(t *testing.T) { | ||
suite.Run(t, new(CacheTestSuite)) | ||
} |
Oops, something went wrong.