Signed-off-by: Daniel Nephin <dnephin@docker.com>
| ... | ... |
@@ -4,12 +4,14 @@ import ( |
| 4 | 4 |
"compress/gzip" |
| 5 | 5 |
"context" |
| 6 | 6 |
"fmt" |
| 7 |
+ "net/http" |
|
| 7 | 8 |
"os" |
| 8 | 9 |
"runtime" |
| 9 | 10 |
"testing" |
| 10 | 11 |
"time" |
| 11 | 12 |
|
| 12 | 13 |
"github.com/docker/docker/daemon/logger" |
| 14 |
+ "github.com/gotestyourself/gotestyourself/env" |
|
| 13 | 15 |
"github.com/stretchr/testify/require" |
| 14 | 16 |
) |
| 15 | 17 |
|
| ... | ... |
@@ -82,6 +84,36 @@ func TestNewMissedToken(t *testing.T) {
|
| 82 | 82 |
} |
| 83 | 83 |
} |
| 84 | 84 |
|
| 85 |
+func TestNewWithProxy(t *testing.T) {
|
|
| 86 |
+ proxy := "http://proxy.testing:8888" |
|
| 87 |
+ reset := env.Patch(t, "HTTP_PROXY", proxy) |
|
| 88 |
+ defer reset() |
|
| 89 |
+ |
|
| 90 |
+ // must not be localhost |
|
| 91 |
+ splunkURL := "http://example.com:12345" |
|
| 92 |
+ logger, err := New(logger.Info{
|
|
| 93 |
+ Config: map[string]string{
|
|
| 94 |
+ splunkURLKey: splunkURL, |
|
| 95 |
+ splunkTokenKey: "token", |
|
| 96 |
+ splunkVerifyConnectionKey: "false", |
|
| 97 |
+ }, |
|
| 98 |
+ ContainerID: "containeriid", |
|
| 99 |
+ }) |
|
| 100 |
+ require.NoError(t, err) |
|
| 101 |
+ splunkLogger := logger.(*splunkLoggerInline) |
|
| 102 |
+ |
|
| 103 |
+ proxyFunc := splunkLogger.transport.Proxy |
|
| 104 |
+ require.NotNil(t, proxyFunc) |
|
| 105 |
+ |
|
| 106 |
+ req, err := http.NewRequest("GET", splunkURL, nil)
|
|
| 107 |
+ require.NoError(t, err) |
|
| 108 |
+ |
|
| 109 |
+ proxyURL, err := proxyFunc(req) |
|
| 110 |
+ require.NoError(t, err) |
|
| 111 |
+ require.NotNil(t, proxyURL) |
|
| 112 |
+ require.Equal(t, proxy, proxyURL.String()) |
|
| 113 |
+} |
|
| 114 |
+ |
|
| 85 | 115 |
// Test default settings |
| 86 | 116 |
func TestDefault(t *testing.T) {
|
| 87 | 117 |
hec := NewHTTPEventCollectorMock(t) |