background/test/utils_test.go

74 lines
1.6 KiB
Go

/*
* @Author: your name
* @Date: 2021-02-27 21:31:29
* @LastEditTime: 2021-10-01 01:12:40
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \background\test\utils_test.go
*/
package test
import (
"background/utils"
"fmt"
"log"
"net"
"testing"
"time"
)
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)
gocode := utils.CreateGoStruct(tbname, fields)
log.Print(gocode)
}
func TestVariableNameChange(t *testing.T) {
t.Log(utils.ToSnakeString("CaTest"))
}
func TestSpeed(t *testing.T) {
var tcpAddr *net.TCPAddr
tcpAddr, _ = net.ResolveTCPAddr("tcp", "192.168.6.103:6500")
conn, err := net.DialTCP("tcp", nil, tcpAddr)
if err != nil {
fmt.Println("Client connect error ! " + err.Error())
return
}
defer conn.Close()
recv := make([]byte, 128)
i := int32(0)
for ; i < 128; i++ {
recv[i] = byte(i & 0xff)
}
fmt.Println(conn.LocalAddr().String() + " : Client connected!")
reportTime := time.Now()
speed := 0
for {
cnt, _ := conn.Write(recv)
speed += cnt
// cnt,e = conn.Read(recv)
// if nil != e{
// log.Print(e.Error())
// }
// speed += cnt
if reportTime.Add(time.Second).Before(time.Now()) {
reportTime = time.Now()
t.Log("speed ", speed, " B/S")
speed = 0
}
}
}