2021-09-22 16:54:22 +00:00
|
|
|
/*
|
|
|
|
* @Author: your name
|
|
|
|
* @Date: 2021-02-27 21:31:29
|
2021-09-30 18:11:11 +00:00
|
|
|
* @LastEditTime: 2021-10-01 01:12:40
|
2021-09-22 16:54:22 +00:00
|
|
|
* @LastEditors: Please set LastEditors
|
|
|
|
* @Description: In User Settings Edit
|
|
|
|
* @FilePath: \background\test\utils_test.go
|
|
|
|
*/
|
2021-02-27 08:49:31 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"background/utils"
|
2021-09-22 16:54:22 +00:00
|
|
|
"fmt"
|
2021-02-27 08:49:31 +00:00
|
|
|
"log"
|
2021-09-22 16:54:22 +00:00
|
|
|
"net"
|
2021-02-27 08:49:31 +00:00
|
|
|
"testing"
|
2021-09-22 16:54:22 +00:00
|
|
|
"time"
|
2021-02-27 08:49:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDDL2ORM(t *testing.T) {
|
|
|
|
ddl := `
|
|
|
|
CREATE TABLE project (
|
|
|
|
id int(13) NOT NULL AUTO_INCREMENT,
|
|
|
|
title varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
|
|
|
content longblob,
|
|
|
|
contact_info varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
|
|
|
PRIMARY KEY (id)
|
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
|
|
|
|
`
|
|
|
|
tbname, fields := utils.DDL2Field(ddl)
|
|
|
|
log.Print(tbname, fields)
|
2021-02-27 17:45:34 +00:00
|
|
|
gocode := utils.CreateGoStruct(tbname,fields)
|
|
|
|
log.Print(gocode)
|
2021-02-27 08:49:31 +00:00
|
|
|
}
|
2021-09-22 16:54:22 +00:00
|
|
|
|
2021-09-30 18:11:11 +00:00
|
|
|
func TestVariableNameChange(t *testing.T){
|
|
|
|
t.Log(utils.ToSnakeString("CaTest"))
|
|
|
|
}
|
2021-09-22 16:54:22 +00:00
|
|
|
func TestSpeed(t *testing.T){
|
|
|
|
var tcpAddr *net.TCPAddr
|
2023-01-24 16:33:57 +00:00
|
|
|
tcpAddr,_ = net.ResolveTCPAddr("tcp","192.168.6.103:6500")
|
2021-09-22 16:54:22 +00:00
|
|
|
|
|
|
|
conn,err := net.DialTCP("tcp",nil,tcpAddr)
|
|
|
|
|
|
|
|
if err!=nil {
|
|
|
|
fmt.Println("Client connect error ! " + err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
defer conn.Close()
|
2023-01-24 16:33:57 +00:00
|
|
|
recv := make([]byte,128)
|
|
|
|
i := int32(0)
|
|
|
|
for ;i < 128;i++ {
|
|
|
|
recv[i] = byte(i&0xff)
|
|
|
|
}
|
2021-09-22 16:54:22 +00:00
|
|
|
fmt.Println(conn.LocalAddr().String() + " : Client connected!")
|
|
|
|
reportTime := time.Now()
|
|
|
|
speed := 0;
|
|
|
|
for {
|
2023-01-24 16:33:57 +00:00
|
|
|
cnt,_ := conn.Write(recv)
|
2021-09-22 16:54:22 +00:00
|
|
|
speed += cnt
|
2023-01-24 16:33:57 +00:00
|
|
|
// cnt,e = conn.Read(recv)
|
|
|
|
// if nil != e{
|
|
|
|
// log.Print(e.Error())
|
|
|
|
// }
|
|
|
|
// speed += cnt
|
2021-09-22 16:54:22 +00:00
|
|
|
if(reportTime.Add(time.Second).Before(time.Now())){
|
|
|
|
reportTime = time.Now()
|
|
|
|
t.Log("speed ",speed," B/S")
|
|
|
|
speed = 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|