2021-10-02 18:00:35 +00:00
|
|
|
package drivers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"path"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
var testS3Driver S3Driver
|
|
|
|
|
|
|
|
func TestS3Create(t *testing.T) {
|
|
|
|
err := testS3Driver.Create("testkey", testFile)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
body, err := testS3Driver.Read("testkey")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, []byte(testContent), body)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestS3Write(t *testing.T) {
|
|
|
|
err := testS3Driver.Write("testkey", []byte(testContent))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
body, err := testS3Driver.Read("testkey")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, []byte(testContent), body)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestS3Get(t *testing.T) {
|
|
|
|
err := testS3Driver.Write("testkey", []byte(testContent))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
err = testS3Driver.Get("testkey", path.Join(testDirectory, "dsttestfile"))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
body, err := ioutil.ReadFile(path.Join(testDirectory, "dsttestfile"))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, []byte(testContent), body)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestS3Read(t *testing.T) {
|
|
|
|
err := testS3Driver.Write("testkey", []byte(testContent))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
body, err := testS3Driver.Read("testkey")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, []byte(testContent), body)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestS3List(t *testing.T) {
|
|
|
|
err := testS3Driver.Write("testkey", []byte(testContent))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
keys, err := testS3Driver.List("")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Contains(t, keys, "testkey")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestS3Delete(t *testing.T) {
|
|
|
|
err := testS3Driver.Write("testkey", []byte(testContent))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
keys, err := testS3Driver.List("")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Contains(t, keys, "testkey")
|
|
|
|
|
|
|
|
err = testS3Driver.Delete("testkey")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
keys, err = testS3Driver.List("")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotContains(t, keys, "testkey")
|
|
|
|
}
|
2021-11-03 22:50:58 +00:00
|
|
|
|
|
|
|
func TestGetDownloadLink(t *testing.T) {
|
|
|
|
err := testS3Driver.Write("testkey", []byte(testContent))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
link, err := testS3Driver.GetDownloadLink("testkey")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Contains(t, link, "/testsnapshots/testkey?X-Amz-Algorithm=AWS4-HMAC-SHA256")
|
|
|
|
}
|