Run file tests on Minio and local drivers. (#7482)
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
dcf9e96a0b
Коммит
3463e1fc93
21
Makefile
21
Makefile
@@ -120,6 +120,16 @@ start-docker:
|
|||||||
docker start mattermost-inbucket > /dev/null; \
|
docker start mattermost-inbucket > /dev/null; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@if [ $(shell docker ps -a | grep -ci mattermost-minio) -eq 0 ]; then \
|
||||||
|
echo starting mattermost-minio; \
|
||||||
|
docker run --name mattermost-minio -p 9001:9000 -e "MINIO_ACCESS_KEY=minioaccesskey" \
|
||||||
|
-e "MINIO_SECRET_KEY=miniosecretkey" -d minio/minio:latest server /data > /dev/null; \
|
||||||
|
docker exec -it mattermost-minio /bin/sh -c "mkdir /data/mattermost-test" > /dev/null; \
|
||||||
|
elif [ $(shell docker ps | grep -ci mattermost-minio) -eq 0 ]; then \
|
||||||
|
echo restarting mattermost-minio; \
|
||||||
|
docker start mattermost-minio > /dev/null; \
|
||||||
|
fi
|
||||||
|
|
||||||
ifeq ($(BUILD_ENTERPRISE_READY),true)
|
ifeq ($(BUILD_ENTERPRISE_READY),true)
|
||||||
@echo Ldap test user test.one
|
@echo Ldap test user test.one
|
||||||
@if [ $(shell docker ps -a | grep -ci mattermost-openldap) -eq 0 ]; then \
|
@if [ $(shell docker ps -a | grep -ci mattermost-openldap) -eq 0 ]; then \
|
||||||
@@ -183,6 +193,11 @@ stop-docker:
|
|||||||
docker stop mattermost-inbucket > /dev/null; \
|
docker stop mattermost-inbucket > /dev/null; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@if [ $(shell docker ps -a | grep -ci mattermost-minio) -eq 1 ]; then \
|
||||||
|
echo stopping mattermost-minio; \
|
||||||
|
docker stop mattermost-minio > /dev/null; \
|
||||||
|
fi
|
||||||
|
|
||||||
@if [ $(shell docker ps -a | grep -ci mattermost-elasticsearch) -eq 1 ]; then \
|
@if [ $(shell docker ps -a | grep -ci mattermost-elasticsearch) -eq 1 ]; then \
|
||||||
echo stopping mattermost-elasticsearch; \
|
echo stopping mattermost-elasticsearch; \
|
||||||
docker stop mattermost-elasticsearch > /dev/null; \
|
docker stop mattermost-elasticsearch > /dev/null; \
|
||||||
@@ -215,6 +230,12 @@ clean-docker:
|
|||||||
docker rm -v mattermost-inbucket > /dev/null; \
|
docker rm -v mattermost-inbucket > /dev/null; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@if [ $(shell docker ps -a | grep -ci mattermost-minio) -eq 1 ]; then \
|
||||||
|
echo removing mattermost-minio; \
|
||||||
|
docker stop mattermost-minio > /dev/null; \
|
||||||
|
docker rm -v mattermost-minio > /dev/null; \
|
||||||
|
fi
|
||||||
|
|
||||||
@if [ $(shell docker ps -a | grep -ci mattermost-elasticsearch) -eq 1 ]; then \
|
@if [ $(shell docker ps -a | grep -ci mattermost-elasticsearch) -eq 1 ]; then \
|
||||||
echo removing mattermost-elasticsearch; \
|
echo removing mattermost-elasticsearch; \
|
||||||
docker stop mattermost-elasticsearch > /dev/null; \
|
docker stop mattermost-elasticsearch > /dev/null; \
|
||||||
|
|||||||
@@ -6,117 +6,138 @@ package utils
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestReadWriteFile(t *testing.T) {
|
type FileTestSuite struct {
|
||||||
|
suite.Suite
|
||||||
|
|
||||||
|
testDriver string
|
||||||
|
|
||||||
|
// Config to be reset after tests.
|
||||||
|
driverName string
|
||||||
|
amazonS3AccessKeyId string
|
||||||
|
amazonS3SecretAccessKey string
|
||||||
|
amazonS3Bucket string
|
||||||
|
amazonS3Endpoint string
|
||||||
|
amazonS3SSL bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFileLocalTestSuite(t *testing.T) {
|
||||||
|
testsuite := FileTestSuite{
|
||||||
|
testDriver: model.IMAGE_DRIVER_LOCAL,
|
||||||
|
}
|
||||||
|
suite.Run(t, &testsuite)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFileMinioTestSuite(t *testing.T) {
|
||||||
|
testsuite := FileTestSuite{
|
||||||
|
testDriver: model.IMAGE_DRIVER_S3,
|
||||||
|
}
|
||||||
|
suite.Run(t, &testsuite)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *FileTestSuite) SetupTest() {
|
||||||
TranslationsPreInit()
|
TranslationsPreInit()
|
||||||
LoadConfig("config.json")
|
LoadConfig("config.json")
|
||||||
InitTranslations(Cfg.LocalizationSettings)
|
InitTranslations(Cfg.LocalizationSettings)
|
||||||
|
|
||||||
b := []byte("test")
|
// Save state to restore after the test has run.
|
||||||
path := "tests/" + model.NewId()
|
s.driverName = *Cfg.FileSettings.DriverName
|
||||||
|
s.amazonS3AccessKeyId = Cfg.FileSettings.AmazonS3AccessKeyId
|
||||||
|
s.amazonS3SecretAccessKey = Cfg.FileSettings.AmazonS3SecretAccessKey
|
||||||
|
s.amazonS3Bucket = Cfg.FileSettings.AmazonS3Bucket
|
||||||
|
s.amazonS3Endpoint = Cfg.FileSettings.AmazonS3Endpoint
|
||||||
|
s.amazonS3SSL = *Cfg.FileSettings.AmazonS3SSL
|
||||||
|
|
||||||
if err := WriteFile(b, path); err != nil {
|
// Set up the state for the tests.
|
||||||
t.Fatal(err)
|
if s.testDriver == model.IMAGE_DRIVER_LOCAL {
|
||||||
}
|
*Cfg.FileSettings.DriverName = model.IMAGE_DRIVER_LOCAL
|
||||||
defer RemoveFile(path)
|
} else if s.testDriver == model.IMAGE_DRIVER_S3 {
|
||||||
|
*Cfg.FileSettings.DriverName = model.IMAGE_DRIVER_S3
|
||||||
if read, err := ReadFile(path); err != nil {
|
Cfg.FileSettings.AmazonS3AccessKeyId = "minioaccesskey"
|
||||||
t.Fatal(err)
|
Cfg.FileSettings.AmazonS3SecretAccessKey = "miniosecretkey"
|
||||||
} else if readString := string(read); readString != "test" {
|
Cfg.FileSettings.AmazonS3Bucket = "mattermost-test"
|
||||||
t.Fatal("should've read back contents of file")
|
Cfg.FileSettings.AmazonS3Endpoint = "dockerhost:9001"
|
||||||
|
*Cfg.FileSettings.AmazonS3SSL = false
|
||||||
|
} else {
|
||||||
|
s.T().Fatal("Invalid image driver set for test suite.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMoveFile(t *testing.T) {
|
func (s *FileTestSuite) TearDownTest() {
|
||||||
TranslationsPreInit()
|
// Restore the test state.
|
||||||
LoadConfig("config.json")
|
*Cfg.FileSettings.DriverName = s.driverName
|
||||||
InitTranslations(Cfg.LocalizationSettings)
|
Cfg.FileSettings.AmazonS3AccessKeyId = s.amazonS3AccessKeyId
|
||||||
|
Cfg.FileSettings.AmazonS3SecretAccessKey = s.amazonS3SecretAccessKey
|
||||||
|
Cfg.FileSettings.AmazonS3Bucket = s.amazonS3Bucket
|
||||||
|
Cfg.FileSettings.AmazonS3Endpoint = s.amazonS3Endpoint
|
||||||
|
*Cfg.FileSettings.AmazonS3SSL = s.amazonS3SSL
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *FileTestSuite) TestReadWriteFile() {
|
||||||
|
b := []byte("test")
|
||||||
|
path := "tests/" + model.NewId()
|
||||||
|
|
||||||
|
s.Nil(WriteFile(b, path))
|
||||||
|
defer RemoveFile(path)
|
||||||
|
|
||||||
|
read, err := ReadFile(path)
|
||||||
|
s.Nil(err)
|
||||||
|
|
||||||
|
readString := string(read)
|
||||||
|
s.EqualValues(readString, "test")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *FileTestSuite) TestMoveFile() {
|
||||||
b := []byte("test")
|
b := []byte("test")
|
||||||
path1 := "tests/" + model.NewId()
|
path1 := "tests/" + model.NewId()
|
||||||
path2 := "tests/" + model.NewId()
|
path2 := "tests/" + model.NewId()
|
||||||
|
|
||||||
if err := WriteFile(b, path1); err != nil {
|
s.Nil(WriteFile(b, path1))
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer RemoveFile(path1)
|
defer RemoveFile(path1)
|
||||||
|
|
||||||
if err := MoveFile(path1, path2); err != nil {
|
s.Nil(MoveFile(path1, path2))
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer RemoveFile(path2)
|
defer RemoveFile(path2)
|
||||||
|
|
||||||
if _, err := ReadFile(path1); err == nil {
|
_, err := ReadFile(path1)
|
||||||
t.Fatal("file should no longer exist at old path")
|
s.Error(err)
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := ReadFile(path2); err != nil {
|
_, err = ReadFile(path2)
|
||||||
t.Fatal("file should exist at new path", err)
|
s.Nil(err)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRemoveFile(t *testing.T) {
|
func (s *FileTestSuite) TestRemoveFile() {
|
||||||
TranslationsPreInit()
|
|
||||||
LoadConfig("config.json")
|
|
||||||
InitTranslations(Cfg.LocalizationSettings)
|
|
||||||
|
|
||||||
b := []byte("test")
|
b := []byte("test")
|
||||||
path := "tests/" + model.NewId()
|
path := "tests/" + model.NewId()
|
||||||
|
|
||||||
if err := WriteFile(b, path); err != nil {
|
s.Nil(WriteFile(b, path))
|
||||||
t.Fatal(err)
|
s.Nil(RemoveFile(path))
|
||||||
}
|
|
||||||
|
|
||||||
if err := RemoveFile(path); err != nil {
|
_, err := ReadFile(path)
|
||||||
t.Fatal(err)
|
s.Error(err)
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := ReadFile(path); err == nil {
|
s.Nil(WriteFile(b, "tests2/foo"))
|
||||||
t.Fatal("should've removed file")
|
s.Nil(WriteFile(b, "tests2/bar"))
|
||||||
}
|
s.Nil(WriteFile(b, "tests2/asdf"))
|
||||||
|
s.Nil(RemoveDirectory("tests2"))
|
||||||
if err := WriteFile(b, "tests2/foo"); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if err := WriteFile(b, "tests2/bar"); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if err := WriteFile(b, "tests2/asdf"); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if err := RemoveDirectory("tests2"); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRemoveDirectory(t *testing.T) {
|
func (s *FileTestSuite) TestRemoveDirectory() {
|
||||||
TranslationsPreInit()
|
|
||||||
LoadConfig("config.json")
|
|
||||||
InitTranslations(Cfg.LocalizationSettings)
|
|
||||||
|
|
||||||
b := []byte("test")
|
b := []byte("test")
|
||||||
|
|
||||||
if err := WriteFile(b, "tests2/foo"); err != nil {
|
s.Nil(WriteFile(b, "tests2/foo"))
|
||||||
t.Fatal(err)
|
s.Nil(WriteFile(b, "tests2/bar"))
|
||||||
}
|
s.Nil(WriteFile(b, "tests2/aaa"))
|
||||||
if err := WriteFile(b, "tests2/bar"); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if err := WriteFile(b, "tests2/aaa"); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := RemoveDirectory("tests2"); err != nil {
|
s.Nil(RemoveDirectory("tests2"))
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := ReadFile("tests2/foo"); err == nil {
|
_, err := ReadFile("tests2/foo")
|
||||||
t.Fatal("should've removed file")
|
s.Error(err)
|
||||||
} else if _, err := ReadFile("tests2/bar"); err == nil {
|
_, err = ReadFile("tests2/bar")
|
||||||
t.Fatal("should've removed file")
|
s.Error(err)
|
||||||
} else if _, err := ReadFile("tests2/asdf"); err == nil {
|
_, err = ReadFile("tests2/asdf")
|
||||||
t.Fatal("should've removed file")
|
s.Error(err)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user