Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion collector/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ func BuildProfilesReceiver(options ...option) xreceiver.CreateProfilesFunc {
ExecutableReporter: controllerOption.executableReporter,
OnShutdown: controllerOption.onShutdown,
}

err := controlerCfg.Validate()
Comment thread
dmathieu marked this conversation as resolved.
if err != nil {
return nil, err
}
return internal.NewController(controlerCfg, rs, nextConsumer)
}
}
Expand Down
14 changes: 13 additions & 1 deletion collector/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package collector

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -12,6 +13,8 @@ import (
"go.opentelemetry.io/collector/receiver/receivertest"
)

const invalidSamplesPerSecond = 0

func TestNewFactory(t *testing.T) {
f := NewFactory()
require.NotNil(t, f)
Expand All @@ -32,6 +35,11 @@ func TestCreateProfilesReceiver(t *testing.T) {
name: "Nil config",
wantError: errInvalidConfig,
},
{
name: "Invalid config",
config: Config{SamplesPerSecond: invalidSamplesPerSecond},
wantError: fmt.Errorf("invalid sampling frequency: %d", invalidSamplesPerSecond),
},
} {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
Expand All @@ -43,7 +51,11 @@ func TestCreateProfilesReceiver(t *testing.T) {
tt.config,
consumertest.NewNop(),
)
require.ErrorIs(t, err, tt.wantError)

// Handle nil errors
if err != nil || tt.wantError != nil {
require.ErrorAs(t, err, &tt.wantError)
}
Comment on lines +55 to +58
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the back and forth.
But this condition doesn't seem valid. It only checks if there is no error and we expect one.
What if there is an error and we don't expect any?

Suggested change
// Handle nil errors
if err != nil || tt.wantError != nil {
require.ErrorAs(t, err, &tt.wantError)
}
if tt.wantError == nil {
require.NoError(t, err)
} else {
require.ErrorAs(t, err, &tt.wantError)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there is an error and we don't expect any?

if there is an error err != nil is true and so require.ErrorAs(t, err, &tt.wantError) is run.

})
}
}