2014-04-12 05:18:18 +00:00
|
|
|
// Beego (http://beego.me/)
|
2014-07-03 15:40:21 +00:00
|
|
|
//
|
2014-04-12 05:18:18 +00:00
|
|
|
// @description beego is an open-source, high-performance web framework for the Go programming language.
|
2014-07-03 15:40:21 +00:00
|
|
|
//
|
2014-04-12 05:18:18 +00:00
|
|
|
// @link http://github.com/astaxie/beego for the canonical source repository
|
2014-07-03 15:40:21 +00:00
|
|
|
//
|
2014-04-12 05:18:18 +00:00
|
|
|
// @license http://github.com/astaxie/beego/blob/master/LICENSE
|
2014-07-03 15:40:21 +00:00
|
|
|
//
|
2014-04-12 05:18:18 +00:00
|
|
|
// @authors astaxie
|
2013-08-21 16:07:33 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var inicontext = `
|
2013-11-27 15:55:26 +00:00
|
|
|
;comment one
|
|
|
|
#comment two
|
2013-08-21 16:07:33 +00:00
|
|
|
appname = beeapi
|
|
|
|
httpport = 8080
|
|
|
|
mysqlport = 3600
|
|
|
|
PI = 3.1415976
|
|
|
|
runmode = "dev"
|
|
|
|
autorender = false
|
|
|
|
copyrequestbody = true
|
2013-11-27 15:55:26 +00:00
|
|
|
[demo]
|
|
|
|
key1="asta"
|
|
|
|
key2 = "xie"
|
2013-11-29 02:17:35 +00:00
|
|
|
CaseInsensitive = true
|
2014-01-15 09:19:03 +00:00
|
|
|
peers = one;two;three
|
2013-08-21 16:07:33 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
func TestIni(t *testing.T) {
|
|
|
|
f, err := os.Create("testini.conf")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
_, err = f.WriteString(inicontext)
|
|
|
|
if err != nil {
|
|
|
|
f.Close()
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
f.Close()
|
|
|
|
defer os.Remove("testini.conf")
|
|
|
|
iniconf, err := NewConfig("ini", "testini.conf")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if iniconf.String("appname") != "beeapi" {
|
|
|
|
t.Fatal("appname not equal to beeapi")
|
|
|
|
}
|
|
|
|
if port, err := iniconf.Int("httpport"); err != nil || port != 8080 {
|
|
|
|
t.Error(port)
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if port, err := iniconf.Int64("mysqlport"); err != nil || port != 3600 {
|
|
|
|
t.Error(port)
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if pi, err := iniconf.Float("PI"); err != nil || pi != 3.1415976 {
|
|
|
|
t.Error(pi)
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if iniconf.String("runmode") != "dev" {
|
|
|
|
t.Fatal("runmode not equal to dev")
|
|
|
|
}
|
|
|
|
if v, err := iniconf.Bool("autorender"); err != nil || v != false {
|
|
|
|
t.Error(v)
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if v, err := iniconf.Bool("copyrequestbody"); err != nil || v != true {
|
|
|
|
t.Error(v)
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err = iniconf.Set("name", "astaxie"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if iniconf.String("name") != "astaxie" {
|
|
|
|
t.Fatal("get name error")
|
|
|
|
}
|
2013-12-09 15:54:35 +00:00
|
|
|
if iniconf.String("demo::key1") != "asta" {
|
2013-11-27 15:55:26 +00:00
|
|
|
t.Fatal("get demo.key1 error")
|
|
|
|
}
|
2013-12-09 15:54:35 +00:00
|
|
|
if iniconf.String("demo::key2") != "xie" {
|
2013-11-27 15:55:26 +00:00
|
|
|
t.Fatal("get demo.key2 error")
|
|
|
|
}
|
2013-12-09 15:54:35 +00:00
|
|
|
if v, err := iniconf.Bool("demo::caseinsensitive"); err != nil || v != true {
|
2013-11-29 02:17:35 +00:00
|
|
|
t.Fatal("get demo.caseinsensitive error")
|
|
|
|
}
|
2014-01-15 09:19:03 +00:00
|
|
|
|
|
|
|
if data := iniconf.Strings("demo::peers"); len(data) != 3 {
|
|
|
|
t.Fatal("get strings error", data)
|
|
|
|
} else if data[0] != "one" {
|
|
|
|
t.Fatal("get first params error not equat to one")
|
|
|
|
}
|
|
|
|
|
2013-08-21 16:07:33 +00:00
|
|
|
}
|