Exemplo n.º 1
0
func TestIniNewBrokers(t *testing.T) {
	assert := assert.New(t)

	conf, err := inidef.LoadConfig("testing_conf.ini")
	assert.Nil(err)
	brokerList, err := broker.NewBrokers(conf, make(chan message.Message))
	assert.Nil(err)
	assert.Equal(3, len(brokerList))
}
Exemplo n.º 2
0
func TestIniNewGateway(t *testing.T) {
	assert := assert.New(t)

	conf, err := inidef.LoadConfig("testing_conf.ini")
	assert.Nil(err)
	gw, err := gateway.NewGateway(conf)
	assert.Nil(err)
	assert.Equal("ham", gw.Name)
}
Exemplo n.º 3
0
func TestIniNewSerialDevices(t *testing.T) {
	assert := assert.New(t)

	conf, err := inidef.LoadConfig("testing_conf.ini")
	brokerList, err := broker.NewBrokers(conf, make(chan message.Message))
	assert.Nil(err)
	deviceList, _, err := device.NewDevices(conf, brokerList)
	assert.Nil(err)
	assert.Equal(3, len(deviceList))
}
Exemplo n.º 4
0
func TestNewGateway(t *testing.T) {
	assert := assert.New(t)

	conf, err := inidef.LoadConfig("../tests/testing_conf.ini")
	gw, err := NewGateway(conf)
	assert.Nil(err)
	assert.Equal("ham", gw.Name)
	assert.NotNil(gw.CmdChan)
	assert.NotNil(gw.MsgChan)
	assert.NotNil(gw.BrokerChan)
}
Exemplo n.º 5
0
func TestIniNewDummyDevice(t *testing.T) {
	assert := assert.New(t)

	conf, err := inidef.LoadConfig("testing_conf.ini")
	brokerList, err := broker.NewBrokers(conf, make(chan message.Message))
	assert.Nil(err)

	dummy, err := device.NewDummyDevice(conf.Sections[7], brokerList, device.NewDeviceChannel())
	assert.Nil(err)
	assert.Equal("dummy", dummy.DeviceType())
	assert.Equal(2, int(dummy.QoS))
}
Exemplo n.º 6
0
Arquivo: app.go Projeto: chansuke/fuji
// Start make command channel and start gateway.
func Start(configPath string) {
	conf, err := inidef.LoadConfig(configPath)
	if err != nil {
		log.Fatalf("loading ini file faild, %v", err)
	}

	commandChannel := make(chan string)

	err = StartByFileWithChannel(conf, commandChannel)
	if err != nil {
		log.Error(err)
	}
}
Exemplo n.º 7
0
// TestConnectLocalPubSub tests
// 1. connect gateway to local broker
// 2. send data from dummy
// 3. check subscribe
func TestConnectLocalPubSub(t *testing.T) {
	assert := assert.New(t)

	// pub/sub test to broker on localhost
	// dummydevice is used as a source of published message
	// publised messages confirmed by subscriber

	// get config
	conf, err := inidef.LoadConfig("connectlocalpubsub.ini")
	assert.Nil(err)

	// get Gateway
	gw, err := gateway.NewGateway(conf)
	assert.Nil(err)

	// get Broker
	brokerList, err := broker.NewBrokers(conf, gw.BrokerChan)
	assert.Nil(err)

	// get DummyDevice
	dummyDevice, err := device.NewDummyDevice(conf.Sections[3], brokerList, device.NewDeviceChannel())
	assert.Nil(err)
	assert.NotNil(dummyDevice)

	// Setup MQTT pub/sub client to confirm published content.
	//
	subscriberChannel := make(chan [2]string)

	opts := MQTT.NewClientOptions()
	url := fmt.Sprintf("tcp://%s:%d", brokerList[0].Host, brokerList[0].Port)
	opts.AddBroker(url)
	opts.SetClientID(gw.Name)
	opts.SetCleanSession(false)
	opts.SetDefaultPublishHandler(func(client *MQTT.Client, msg MQTT.Message) {
		subscriberChannel <- [2]string{msg.Topic(), string(msg.Payload())}
	})

	client := MQTT.NewClient(opts)
	assert.Nil(err)
	if token := client.Connect(); token.Wait() && token.Error() != nil {
		assert.Nil(token.Error())
	}

	qos := 0
	topic := "#"
	client.Subscribe(topic, byte(qos), func(client *MQTT.Client, msg MQTT.Message) {
	})

	// TODO: should be write later
	/*
		channel := fuji.SetupMQTTChannel(client, gateway, brokerList[0])

		// Setup DummyDevice to publish test payload

		dummyDevice.Start(channel)

		// wait for 1 publication of dummy worker
		message := <-subscriberChannel
		assert.Equal("dummy", message)

		client.Disconnect(250)
	*/
}
Exemplo n.º 8
0
func TestIniLoadini(t *testing.T) {
	assert := assert.New(t)

	_, err := inidef.LoadConfig("testing_conf.ini")
	assert.Nil(err)
}