本文整理汇总了Golang中github.com/shiguredo/fuji/inidef.LoadConfigByte函数的典型用法代码示例。如果您正苦于以下问题:Golang LoadConfigByte函数的具体用法?Golang LoadConfigByte怎么用?Golang LoadConfigByte使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LoadConfigByte函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestRetainJustPublish
// TestRetainJustPublish tests
// 1. connect gateway to local broker
// 2. send data with retaind flag dummy device normaly
func TestRetainJustPublish(t *testing.T) {
assert := assert.New(t)
iniStr := `
[gateway]
name = retainham
[broker "local/1"]
host = localhost
port = 1883
[device "doraretain/dummy"]
broker = local
qos = 0
interval = 10
payload = Hello world retain true.
type = EnOcean
retain = true
`
conf, err := inidef.LoadConfigByte([]byte(iniStr))
assert.Nil(err)
commandChannel := make(chan string)
go fuji.StartByFileWithChannel(conf, commandChannel)
time.Sleep(2 * time.Second)
}
示例2: TestWillJustPublish
// TestWillJustPublish tests
// 1. connect localhost broker with will message
// 2. send data from a dummy device
// 3. disconnect
func TestWillJustPublish(t *testing.T) {
assert := assert.New(t)
iniStr := `
[gateway]
name = willjustpublishham
[broker "local/1"]
host = localhost
port = 1883
will_message = no letter is good letter.
[device "dora/dummy"]
broker = local
qos = 0
interval = 10
payload = Hello will just publish world.
type = EnOcean
`
conf, err := inidef.LoadConfigByte([]byte(iniStr))
assert.Nil(err)
commandChannel := make(chan string)
go fuji.StartByFileWithChannel(conf, commandChannel)
time.Sleep(5 * time.Second)
// fuji.Stop()
}
示例3: TestStatus
func TestStatus(t *testing.T) {
assert := assert.New(t)
iniStr := `
[broker "sango"]
host = 192.168.1.20
port = 1033
[status "cpu"]
cpu_times = user, system, idle, nice, iowait, irq, softirq, guest
[status "memory"]
virtual_memory = total, available, percent, used, free
[status]
broker = sango
interval = 10
`
conf, err := inidef.LoadConfigByte([]byte(iniStr))
assert.Nil(err)
tt, err := NewStatus(conf)
assert.Nil(err)
st, ok := tt.(Status)
assert.True(ok)
assert.Equal(st.BrokerName, "sango")
assert.Equal(st.Interval, 10)
assert.Equal(8, len(st.CPU.CpuTimes))
assert.Equal(5, len(st.Memory.VirtualMemory))
}
示例4: TestNewGatewayMaxRetryCount
func TestNewGatewayMaxRetryCount(t *testing.T) {
assert := assert.New(t)
{ // default
iniStr := `
[gateway]
name = sango
`
conf, err := inidef.LoadConfigByte([]byte(iniStr))
gw, err := NewGateway(conf)
assert.Nil(err)
assert.Equal(3, gw.MaxRetryCount)
}
{ // specified
iniStr := `
[gateway]
name = sango
max_retry_count = 10
`
conf, err := inidef.LoadConfigByte([]byte(iniStr))
gw, err := NewGateway(conf)
assert.Nil(err)
assert.Equal(10, gw.MaxRetryCount)
}
{ // minus fail validation
iniStr := `
[gateway]
name = sango
max_retry_count = -10
`
conf, err := inidef.LoadConfigByte([]byte(iniStr))
_, err = NewGateway(conf)
assert.NotNil(err)
}
{ // invalid int
iniStr := `
[gateway]
name = sango
max_retry_count = aabbcc
`
conf, err := inidef.LoadConfigByte([]byte(iniStr))
_, err = NewGateway(conf)
assert.NotNil(err)
}
}
示例5: generalIniWillTest
func generalIniWillTest(test iniWillTestCase, t *testing.T) {
assert := assert.New(t)
conf, err := inidef.LoadConfigByte([]byte(test.iniStr))
assert.Nil(err)
brokers, err := broker.NewBrokers(conf, make(chan message.Message))
assert.Nil(err)
assert.NotEqual(0, len(brokers))
}
示例6: TestBrokerValidationPort
func TestBrokerValidationPort(t *testing.T) {
assert := assert.New(t)
iniStr := `
[broker "sango/2"]
host = 192.168.1.22
port = 65536
`
conf, err := inidef.LoadConfigByte([]byte(iniStr))
_, err = NewBrokers(conf, make(chan message.Message))
assert.NotNil(err)
}
示例7: TestBrokerValidationWill
func TestBrokerValidationWill(t *testing.T) {
assert := assert.New(t)
iniStr := `
[broker "sango/1"]
host = 192.168.1.22
port = 1883
will_message = will
`
conf, err := inidef.LoadConfigByte([]byte(iniStr))
b, err := NewBrokers(conf, make(chan message.Message))
assert.Nil(err)
assert.Equal(1, len(b))
assert.Equal([]byte("will"), b[0].WillMessage)
iniStr = `
[broker "sango/1"]
host = 192.168.1.22
port = 1883
will_message = \x01\x0f
`
conf, err = inidef.LoadConfigByte([]byte(iniStr))
b, err = NewBrokers(conf, make(chan message.Message))
assert.Nil(err)
assert.Equal(1, len(b))
assert.Equal([]byte{1, 15}, b[0].WillMessage)
// either will message has invalid binary, not error, just warn
iniStr = `
[broker "sango/1"]
host = 192.168.1.22
port = 1883
will_message = \x01\x0fffff
`
conf, err = inidef.LoadConfigByte([]byte(iniStr))
b, err = NewBrokers(conf, make(chan message.Message))
assert.Nil(err)
assert.Equal(1, len(b))
assert.Equal([]byte{1, 15}, b[0].WillMessage)
}
示例8: TestNewGatewayInvalidName
func TestNewGatewayInvalidName(t *testing.T) {
assert := assert.New(t)
{ // includes plus
iniStr := `
[gateway]
name = bone+lessham
`
conf, err := inidef.LoadConfigByte([]byte(iniStr))
_, err = NewGateway(conf)
assert.NotNil(err)
}
{ // includes sharp
iniStr := `
[gateway]
name = ` + "`" + `bone\#lessham`
conf, err := inidef.LoadConfigByte([]byte(iniStr))
_, err = NewGateway(conf)
assert.NotNil(err)
}
{ // too long
iniStr := `
[gateway]
name = bonelesshaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
`
conf, err := inidef.LoadConfigByte([]byte(iniStr))
_, err = NewGateway(conf)
assert.NotNil(err)
}
{ // \\U0000 string
iniStr := fmt.Sprintf(`
[gateway]
name = na%cme
`, '\u0000')
conf, err := inidef.LoadConfigByte([]byte(iniStr))
_, err = NewGateway(conf)
assert.NotNil(err)
}
}
示例9: TestBrokerValidationHost
func TestBrokerValidationHost(t *testing.T) {
assert := assert.New(t)
// invalid host, too long
iniStr := `
[broker "sango/2"]
host = 192.168.1.22aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
port = 1883
`
conf, err := inidef.LoadConfigByte([]byte(iniStr))
_, err = NewBrokers(conf, make(chan message.Message))
assert.NotNil(err)
}
示例10: generalIniRetainSerialDeviceTest
// generalIniRetainSerialDeviceTest checks retain function with serial device
func generalIniRetainSerialDeviceTest(test iniRetainTestCase, t *testing.T) {
assert := assert.New(t)
conf, err := inidef.LoadConfigByte([]byte(test.iniStr))
assert.Nil(err)
brokers, err := broker.NewBrokers(conf, make(chan message.Message))
assert.Nil(err)
devices, _, err := device.NewDevices(conf, brokers)
assert.Nil(err)
assert.Equal(1, len(devices))
}
示例11: TestNewSerialDeviceInvalidQoS
func TestNewSerialDeviceInvalidQoS(t *testing.T) {
assert := assert.New(t)
iniStr := `
[device "dora/serial"]
broker = sango
qos = -1
`
conf, err := inidef.LoadConfigByte([]byte(iniStr))
b1 := &broker.Broker{Name: "sango"}
brokers := []*broker.Broker{b1}
_, err = NewSerialDevice(conf.Sections[1], brokers, make(chan message.Message))
assert.NotNil(err)
}
示例12: TestNewSerialDeviceInvalidBroker
func TestNewSerialDeviceInvalidBroker(t *testing.T) {
assert := assert.New(t)
iniStr := `
[device "dora/serial"]
broker = doesNotExist
qos = 1
`
conf, err := inidef.LoadConfigByte([]byte(iniStr))
b1 := &broker.Broker{Name: "sango"}
brokers := []*broker.Broker{b1}
_, err = NewSerialDevice(conf.Sections[1], brokers, NewDeviceChannel())
assert.NotNil(err)
}
示例13: TestNewDummyDeviceInvalidBroker
func TestNewDummyDeviceInvalidBroker(t *testing.T) {
assert := assert.New(t)
iniStr := `
[device "dora/dummy"]
broker = doesNotExist
interval = 10
qos = 1
`
conf, err := inidef.LoadConfigByte([]byte(iniStr))
b1 := &broker.Broker{Name: "sango"}
brokers := []*broker.Broker{b1}
_, err = NewDummyDevice(conf.Sections[1], brokers, make(chan message.Message))
assert.NotNil(err)
}
示例14: TestNewDummyDeviceInvalidQoS
func TestNewDummyDeviceInvalidQoS(t *testing.T) {
assert := assert.New(t)
iniStr := `
[device "dora/dummy"]
broker = sango
interval = -1
qos = -1
`
conf, err := inidef.LoadConfigByte([]byte(iniStr))
b1 := &broker.Broker{Name: "sango"}
brokers := []*broker.Broker{b1}
_, err = NewDummyDevice(conf.Sections[1], brokers, NewDeviceChannel())
assert.NotNil(err)
}
示例15: TestNewBrokersSingle
func TestNewBrokersSingle(t *testing.T) {
assert := assert.New(t)
iniStr := `
[broker "sango/2"]
host = 192.168.1.22
port = 1883
`
conf, err := inidef.LoadConfigByte([]byte(iniStr))
b, err := NewBrokers(conf, make(chan message.Message))
assert.Nil(err)
assert.Equal(1, len(b))
assert.Equal("sango", b[0].Name)
assert.Equal(2, b[0].Priority)
assert.Equal("", b[0].TopicPrefix)
assert.Equal([]byte{}, b[0].WillMessage)
}