Skip to content

Commit

Permalink
PR suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
gh123man committed Dec 18, 2023
1 parent 7d8abfd commit 099a6c1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
3 changes: 3 additions & 0 deletions comp/logs/agent/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ type ServerlessLogsAgent interface {
// Mock implements mock-specific methods.
type Mock interface {
Component

SetSources(sources *sources.LogSources)
AsComponent() Component
}

// Module defines the fx options for this component.
Expand Down
23 changes: 10 additions & 13 deletions comp/logs/agent/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import (
"context"
"time"

"go.uber.org/fx"

"github.com/DataDog/datadog-agent/pkg/logs/diagnostic"
"github.com/DataDog/datadog-agent/pkg/logs/pipeline"
"github.com/DataDog/datadog-agent/pkg/logs/schedulers"
"github.com/DataDog/datadog-agent/pkg/logs/sources"
"github.com/DataDog/datadog-agent/pkg/util/optional"
"go.uber.org/fx"
)

type mockLogsAgent struct {
Expand All @@ -39,18 +40,6 @@ func newMock(deps dependencies) optional.Option[Mock] {
return optional.NewOption[Mock](logsAgent)
}

// NewMock can be used in other packages using the log agent as a dependency.
func NewMock(logSources *sources.LogSources) optional.Option[Component] {
logsAgent := &mockLogsAgent{
hasFlushed: false,
addedSchedulers: make([]schedulers.Scheduler, 0),
isRunning: false,
flushDelay: 0,
logSources: logSources,
}
return optional.NewOption[Component](logsAgent)
}

func (a *mockLogsAgent) start(context.Context) error {
a.isRunning = true
return nil
Expand All @@ -73,6 +62,10 @@ func (a *mockLogsAgent) GetMessageReceiver() *diagnostic.BufferedMessageReceiver
return nil
}

func (a *mockLogsAgent) SetSources(sources *sources.LogSources) {
a.logSources = sources
}

func (a *mockLogsAgent) GetSources() *sources.LogSources {
return a.logSources
}
Expand All @@ -98,3 +91,7 @@ func (a *mockLogsAgent) Flush(ctx context.Context) {
func (a *mockLogsAgent) GetPipelineProvider() pipeline.Provider {
return nil
}

func (a *mockLogsAgent) AsComponent() Component {
return a
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import (
"github.com/stretchr/testify/mock"
"go.uber.org/fx"

"github.com/DataDog/datadog-agent/comp/core"
"github.com/DataDog/datadog-agent/comp/core/config"
"github.com/DataDog/datadog-agent/comp/core/log/logimpl"
logagent "github.com/DataDog/datadog-agent/comp/logs/agent"
logConfig "github.com/DataDog/datadog-agent/comp/logs/agent/config"
"github.com/DataDog/datadog-agent/comp/metadata/inventoryagent"
"github.com/DataDog/datadog-agent/pkg/collector"
"github.com/DataDog/datadog-agent/pkg/collector/check"
checkid "github.com/DataDog/datadog-agent/pkg/collector/check/id"
Expand Down Expand Up @@ -137,11 +139,13 @@ func TestGetPayload(t *testing.T) {
Source: "redis",
})
logSources.AddSource(src)
mockLogAgent := logagent.NewMock(logSources)
mockLogAgent := fxutil.Test[optional.Option[logagent.Mock]](t, logagent.MockModule(), core.MockBundle(), inventoryagent.MockModule())
logsAgent, _ := mockLogAgent.Get()
logsAgent.SetSources(logSources)

ic := getTestInventoryChecks(t,
optional.NewOption[collector.Collector](mockColl),
mockLogAgent,
optional.NewOption[logagent.Component](logsAgent.AsComponent()),
overrides,
)

Expand Down

0 comments on commit 099a6c1

Please sign in to comment.