1 Star 0 Fork 1

wetrycode/tegenaria

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
settings_test.go 1.11 KB
一键复制 编辑 原始数据 按行查看 历史
package tegenaria
import (
"testing"
"github.com/smartystreets/goconvey/convey"
"github.com/spf13/afero"
"github.com/spf13/viper"
)
var yamlExample = []byte(`
redis:
addr: "127.0.0.1:6379"
username: ""
password: ""
log:
level: "error"
`)
func TestSetting(t *testing.T) {
convey.Convey("test settings load", t, func() {
config := &Configuration{
viper.New(),
}
fs := afero.NewMemMapFs()
err := fs.Mkdir(AbsFilePathTest(t, "/etc/viper"), 0o777)
convey.So(err, convey.ShouldBeNil)
file, err := fs.Create(AbsFilePathTest(t, "/etc/viper/settings.yaml"))
convey.So(err, convey.ShouldBeNil)
_, err = fs.Stat("/etc/viper/settings.yaml")
convey.So(err, convey.ShouldBeNil)
_, err = file.Write(yamlExample)
convey.So(err, convey.ShouldBeNil)
config.SetFs(fs)
ret := config.load("/etc/viper")
value, _ := config.GetValue("log.level")
convey.So(ret, convey.ShouldBeTrue)
convey.So(config.GetString("redis.addr"), convey.ShouldContainSubstring, "127.0.0.1")
convey.So(config.GetString("log.level"), convey.ShouldContainSubstring, "error")
convey.So(value, convey.ShouldNotBeNil)
})
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/wetrycode/tegenaria.git
git@gitee.com:wetrycode/tegenaria.git
wetrycode
tegenaria
tegenaria
master

搜索帮助