Files
streamsql/streamsql_table_print_test.go
T

46 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package streamsql
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
// TestPrintTable 测试PrintTable方法的基本功能
func TestPrintTable(t *testing.T) {
// 创建StreamSQL实例并测试PrintTable
ssql := New()
err := ssql.Execute("SELECT device, AVG(temperature) as avg_temp FROM stream GROUP BY device, TumblingWindow('2s')")
assert.NoError(t, err)
// 使用PrintTable方法不验证输出内容只确保不会panic
assert.NotPanics(t, func() {
ssql.PrintTable()
}, "PrintTable方法不应该panic")
// 发送测试数据
testData := []map[string]interface{}{
{"device": "sensor1", "temperature": 25.0},
{"device": "sensor2", "temperature": 30.0},
}
for _, data := range testData {
ssql.Emit(data)
}
// 等待窗口触发
time.Sleep(3 * time.Second)
}
// TestPrintTableFormat 测试printTableFormat方法处理不同数据类型
func TestPrintTableFormat(t *testing.T) {
ssql := New()
// 测试不同类型的数据确保不会panic
assert.NotPanics(t, func() {
// 测试空切片
ssql.printTableFormat([]map[string]interface{}{})
}, "空切片不应该panic")
}