node-api/apps/drivers/s3_test.go
Adam Štrauch bc50cb1105
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
Support for snapshots
* full implementation of snapshots
* tests of the snapshot backend
* Drone CI pipeline
* New snapshots handlers
* Filesystem driver
* S3 driver
2021-10-26 18:57:52 +02:00

80 lines
1.7 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")
}