blog_backend_api/test/utils_test.go

67 lines
1.4 KiB
Go
Raw Normal View History

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