-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make request timeout and TLS properties configurable. (#122)
Co-authored-by: Jeanette Booher <[email protected]> Co-authored-by: Kyle Tolliver <[email protected]> Co-authored-by: Luke Winikates <[email protected]> Co-authored-by: Devon Warshaw <[email protected]> Co-authored-by: Ernst Riemer <[email protected]> Co-authored-by: Jesse Pye <[email protected]>
- Loading branch information
1 parent
373ef2f
commit 45f78be
Showing
7 changed files
with
132 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,44 @@ | ||
package internal | ||
|
||
import ( | ||
"crypto/tls" | ||
"crypto/x509" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"net/http" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestBuildRequest(t *testing.T) { | ||
var r *reporter | ||
r = NewReporter("http://localhost:8010/wavefront", "").(*reporter) | ||
r = NewReporter("http://localhost:8010/wavefront", "", &http.Client{}).(*reporter) | ||
request, err := r.buildRequest("wavefront", nil) | ||
require.NoError(t, err) | ||
assert.Equal(t, "http://localhost:8010/wavefront/report?f=wavefront", request.URL.String()) | ||
} | ||
|
||
func TestNewClientWithNilTLSConfig(t *testing.T) { | ||
client := NewClient(10*time.Second, nil) | ||
assert.Equal(t, nil, client.Transport) | ||
} | ||
|
||
func TestNewClientWithCustomTLSConfig(t *testing.T) { | ||
caCertPool := x509.NewCertPool() | ||
fakeCert := []byte("Not a real cert") | ||
caCertPool.AppendCertsFromPEM(fakeCert) | ||
|
||
tlsConfig := &tls.Config{ | ||
RootCAs: caCertPool, | ||
} | ||
|
||
emptyTLSConfig := &tls.Config{} | ||
|
||
transport := &http.Transport{TLSClientConfig: tlsConfig} | ||
transportWithEmptyTLSConfig := &http.Transport{TLSClientConfig: emptyTLSConfig} | ||
|
||
client := NewClient(10*time.Second, tlsConfig) | ||
assert.Equal(t, transport, client.Transport) | ||
assert.NotEqual(t, transportWithEmptyTLSConfig, client.Transport) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters