aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/testutil
diff options
context:
space:
mode:
Diffstat (limited to 'swarm/testutil')
-rw-r--r--swarm/testutil/http.go45
1 files changed, 15 insertions, 30 deletions
diff --git a/swarm/testutil/http.go b/swarm/testutil/http.go
index 074823032..2309c39f0 100644
--- a/swarm/testutil/http.go
+++ b/swarm/testutil/http.go
@@ -32,19 +32,6 @@ type TestServer interface {
ServeHTTP(http.ResponseWriter, *http.Request)
}
-// simulated timeProvider
-type fakeTimeProvider struct {
- currentTime uint64
-}
-
-func (f *fakeTimeProvider) Tick() {
- f.currentTime++
-}
-
-func (f *fakeTimeProvider) Now() mru.Timestamp {
- return mru.Timestamp{Time: f.currentTime}
-}
-
func NewTestSwarmServer(t *testing.T, serverFunc func(*api.API) TestServer, resolver api.Resolver) *TestSwarmServer {
dir, err := ioutil.TempDir("", "swarm-storage-test")
if err != nil {
@@ -67,10 +54,6 @@ func NewTestSwarmServer(t *testing.T, serverFunc func(*api.API) TestServer, reso
t.Fatal(err)
}
- fakeTimeProvider := &fakeTimeProvider{
- currentTime: 42,
- }
- mru.TimestampProvider = fakeTimeProvider
rhparams := &mru.HandlerParams{}
rh, err := mru.NewTestHandler(resourceDir, rhparams)
if err != nil {
@@ -79,34 +62,36 @@ func NewTestSwarmServer(t *testing.T, serverFunc func(*api.API) TestServer, reso
a := api.NewAPI(fileStore, resolver, rh.Handler, nil)
srv := httptest.NewServer(serverFunc(a))
- return &TestSwarmServer{
- Server: srv,
- FileStore: fileStore,
- dir: dir,
- Hasher: storage.MakeHashFunc(storage.DefaultHash)(),
- timestampProvider: fakeTimeProvider,
+ tss := &TestSwarmServer{
+ Server: srv,
+ FileStore: fileStore,
+ dir: dir,
+ Hasher: storage.MakeHashFunc(storage.DefaultHash)(),
cleanup: func() {
srv.Close()
rh.Close()
os.RemoveAll(dir)
os.RemoveAll(resourceDir)
},
+ CurrentTime: 42,
}
+ mru.TimestampProvider = tss
+ return tss
}
type TestSwarmServer struct {
*httptest.Server
- Hasher storage.SwarmHash
- FileStore *storage.FileStore
- dir string
- cleanup func()
- timestampProvider *fakeTimeProvider
+ Hasher storage.SwarmHash
+ FileStore *storage.FileStore
+ dir string
+ cleanup func()
+ CurrentTime uint64
}
func (t *TestSwarmServer) Close() {
t.cleanup()
}
-func (t *TestSwarmServer) GetCurrentTime() mru.Timestamp {
- return t.timestampProvider.Now()
+func (t *TestSwarmServer) Now() mru.Timestamp {
+ return mru.Timestamp{Time: t.CurrentTime}
}