-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdirectProxy_test.go
44 lines (37 loc) · 1.08 KB
/
directProxy_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"context"
"net/http"
"testing"
"time"
"github.com/azak-azkaran/cascade/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestDirectProxy_Run(t *testing.T) {
utils.Init()
time.Sleep(1 * time.Second)
directProxy := DIRECT.Run(true)
var directServer *http.Server
go func() {
utils.Sugar.Info("serving end proxy server at localhost:7082")
directServer = &http.Server{
Addr: "localhost:7082",
Handler: directProxy,
}
err := directServer.ListenAndServe()
assert.EqualError(t, err, http.ErrServerClosed.Error())
}()
utils.Sugar.Info("waiting for running")
time.Sleep(1 * time.Second)
resp, err := utils.GetResponse("http://localhost:7082", "https://www.google.de")
assert.NoError(t, err)
require.NotNil(t, resp)
assert.Equal(t, resp.StatusCode, http.StatusOK)
resp, err = utils.GetResponse("http://localhost:7082", "http://www.google.de")
assert.NoError(t, err)
require.NotNil(t, resp)
assert.Equal(t, resp.StatusCode, http.StatusOK)
err = directServer.Shutdown(context.TODO())
assert.NoError(t, err)
}