当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 56

yunwisdom/pipe
暂停

forked from 88250/pipe 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
settingsrv_test.go 2.91 KB
一键复制 编辑 原始数据 按行查看 历史
88250 提交于 2019-01-04 00:08 . :green_heart:修复单元测试
// Pipe - A small and beautiful blogging platform written in golang.
// Copyright (C) 2017-2019, b3log.org & hacpai.com
//
// 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)
settingsCount := 26
if settingsCount != len(settings) {
t.Errorf("expected is [%d], actual is [%d]", settingsCount, 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)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/yunwisdom/pipe.git
git@gitee.com:yunwisdom/pipe.git
yunwisdom
pipe
pipe
master

搜索帮助