forked from b3log/pipe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettingsrv_test.go
90 lines (75 loc) · 2.86 KB
/
settingsrv_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Pipe - A small and beautiful blogging platform written in golang.
// Copyright (C) 2017-2018, b3log.org
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package service
import (
"testing"
"github.com/b3log/pipe/model"
)
func TestGetSetting(t *testing.T) {
setting := Setting.GetSetting(model.SettingCategoryBasic, model.SettingNameBasicBlogTitle, 1)
if nil == setting {
t.Errorf("setting is nil")
return
}
if "pipe 的博客" != setting.Value {
t.Errorf("expected is [%s], actual is [%s]", "pipe 的博客", setting.Value)
}
}
func TestGetAllSettings(t *testing.T) {
settings := Setting.GetAllSettings(1)
if 25 != len(settings) {
t.Errorf("expected is [%d], actual is [%d]", 24, len(settings))
}
}
func TestGetCategorySettings(t *testing.T) {
basicSettings := Setting.GetCategorySettings(model.SettingCategoryBasic, 1)
if 11 != len(basicSettings) {
t.Errorf("expected is [%d], actual is [%d]", 10, len(basicSettings))
}
}
func TestGetSettings(t *testing.T) {
settings := Setting.GetSettings(model.SettingCategoryBasic,
[]string{model.SettingNameBasicBlogTitle, model.SettingNameBasicBlogSubtitle}, 1)
if nil == settings {
t.Errorf("settings is nil")
return
}
if 1 > len(settings) {
t.Errorf("settings is empty")
return
}
if "pipe 的博客" != settings[model.SettingNameBasicBlogTitle].Value {
t.Errorf("expected is [%s], actual is [%s]", "pipe 的博客", settings[model.SettingNameBasicBlogTitle].Value)
}
}
func TestUpdateSettings(t *testing.T) {
settings := Setting.GetSettings(model.SettingCategoryBasic,
[]string{model.SettingNameBasicBlogTitle, model.SettingNameBasicBlogSubtitle}, 1)
settings[model.SettingNameBasicBlogTitle].Value = "更新后的标题"
var basics []*model.Setting
for _, setting := range settings {
basics = append(basics, setting)
}
if err := Setting.UpdateSettings(model.SettingCategoryBasic, basics, 1); nil != err {
t.Errorf("updates settings failed: " + err.Error())
return
}
settings = Setting.GetSettings(model.SettingCategoryBasic,
[]string{model.SettingNameBasicBlogTitle, model.SettingNameBasicBlogSubtitle}, 1)
if "更新后的标题" != settings[model.SettingNameBasicBlogTitle].Value {
t.Errorf("expected is [%s], actual is [%s]", "更新后的标题", settings[model.SettingNameBasicBlogTitle].Value)
}
}