forked from zorkian/go-datadog-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequest_test.go
62 lines (54 loc) · 1.85 KB
/
request_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package datadog
import (
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestUriForApi(t *testing.T) {
c := Client{
apiKey: "sample_api_key",
appKey: "sample_app_key",
baseUrl: "https://base.datadoghq.com",
HttpClient: &http.Client{},
RetryTimeout: 1000,
}
t.Run("Get Uri for api string with query string", func(t *testing.T) {
uri, err := c.uriForAPI("/v1/events?type=critical")
assert.Nil(t, err)
assert.Equal(t, "https://base.datadoghq.com/api/v1/events?api_key=sample_api_key&application_key=sample_app_key&type=critical", uri)
})
t.Run("Get Uri for api without query string", func(t *testing.T) {
uri, err := c.uriForAPI("/v1/events")
assert.Nil(t, err)
assert.Equal(t, "https://base.datadoghq.com/api/v1/events?api_key=sample_api_key&application_key=sample_app_key", uri)
})
}
func TestRedactError(t *testing.T) {
c := Client{
apiKey: "sample_api_key",
appKey: "sample_app_key",
baseUrl: "https://base.datadoghq.com",
HttpClient: &http.Client{},
RetryTimeout: 1000,
}
t.Run("Error containing api key in string is correctly redacted", func(t *testing.T) {
var leakErr = fmt.Errorf("Error test: %s,%s", c.apiKey, c.apiKey)
var redactedErr = c.redactError(leakErr)
if assert.NotNil(t, redactedErr) {
assert.Equal(t, "Error test: redacted,redacted", redactedErr.Error())
}
})
t.Run("Error containing application key in string is correctly redacted", func(t *testing.T) {
var leakErr = fmt.Errorf("Error test: %s,%s", c.appKey, c.appKey)
var redactedErr = c.redactError(leakErr)
if assert.NotNil(t, redactedErr) {
assert.Equal(t, "Error test: redacted,redacted", redactedErr.Error())
}
})
t.Run("Nil error returns nil", func(t *testing.T) {
var harmlessErr error = nil
var redactedErr = c.redactError(harmlessErr)
assert.Nil(t, redactedErr)
})
}