2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-08 13:53:27 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package testsuite
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2018-11-29 18:39:27 +00:00
|
|
|
|
2018-11-08 13:53:27 +00:00
|
|
|
"storj.io/storj/storage"
|
|
|
|
)
|
|
|
|
|
|
|
|
// RunQueueTests runs common storage.Queue tests
|
|
|
|
func RunQueueTests(t *testing.T, q storage.Queue) {
|
|
|
|
t.Run("basic", func(t *testing.T) { testBasic(t, q) })
|
|
|
|
}
|
|
|
|
|
|
|
|
func testBasic(t *testing.T, q storage.Queue) {
|
|
|
|
err := q.Enqueue(storage.Value("hello world"))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = q.Enqueue(storage.Value("Привіт, світе"))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = q.Enqueue(storage.Value([]byte{0, 0, 0, 0, 255, 255, 255, 255}))
|
|
|
|
assert.NoError(t, err)
|
2018-11-16 13:31:33 +00:00
|
|
|
list, err := q.Peekqueue(100)
|
|
|
|
assert.NotNil(t, list)
|
|
|
|
assert.NoError(t, err)
|
2018-11-08 13:53:27 +00:00
|
|
|
out, err := q.Dequeue()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, out, storage.Value("hello world"))
|
|
|
|
out, err = q.Dequeue()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, out, storage.Value("Привіт, світе"))
|
|
|
|
out, err = q.Dequeue()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, out, storage.Value([]byte{0, 0, 0, 0, 255, 255, 255, 255}))
|
|
|
|
out, err = q.Dequeue()
|
|
|
|
assert.Nil(t, out)
|
|
|
|
assert.Error(t, err)
|
|
|
|
}
|