loading up the forgejo repo on tangled to test page performance
at forgejo 3.5 kB view raw
1// Copyright 2023 The Gitea Authors. All rights reserved. 2// SPDX-License-Identifier: MIT 3 4package setting 5 6import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 "github.com/stretchr/testify/require" 11) 12 13func Test_getStorageCustomType(t *testing.T) { 14 iniStr := ` 15[attachment] 16STORAGE_TYPE = my_minio 17MINIO_BUCKET = gitea-attachment 18 19[storage.my_minio] 20STORAGE_TYPE = minio 21MINIO_ENDPOINT = my_minio:9000 22` 23 cfg, err := NewConfigProviderFromData(iniStr) 24 require.NoError(t, err) 25 26 require.NoError(t, loadAttachmentFrom(cfg)) 27 28 assert.EqualValues(t, "minio", Attachment.Storage.Type) 29 assert.Equal(t, "my_minio:9000", Attachment.Storage.MinioConfig.Endpoint) 30 assert.Equal(t, "gitea-attachment", Attachment.Storage.MinioConfig.Bucket) 31 assert.Equal(t, "attachments/", Attachment.Storage.MinioConfig.BasePath) 32} 33 34func Test_getStorageTypeSectionOverridesStorageSection(t *testing.T) { 35 iniStr := ` 36[attachment] 37STORAGE_TYPE = minio 38 39[storage.minio] 40MINIO_BUCKET = gitea-minio 41 42[storage] 43MINIO_BUCKET = gitea 44` 45 cfg, err := NewConfigProviderFromData(iniStr) 46 require.NoError(t, err) 47 48 require.NoError(t, loadAttachmentFrom(cfg)) 49 50 assert.EqualValues(t, "minio", Attachment.Storage.Type) 51 assert.Equal(t, "gitea-minio", Attachment.Storage.MinioConfig.Bucket) 52 assert.Equal(t, "attachments/", Attachment.Storage.MinioConfig.BasePath) 53} 54 55func Test_getStorageSpecificOverridesStorage(t *testing.T) { 56 iniStr := ` 57[attachment] 58STORAGE_TYPE = minio 59MINIO_BUCKET = gitea-attachment 60 61[storage.attachments] 62MINIO_BUCKET = gitea 63 64[storage] 65STORAGE_TYPE = local 66` 67 cfg, err := NewConfigProviderFromData(iniStr) 68 require.NoError(t, err) 69 70 require.NoError(t, loadAttachmentFrom(cfg)) 71 72 assert.EqualValues(t, "minio", Attachment.Storage.Type) 73 assert.Equal(t, "gitea-attachment", Attachment.Storage.MinioConfig.Bucket) 74 assert.Equal(t, "attachments/", Attachment.Storage.MinioConfig.BasePath) 75} 76 77func Test_getStorageGetDefaults(t *testing.T) { 78 cfg, err := NewConfigProviderFromData("") 79 require.NoError(t, err) 80 81 require.NoError(t, loadAttachmentFrom(cfg)) 82 83 // default storage is local, so bucket is empty 84 assert.Empty(t, Attachment.Storage.MinioConfig.Bucket) 85} 86 87func Test_getStorageInheritNameSectionType(t *testing.T) { 88 iniStr := ` 89[storage.attachments] 90STORAGE_TYPE = minio 91` 92 cfg, err := NewConfigProviderFromData(iniStr) 93 require.NoError(t, err) 94 95 require.NoError(t, loadAttachmentFrom(cfg)) 96 97 assert.EqualValues(t, "minio", Attachment.Storage.Type) 98} 99 100func Test_AttachmentStorage(t *testing.T) { 101 iniStr := ` 102;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 103[storage] 104STORAGE_TYPE = minio 105MINIO_ENDPOINT = s3.my-domain.net 106MINIO_BUCKET = gitea 107MINIO_LOCATION = homenet 108MINIO_USE_SSL = true 109MINIO_ACCESS_KEY_ID = correct_key 110MINIO_SECRET_ACCESS_KEY = correct_key 111` 112 cfg, err := NewConfigProviderFromData(iniStr) 113 require.NoError(t, err) 114 115 require.NoError(t, loadAttachmentFrom(cfg)) 116 storage := Attachment.Storage 117 118 assert.EqualValues(t, "minio", storage.Type) 119 assert.Equal(t, "gitea", storage.MinioConfig.Bucket) 120} 121 122func Test_AttachmentStorage1(t *testing.T) { 123 iniStr := ` 124[storage] 125STORAGE_TYPE = minio 126` 127 cfg, err := NewConfigProviderFromData(iniStr) 128 require.NoError(t, err) 129 130 require.NoError(t, loadAttachmentFrom(cfg)) 131 assert.EqualValues(t, "minio", Attachment.Storage.Type) 132 assert.Equal(t, "gitea", Attachment.Storage.MinioConfig.Bucket) 133 assert.Equal(t, "attachments/", Attachment.Storage.MinioConfig.BasePath) 134}