mirror of
https://github.com/gofiber/storage.git
synced 2025-10-05 08:37:10 +08:00
add TestMain for a few storages and update benchmark workflow
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
package azureblob
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/bloberror"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func newStore() *Storage {
|
||||
return New(Config{
|
||||
var testStore *Storage
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
testStore = New(Config{
|
||||
Account: "devstoreaccount1",
|
||||
Container: "test",
|
||||
Endpoint: "http://127.0.0.1:10000/devstoreaccount1",
|
||||
@@ -16,7 +19,13 @@ func newStore() *Storage {
|
||||
Account: "devstoreaccount1",
|
||||
Key: "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==",
|
||||
},
|
||||
Reset: true,
|
||||
})
|
||||
|
||||
code := m.Run()
|
||||
|
||||
_ = testStore.Close()
|
||||
os.Exit(code)
|
||||
}
|
||||
|
||||
func Test_AzureBlob_Get(t *testing.T) {
|
||||
@@ -24,7 +33,6 @@ func Test_AzureBlob_Get(t *testing.T) {
|
||||
key = "john"
|
||||
val = []byte("doe")
|
||||
)
|
||||
testStore := newStore()
|
||||
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
@@ -40,7 +48,6 @@ func Test_AzureBlob_Set(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore := newStore()
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
@@ -50,7 +57,6 @@ func Test_AzureBlob_Delete(t *testing.T) {
|
||||
key = "john"
|
||||
val = []byte("doe")
|
||||
)
|
||||
testStore := newStore()
|
||||
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
@@ -73,7 +79,6 @@ func Test_AzureBlob_Override(t *testing.T) {
|
||||
key = "john"
|
||||
val = []byte("doe")
|
||||
)
|
||||
testStore := newStore()
|
||||
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
@@ -83,7 +88,6 @@ func Test_AzureBlob_Override(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_AzureBlob_Get_NotExist(t *testing.T) {
|
||||
testStore := newStore()
|
||||
result, err := testStore.Get("notexist")
|
||||
if err != nil {
|
||||
if bloberror.HasCode(err, bloberror.BlobNotFound) {
|
||||
@@ -96,7 +100,6 @@ func Test_AzureBlob_Get_NotExist(t *testing.T) {
|
||||
|
||||
func Test_AzureBlob_Reset(t *testing.T) {
|
||||
val := []byte("doe")
|
||||
testStore := newStore()
|
||||
|
||||
err := testStore.Set("john1", val, 0)
|
||||
require.NoError(t, err)
|
||||
@@ -127,18 +130,14 @@ func Test_AzureBlob_Reset(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_S3_Conn(t *testing.T) {
|
||||
testStore := newStore()
|
||||
require.True(t, testStore.Conn() != nil)
|
||||
}
|
||||
|
||||
func Test_AzureBlob_Close(t *testing.T) {
|
||||
testStore := newStore()
|
||||
require.Nil(t, testStore.Close())
|
||||
}
|
||||
|
||||
func Benchmark_AzureBlob_Set(b *testing.B) {
|
||||
testStore := newStore()
|
||||
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
|
||||
@@ -151,7 +150,6 @@ func Benchmark_AzureBlob_Set(b *testing.B) {
|
||||
}
|
||||
|
||||
func Benchmark_AzureBlob_Get(b *testing.B) {
|
||||
testStore := newStore()
|
||||
err := testStore.Set("john", []byte("doe"), 0)
|
||||
require.NoError(b, err)
|
||||
|
||||
@@ -166,7 +164,6 @@ func Benchmark_AzureBlob_Get(b *testing.B) {
|
||||
}
|
||||
|
||||
func Benchmark_AzureBlob_Delete(b *testing.B) {
|
||||
testStore := newStore()
|
||||
err := testStore.Set("john", []byte("doe"), 0)
|
||||
require.NoError(b, err)
|
||||
|
||||
|
Reference in New Issue
Block a user