From b440c5767eebdf406200e9a47446827778514425 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Thu, 10 Aug 2023 22:05:00 +0200 Subject: [PATCH] [TESTS] verify facts for the admin storage documentation (cherry picked from commit 57e597bf7e1e3bb3b7bcbcea66a4ea170a231f85) (cherry picked from commit 643a2b0e81570e935779f6c509ebe4633fad74b9) (cherry picked from commit f10faffb4febeef114d5be4e6abe57bd3cd72894) --- modules/setting/forgejo_storage_test.go | 65 +++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 modules/setting/forgejo_storage_test.go diff --git a/modules/setting/forgejo_storage_test.go b/modules/setting/forgejo_storage_test.go new file mode 100644 index 0000000000..c24d340154 --- /dev/null +++ b/modules/setting/forgejo_storage_test.go @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: MIT + +// +// Tests verifying the Forgejo documentation on storage settings is correct +// +// https://forgejo.org/docs/v1.20/admin/storage/ +// + +package setting + +import ( + "fmt" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" +) + +func testForgejoStoragePath(t *testing.T, appDataPath, iniStr string, loader func(rootCfg ConfigProvider) error, storagePtr **Storage, expectedPath string) { + cfg, err := NewConfigProviderFromData(iniStr) + assert.NoError(t, err) + AppDataPath = appDataPath + assert.NoError(t, loader(cfg)) + storage := *storagePtr + + assert.EqualValues(t, "local", storage.Type) + assert.True(t, filepath.IsAbs(storage.Path)) + assert.EqualValues(t, filepath.Clean(expectedPath), filepath.Clean(storage.Path)) +} + +func TestForgejoDocs_StorageOverride(t *testing.T) { + for _, c := range []struct { + name string + basePath string + section string + loader func(rootCfg ConfigProvider) error + storage **Storage + }{ + {"Attachements", "attachments", "attachment", loadAttachmentFrom, &Attachment.Storage}, + {"LFS", "lfs", "lfs", loadLFSFrom, &LFS.Storage}, + {"Avatars", "avatars", "avatar", loadAvatarsFrom, &Avatar.Storage}, + {"Repository avatars", "repo-avatars", "repo-avatar", loadRepoAvatarFrom, &RepoAvatar.Storage}, + {"Repository archives", "repo-archive", "repo-archive", loadRepoArchiveFrom, &RepoArchive.Storage}, + {"Packages", "packages", "packages", loadPackagesFrom, &Packages.Storage}, + {"Actions logs", "actions_log", "storage.actions_log", loadActionsFrom, &Actions.LogStorage}, + {"Actions Artifacts", "actions_artifacts", "actions.artifacts", loadActionsFrom, &Actions.ArtifactStorage}, + } { + t.Run(c.name, func(t *testing.T) { + testForgejoStoragePath(t, "/appdata", "", c.loader, c.storage, fmt.Sprintf("/appdata/%s", c.basePath)) + + testForgejoStoragePath(t, "/appdata", ` +[storage] +STORAGE_TYPE = local +PATH = /storagepath +`, c.loader, c.storage, fmt.Sprintf("/storagepath/%s", c.basePath)) + + section := fmt.Sprintf(` +[%s] +STORAGE_TYPE = local +PATH = /sectionpath +`, c.section) + testForgejoStoragePath(t, "/appdata", section, c.loader, c.storage, "/sectionpath") + }) + } +}