node-api/apps/drivers/s3_test.go

80 lines
1.7 KiB
Go
Raw Normal View History

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")
}