region Tests
(t *testing.T)
| 12 | |
| 13 | // region Tests |
| 14 | func TestConnectionSetup(t *testing.T) { |
| 15 | log := log.NewTestLogger(t) |
| 16 | fromClientReader, fromClientWriter := io.Pipe() |
| 17 | toClientReader, toClientWriter := io.Pipe() |
| 18 | |
| 19 | clientCtx := proto.NewForwardCtx(toClientReader, fromClientWriter, log) |
| 20 | |
| 21 | serverCtx := proto.NewForwardCtx(fromClientReader, toClientWriter, log) |
| 22 | |
| 23 | closeChan := make(chan struct{}) |
| 24 | |
| 25 | go func() { |
| 26 | connChan, err := serverCtx.StartReverseForwardClient( |
| 27 | "127.0.0.1", |
| 28 | 8080, |
| 29 | false, |
| 30 | ) |
| 31 | if err != nil { |
| 32 | panic(err) |
| 33 | } |
| 34 | |
| 35 | testConServer := <-connChan |
| 36 | err = testConServer.Accept() |
| 37 | if err != nil { |
| 38 | log.Error("Error accept connection", err) |
| 39 | } |
| 40 | buf := make([]byte, 512) |
| 41 | nBytes, err := testConServer.Read(buf) |
| 42 | if err != nil { |
| 43 | log.Error("Failed to read from server") |
| 44 | } |
| 45 | _, err = testConServer.Write(buf[:nBytes]) |
| 46 | if err != nil { |
| 47 | log.Error("Failed to write to server") |
| 48 | } |
| 49 | <-closeChan |
| 50 | serverCtx.Kill() |
| 51 | }() |
| 52 | |
| 53 | conType, setup, connectionChan, err := clientCtx.StartClient() |
| 54 | if err != nil { |
| 55 | t.Fatal("Test failed with error", err) |
| 56 | } |
| 57 | if conType != proto.CONNECTION_TYPE_PORT_FORWARD { |
| 58 | panic(fmt.Errorf("Invalid connection type %d", conType)) |
| 59 | } |
| 60 | |
| 61 | go func() { |
| 62 | for { |
| 63 | conn, ok := <-connectionChan |
| 64 | if !ok { |
| 65 | break |
| 66 | } |
| 67 | _ = conn.Reject() |
| 68 | _ = conn.Close() |
| 69 | } |
| 70 | }() |
| 71 |
nothing calls this directly
no test coverage detected