Skip to content

Commit 3c60e37

Browse files
committed
updat tests
1 parent 440ebe4 commit 3c60e37

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

receiver/mongodbatlasreceiver/config.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"strings"
1212
"time"
1313

14-
"go.mongodb.org/atlas/mongodbatlas"
1514
"go.opentelemetry.io/collector/component"
1615
"go.opentelemetry.io/collector/config/configopaque"
1716
"go.opentelemetry.io/collector/config/configretry"
@@ -140,10 +139,6 @@ var (
140139
func (c *Config) Validate() error {
141140
var errs error
142141

143-
if c.BaseURL == "" {
144-
c.BaseURL = mongodbatlas.CloudURL
145-
}
146-
147142
if err := validateEndpoint(c.BaseURL); err != nil {
148143
return fmt.Errorf("invalid base_url %q: %w", c.BaseURL, err)
149144
}

receiver/mongodbatlasreceiver/config_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/stretchr/testify/require"
12+
"go.mongodb.org/atlas/mongodbatlas"
1213
"go.opentelemetry.io/collector/component"
1314
"go.opentelemetry.io/collector/config/configtls"
1415
"go.opentelemetry.io/collector/confmap/confmaptest"
@@ -28,12 +29,14 @@ func TestValidate(t *testing.T) {
2829
{
2930
name: "Empty config",
3031
input: Config{
32+
BaseURL: mongodbatlas.CloudURL,
3133
ControllerConfig: scraperhelper.NewDefaultControllerConfig(),
3234
},
3335
},
3436
{
3537
name: "Valid alerts config",
3638
input: Config{
39+
BaseURL: mongodbatlas.CloudURL,
3740
Alerts: AlertConfig{
3841
Enabled: true,
3942
Endpoint: "0.0.0.0:7706",
@@ -46,6 +49,7 @@ func TestValidate(t *testing.T) {
4649
{
4750
name: "Alerts missing endpoint",
4851
input: Config{
52+
BaseURL: mongodbatlas.CloudURL,
4953
Alerts: AlertConfig{
5054
Enabled: true,
5155
Secret: "some_secret",
@@ -58,6 +62,7 @@ func TestValidate(t *testing.T) {
5862
{
5963
name: "Alerts missing secret",
6064
input: Config{
65+
BaseURL: mongodbatlas.CloudURL,
6166
Alerts: AlertConfig{
6267
Enabled: true,
6368
Endpoint: "0.0.0.0:7706",
@@ -70,6 +75,7 @@ func TestValidate(t *testing.T) {
7075
{
7176
name: "Invalid endpoint",
7277
input: Config{
78+
BaseURL: mongodbatlas.CloudURL,
7379
Alerts: AlertConfig{
7480
Enabled: true,
7581
Endpoint: "7706",
@@ -83,6 +89,7 @@ func TestValidate(t *testing.T) {
8389
{
8490
name: "TLS config missing key",
8591
input: Config{
92+
BaseURL: mongodbatlas.CloudURL,
8693
Alerts: AlertConfig{
8794
Enabled: true,
8895
Endpoint: "0.0.0.0:7706",
@@ -101,6 +108,7 @@ func TestValidate(t *testing.T) {
101108
{
102109
name: "TLS config missing cert",
103110
input: Config{
111+
BaseURL: mongodbatlas.CloudURL,
104112
Alerts: AlertConfig{
105113
Enabled: true,
106114
Endpoint: "0.0.0.0:7706",
@@ -119,6 +127,7 @@ func TestValidate(t *testing.T) {
119127
{
120128
name: "Valid Metrics Config",
121129
input: Config{
130+
BaseURL: mongodbatlas.CloudURL,
122131
Projects: []*ProjectConfig{
123132
{
124133
Name: "Project1",
@@ -130,6 +139,7 @@ func TestValidate(t *testing.T) {
130139
{
131140
name: "Valid Metrics Config with multiple projects with an inclusion or exclusion",
132141
input: Config{
142+
BaseURL: mongodbatlas.CloudURL,
133143
Projects: []*ProjectConfig{
134144
{
135145
Name: "Project1",
@@ -146,6 +156,7 @@ func TestValidate(t *testing.T) {
146156
{
147157
name: "invalid Metrics Config",
148158
input: Config{
159+
BaseURL: mongodbatlas.CloudURL,
149160
Projects: []*ProjectConfig{
150161
{
151162
Name: "Project1",
@@ -160,6 +171,7 @@ func TestValidate(t *testing.T) {
160171
{
161172
name: "Valid Logs Config",
162173
input: Config{
174+
BaseURL: mongodbatlas.CloudURL,
163175
Logs: LogConfig{
164176
Enabled: true,
165177
Projects: []*LogsProjectConfig{
@@ -177,6 +189,7 @@ func TestValidate(t *testing.T) {
177189
{
178190
name: "Invalid Logs Config",
179191
input: Config{
192+
BaseURL: mongodbatlas.CloudURL,
180193
Logs: LogConfig{
181194
Enabled: true,
182195
},
@@ -187,6 +200,7 @@ func TestValidate(t *testing.T) {
187200
{
188201
name: "Invalid ProjectConfig",
189202
input: Config{
203+
BaseURL: mongodbatlas.CloudURL,
190204
Logs: LogConfig{
191205
Enabled: true,
192206
Projects: []*LogsProjectConfig{
@@ -207,6 +221,7 @@ func TestValidate(t *testing.T) {
207221
{
208222
name: "Invalid Alerts Retrieval ProjectConfig",
209223
input: Config{
224+
BaseURL: mongodbatlas.CloudURL,
210225
Alerts: AlertConfig{
211226
Enabled: true,
212227
Mode: alertModePoll,
@@ -226,6 +241,7 @@ func TestValidate(t *testing.T) {
226241
{
227242
name: "Invalid Alerts Poll No Projects",
228243
input: Config{
244+
BaseURL: mongodbatlas.CloudURL,
229245
Alerts: AlertConfig{
230246
Enabled: true,
231247
Mode: alertModePoll,
@@ -239,6 +255,7 @@ func TestValidate(t *testing.T) {
239255
{
240256
name: "Valid Alerts Config",
241257
input: Config{
258+
BaseURL: mongodbatlas.CloudURL,
242259
Alerts: AlertConfig{
243260
Enabled: true,
244261
Mode: alertModePoll,
@@ -255,6 +272,7 @@ func TestValidate(t *testing.T) {
255272
{
256273
name: "Invalid Alerts Mode",
257274
input: Config{
275+
BaseURL: mongodbatlas.CloudURL,
258276
Alerts: AlertConfig{
259277
Enabled: true,
260278
Mode: "invalid type",
@@ -267,6 +285,7 @@ func TestValidate(t *testing.T) {
267285
{
268286
name: "Invalid Page Size",
269287
input: Config{
288+
BaseURL: mongodbatlas.CloudURL,
270289
Alerts: AlertConfig{
271290
Enabled: true,
272291
Mode: alertModePoll,
@@ -284,6 +303,7 @@ func TestValidate(t *testing.T) {
284303
{
285304
name: "Invalid events config - no projects",
286305
input: Config{
306+
BaseURL: mongodbatlas.CloudURL,
287307
Events: &EventsConfig{
288308
Projects: []*ProjectConfig{},
289309
},
@@ -294,6 +314,7 @@ func TestValidate(t *testing.T) {
294314
{
295315
name: "Valid Access Logs Config",
296316
input: Config{
317+
BaseURL: mongodbatlas.CloudURL,
297318
Logs: LogConfig{
298319
Projects: []*LogsProjectConfig{
299320
{
@@ -314,6 +335,7 @@ func TestValidate(t *testing.T) {
314335
{
315336
name: "Invalid Access Logs Config - bad project config",
316337
input: Config{
338+
BaseURL: mongodbatlas.CloudURL,
317339
Logs: LogConfig{
318340
Enabled: true,
319341
Projects: []*LogsProjectConfig{

0 commit comments

Comments
 (0)