123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package client
- import (
- "net"
- "sync"
- "testing"
- "github.com/cnlh/nps/lib/common"
- conn2 "github.com/cnlh/nps/lib/conn"
- "github.com/cnlh/nps/lib/file"
- )
- func TestConfig(t *testing.T) {
- conn, err := net.Dial("tcp", "127.0.0.1:8284")
- if err != nil {
- t.Fail()
- }
- c := conn2.NewConn(conn)
- c.SetAlive("tcp")
- if _, err := c.Write([]byte(common.Getverifyval("123"))); err != nil {
- t.Fail()
- }
- c.WriteConfig()
- config := &file.Config{
- U: "1",
- P: "2",
- Compress: "snappy",
- Crypt: true,
- CompressEncode: 0,
- CompressDecode: 0,
- }
- host := &file.Host{
- Host: "a.o.com",
- Target: "127.0.0.1:8080",
- HeaderChange: "",
- HostChange: "",
- Flow: nil,
- Client: nil,
- Remark: "111",
- NowIndex: 0,
- TargetArr: nil,
- NoStore: false,
- RWMutex: sync.RWMutex{},
- }
- tunnel := &file.Tunnel{
- Port: 9001,
- Mode: "tcp",
- Target: "127.0.0.1:8082",
- Remark: "333",
- }
- var b []byte
- if b, err = c.ReadLen(16); err != nil {
- t.Fail()
- }
- if _, err := c.SendConfigInfo(config); err != nil {
- t.Fail()
- }
- if !c.GetAddStatus() {
- t.Fail()
- }
- if _, err := c.SendHostInfo(host); err != nil {
- t.Fail()
- }
- if !c.GetAddStatus() {
- t.Fail()
- }
- if _, err := c.SendTaskInfo(tunnel); err != nil {
- t.Fail()
- }
- if !c.GetAddStatus() {
- t.Fail()
- }
- c.Close()
- NewRPClient("127.0.0.1:8284", string(b), "tcp").Start()
- }
|