52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/taosdata/taoskeeper/db"
|
|
"github.com/taosdata/taoskeeper/util"
|
|
)
|
|
|
|
func TestCreateClusterInfoSql(t *testing.T) {
|
|
conn, _ := db.NewConnector("root", "taosdata", "127.0.0.1", 6041, false)
|
|
defer conn.Close()
|
|
|
|
dbName := "db_202412031539"
|
|
conn.Exec(context.Background(), "create database "+dbName, util.GetQidOwn())
|
|
defer conn.Exec(context.Background(), "drop database "+dbName, util.GetQidOwn())
|
|
|
|
conn, _ = db.NewConnectorWithDb("root", "taosdata", "127.0.0.1", 6041, dbName, false)
|
|
defer conn.Close()
|
|
|
|
conn.Exec(context.Background(), CreateClusterInfoSql, util.GetQidOwn())
|
|
|
|
testCases := []struct {
|
|
ep string
|
|
wantErr bool
|
|
}{
|
|
{"", false},
|
|
{"hello", false},
|
|
{strings.Repeat("a", 128), false},
|
|
{strings.Repeat("a", 255), false},
|
|
{strings.Repeat("a", 256), true},
|
|
}
|
|
|
|
conn.Exec(context.Background(),
|
|
"create table d0 using cluster_info tags('cluster_id')", util.GetQidOwn())
|
|
|
|
for _, tc := range testCases {
|
|
sql := fmt.Sprintf("insert into d0 (ts, first_ep) values(%d, '%s')", time.Now().UnixMilli(), tc.ep)
|
|
_, err := conn.Exec(context.Background(), sql, util.GetQidOwn())
|
|
if tc.wantErr {
|
|
assert.Error(t, err) // [0x2653] Value too long for column/tag: endpoint
|
|
} else {
|
|
assert.NoError(t, err)
|
|
}
|
|
}
|
|
}
|