summaryrefslogtreecommitdiffstats
path: root/models/system/setting_test.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-10-17 07:29:26 +0800
committerGitHub <noreply@github.com>2022-10-17 07:29:26 +0800
commitf860a6d2e4177ed4f4c2a58a07882bd00a1a52ad (patch)
tree93abb2f354576e50c87d70b0b4bb46369fb3a1f1 /models/system/setting_test.go
parent5d3dbffa150d832d2f9aedd9f90ca91178a95f9c (diff)
downloadgitea-f860a6d2e4177ed4f4c2a58a07882bd00a1a52ad.tar.gz
gitea-f860a6d2e4177ed4f4c2a58a07882bd00a1a52ad.zip
Add system setting table with cache and also add cache supports for user setting (#18058)
Diffstat (limited to 'models/system/setting_test.go')
-rw-r--r--models/system/setting_test.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/models/system/setting_test.go b/models/system/setting_test.go
new file mode 100644
index 0000000000..d25fc05f31
--- /dev/null
+++ b/models/system/setting_test.go
@@ -0,0 +1,53 @@
+// Copyright 2021 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package system_test
+
+import (
+ "strings"
+ "testing"
+
+ "code.gitea.io/gitea/models/system"
+ "code.gitea.io/gitea/models/unittest"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestSettings(t *testing.T) {
+ keyName := "server.LFS_LOCKS_PAGING_NUM"
+ assert.NoError(t, unittest.PrepareTestDatabase())
+
+ newSetting := &system.Setting{SettingKey: keyName, SettingValue: "50"}
+
+ // create setting
+ err := system.SetSetting(newSetting)
+ assert.NoError(t, err)
+ // test about saving unchanged values
+ err = system.SetSetting(newSetting)
+ assert.NoError(t, err)
+
+ // get specific setting
+ settings, err := system.GetSettings([]string{keyName})
+ assert.NoError(t, err)
+ assert.Len(t, settings, 1)
+ assert.EqualValues(t, newSetting.SettingValue, settings[strings.ToLower(keyName)].SettingValue)
+
+ // updated setting
+ updatedSetting := &system.Setting{SettingKey: keyName, SettingValue: "100", Version: newSetting.Version}
+ err = system.SetSetting(updatedSetting)
+ assert.NoError(t, err)
+
+ // get all settings
+ settings, err = system.GetAllSettings()
+ assert.NoError(t, err)
+ assert.Len(t, settings, 3)
+ assert.EqualValues(t, updatedSetting.SettingValue, settings[strings.ToLower(updatedSetting.SettingKey)].SettingValue)
+
+ // delete setting
+ err = system.DeleteSetting(&system.Setting{SettingKey: strings.ToLower(keyName)})
+ assert.NoError(t, err)
+ settings, err = system.GetAllSettings()
+ assert.NoError(t, err)
+ assert.Len(t, settings, 2)
+}