MM-10658 Change config fields to pointers (#9033)
* MM 10658 Change config fields to pointers (#8898) * Change fields of config structs to pointers and set defaults MM-10658 https://github.com/mattermost/mattermost-server/issues/8841 * Fix tests that go broken during switching config structs to pointers MM-10658 https://github.com/mattermost/mattermost-server/issues/8841 * Apply changes of current master while switching config structs to pointers MM-10658 https://github.com/mattermost/mattermost-server/issues/8841 * Fix new config pointer uses * Fix app tests * Fix mail test * remove debugging statement * fix TestUpdateConfig * assign config consistently * initialize AmazonS3Region in TestS3TestConnection * initialize fields for TestEmailTest * fix TestCheckMandatoryS3Fields
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
0c981aa010
Коммит
2ca222033c
@@ -29,19 +29,19 @@ func NewFileBackend(settings *model.FileSettings, enableComplianceFeatures bool)
|
||||
switch *settings.DriverName {
|
||||
case model.IMAGE_DRIVER_S3:
|
||||
return &S3FileBackend{
|
||||
endpoint: settings.AmazonS3Endpoint,
|
||||
accessKey: settings.AmazonS3AccessKeyId,
|
||||
secretKey: settings.AmazonS3SecretAccessKey,
|
||||
endpoint: *settings.AmazonS3Endpoint,
|
||||
accessKey: *settings.AmazonS3AccessKeyId,
|
||||
secretKey: *settings.AmazonS3SecretAccessKey,
|
||||
secure: settings.AmazonS3SSL == nil || *settings.AmazonS3SSL,
|
||||
signV2: settings.AmazonS3SignV2 != nil && *settings.AmazonS3SignV2,
|
||||
region: settings.AmazonS3Region,
|
||||
bucket: settings.AmazonS3Bucket,
|
||||
region: *settings.AmazonS3Region,
|
||||
bucket: *settings.AmazonS3Bucket,
|
||||
encrypt: settings.AmazonS3SSE != nil && *settings.AmazonS3SSE && enableComplianceFeatures,
|
||||
trace: settings.AmazonS3Trace != nil && *settings.AmazonS3Trace,
|
||||
}, nil
|
||||
case model.IMAGE_DRIVER_LOCAL:
|
||||
return &LocalFileBackend{
|
||||
directory: settings.Directory,
|
||||
directory: *settings.Directory,
|
||||
}, nil
|
||||
}
|
||||
return nil, model.NewAppError("NewFileBackend", "api.file.no_driver.app_error", nil, "", http.StatusInternalServerError)
|
||||
|
||||
@@ -42,7 +42,7 @@ func TestLocalFileBackendTestSuite(t *testing.T) {
|
||||
suite.Run(t, &FileBackendTestSuite{
|
||||
settings: model.FileSettings{
|
||||
DriverName: model.NewString(model.IMAGE_DRIVER_LOCAL),
|
||||
Directory: dir,
|
||||
Directory: &dir,
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -71,10 +71,11 @@ func runBackendTest(t *testing.T, encrypt bool) {
|
||||
suite.Run(t, &FileBackendTestSuite{
|
||||
settings: model.FileSettings{
|
||||
DriverName: model.NewString(model.IMAGE_DRIVER_S3),
|
||||
AmazonS3AccessKeyId: model.MINIO_ACCESS_KEY,
|
||||
AmazonS3SecretAccessKey: model.MINIO_SECRET_KEY,
|
||||
AmazonS3Bucket: model.MINIO_BUCKET,
|
||||
AmazonS3Endpoint: s3Endpoint,
|
||||
AmazonS3AccessKeyId: model.NewString(model.MINIO_ACCESS_KEY),
|
||||
AmazonS3SecretAccessKey: model.NewString(model.MINIO_SECRET_KEY),
|
||||
AmazonS3Bucket: model.NewString(model.MINIO_BUCKET),
|
||||
AmazonS3Region: model.NewString(""),
|
||||
AmazonS3Endpoint: model.NewString(s3Endpoint),
|
||||
AmazonS3SSL: model.NewBool(false),
|
||||
AmazonS3SSE: model.NewBool(encrypt),
|
||||
},
|
||||
|
||||
@@ -281,12 +281,12 @@ func s3PutOptions(encrypted bool, contentType string) s3.PutObjectOptions {
|
||||
}
|
||||
|
||||
func CheckMandatoryS3Fields(settings *model.FileSettings) *model.AppError {
|
||||
if len(settings.AmazonS3Bucket) == 0 {
|
||||
if settings.AmazonS3Bucket == nil || len(*settings.AmazonS3Bucket) == 0 {
|
||||
return model.NewAppError("S3File", "api.admin.test_s3.missing_s3_bucket", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
// if S3 endpoint is not set call the set defaults to set that
|
||||
if len(settings.AmazonS3Endpoint) == 0 {
|
||||
if settings.AmazonS3Endpoint == nil || len(*settings.AmazonS3Endpoint) == 0 {
|
||||
settings.SetDefaults()
|
||||
}
|
||||
|
||||
|
||||
@@ -17,15 +17,15 @@ func TestCheckMandatoryS3Fields(t *testing.T) {
|
||||
t.Fatal("should've failed with missing s3 bucket")
|
||||
}
|
||||
|
||||
cfg.AmazonS3Bucket = "test-mm"
|
||||
cfg.AmazonS3Bucket = model.NewString("test-mm")
|
||||
err = CheckMandatoryS3Fields(&cfg)
|
||||
if err != nil {
|
||||
t.Fatal("should've not failed")
|
||||
}
|
||||
|
||||
cfg.AmazonS3Endpoint = ""
|
||||
cfg.AmazonS3Endpoint = model.NewString("")
|
||||
err = CheckMandatoryS3Fields(&cfg)
|
||||
if err != nil || cfg.AmazonS3Endpoint != "s3.amazonaws.com" {
|
||||
if err != nil || *cfg.AmazonS3Endpoint != "s3.amazonaws.com" {
|
||||
t.Fatal("should've not failed because it should set the endpoint to the default")
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user