Adam Štrauch
3120a8c6ee
All checks were successful
continuous-integration/drone/push Build is passing
88 lines
1.9 KiB
Go
88 lines
1.9 KiB
Go
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")
|
|
}
|
|
|
|
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")
|
|
}
|