@@ -16,6 +16,7 @@ import (
16
16
"testing"
17
17
18
18
"github.com/stretchr/testify/assert"
19
+ "github.com/stretchr/testify/require"
19
20
20
21
"github.com/DataDog/datadog-agent/comp/core/config"
21
22
logmock "github.com/DataDog/datadog-agent/comp/core/log/mock"
@@ -35,16 +36,18 @@ func TestCheckValidAPIKey(t *testing.T) {
35
36
36
37
keysPerDomains := map [string ][]utils.APIKeys {
37
38
ts1 .URL : {
38
- utils .NewAPIKeys ("" , "api_key1" ),
39
- utils .NewAPIKeys ("" , "api_key2" ),
39
+ utils .NewAPIKeys ("path " , "api_key1" ),
40
+ utils .NewAPIKeys ("path " , "api_key2" ),
40
41
},
41
42
ts2 .URL : {
42
- utils .NewAPIKeys ("" , "key3" ),
43
+ utils .NewAPIKeys ("path " , "key3" ),
43
44
},
44
45
}
45
46
log := logmock .New (t )
46
47
cfg := config .NewMock (t )
47
- fh := forwarderHealth {log : log , config : cfg , domainResolvers : resolver .NewSingleDomainResolvers (keysPerDomains )}
48
+ r , err := resolver .NewSingleDomainResolvers (keysPerDomains )
49
+ require .NoError (t , err )
50
+ fh := forwarderHealth {log : log , config : cfg , domainResolvers : r }
48
51
fh .init ()
49
52
assert .True (t , fh .checkValidAPIKey ())
50
53
@@ -55,18 +58,18 @@ func TestCheckValidAPIKey(t *testing.T) {
55
58
56
59
func TestComputeDomainsURL (t * testing.T ) {
57
60
keysPerDomains := map [string ][]utils.APIKeys {
58
- "https://app.datadoghq.com" : {utils .NewAPIKeys ("" , "api_key1" )},
59
- "https://custom.datadoghq.com" : {utils .NewAPIKeys ("" , "api_key2" )},
60
- "https://custom.agent.datadoghq.com" : {utils .NewAPIKeys ("" , "api_key3" )},
61
- "https://app.datadoghq.eu" : {utils .NewAPIKeys ("" , "api_key4" )},
62
- "https://app.us2.datadoghq.com" : {utils .NewAPIKeys ("" , "api_key5" )},
63
- "https://app.xx9.datadoghq.com" : {utils .NewAPIKeys ("" , "api_key5" )},
64
- "https://custom.agent.us2.datadoghq.com" : {utils .NewAPIKeys ("" , "api_key6" )},
61
+ "https://app.datadoghq.com" : {utils .NewAPIKeys ("path " , "api_key1" )},
62
+ "https://custom.datadoghq.com" : {utils .NewAPIKeys ("path " , "api_key2" )},
63
+ "https://custom.agent.datadoghq.com" : {utils .NewAPIKeys ("path " , "api_key3" )},
64
+ "https://app.datadoghq.eu" : {utils .NewAPIKeys ("path " , "api_key4" )},
65
+ "https://app.us2.datadoghq.com" : {utils .NewAPIKeys ("path " , "api_key5" )},
66
+ "https://app.xx9.datadoghq.com" : {utils .NewAPIKeys ("path " , "api_key5" )},
67
+ "https://custom.agent.us2.datadoghq.com" : {utils .NewAPIKeys ("path " , "api_key6" )},
65
68
// debatable whether the next one should be changed to `api.`, preserve pre-existing behavior for now
66
- "https://app.datadoghq.internal" : {utils .NewAPIKeys ("" , "api_key7" )},
67
- "https://app.myproxy.com" : {utils .NewAPIKeys ("" , "api_key8" )},
68
- "https://app.ddog-gov.com" : {utils .NewAPIKeys ("" , "api_key9" )},
69
- "https://custom.ddog-gov.com" : {utils .NewAPIKeys ("" , "api_key10" )},
69
+ "https://app.datadoghq.internal" : {utils .NewAPIKeys ("path " , "api_key7" )},
70
+ "https://app.myproxy.com" : {utils .NewAPIKeys ("path " , "api_key8" )},
71
+ "https://app.ddog-gov.com" : {utils .NewAPIKeys ("path " , "api_key9" )},
72
+ "https://custom.ddog-gov.com" : {utils .NewAPIKeys ("path " , "api_key10" )},
70
73
}
71
74
72
75
expectedMap := map [string ][]string {
@@ -84,7 +87,9 @@ func TestComputeDomainsURL(t *testing.T) {
84
87
sort .Strings (keys )
85
88
}
86
89
log := logmock .New (t )
87
- fh := forwarderHealth {log : log , domainResolvers : resolver .NewSingleDomainResolvers (keysPerDomains )}
90
+ r , err := resolver .NewSingleDomainResolvers (keysPerDomains )
91
+ require .NoError (t , err )
92
+ fh := forwarderHealth {log : log , domainResolvers : r }
88
93
fh .init ()
89
94
90
95
// lexicographical sort for assert
@@ -166,14 +171,16 @@ func TestUpdateAPIKey(t *testing.T) {
166
171
167
172
// starting API Keys, before the update
168
173
keysPerDomains := map [string ][]utils.APIKeys {
169
- ts1 .URL : {utils .NewAPIKeys ("" , "api_key1" ), utils .NewAPIKeys ("" , "api_key2" )},
170
- ts2 .URL : {utils .NewAPIKeys ("" , "api_key3" )},
174
+ ts1 .URL : {utils .NewAPIKeys ("path " , "api_key1" ), utils .NewAPIKeys ("path " , "api_key2" )},
175
+ ts2 .URL : {utils .NewAPIKeys ("path " , "api_key3" )},
171
176
}
172
177
173
178
log := logmock .New (t )
174
179
cfg := config .NewMock (t )
175
180
176
- fh := forwarderHealth {log : log , config : cfg , domainResolvers : resolver .NewSingleDomainResolvers (keysPerDomains )}
181
+ r , err := resolver .NewSingleDomainResolvers (keysPerDomains )
182
+ require .NoError (t , err )
183
+ fh := forwarderHealth {log : log , config : cfg , domainResolvers : r }
177
184
fh .init ()
178
185
assert .True (t , fh .checkValidAPIKey ())
179
186
0 commit comments