Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
Implement PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrod1598 committed Jun 15, 2021
1 parent 40a2455 commit 6a2bc34
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
4 changes: 4 additions & 0 deletions agent/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ func (b *LogAgentBuilder) Build() (*LogAgent, error) {
b.config = cfgs
}

if len(b.config.Pipeline) == 0 {
return nil, errors.NewError("empty pipeline not allowed", "")
}

sampledLogger := b.logger.Desugar().WithOptions(
zap.WrapCore(func(core zapcore.Core) zapcore.Core {
return zapcore.NewSamplerWithOptions(core, time.Second, 1, 10000)
Expand Down
42 changes: 25 additions & 17 deletions agent/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ import (
)

func TestBuildAgentSuccess(t *testing.T) {
mockCfg := Config{}
mockCfg := Config{
[]operator.Config{
{
Builder: noop.NewNoopOperatorConfig("noop"),
},
},
}
mockLogger := zap.NewNop().Sugar()
mockPluginDir := "/some/path/plugins"

Expand All @@ -41,10 +47,10 @@ func TestBuildAgentSuccess(t *testing.T) {
func TestBuildAgentDefaultOperator(t *testing.T) {
mockCfg := Config{
[]operator.Config{
operator.Config{
{
Builder: noop.NewNoopOperatorConfig("noop"),
},
operator.Config{
{
Builder: noop.NewNoopOperatorConfig("noop1"),
},
},
Expand All @@ -67,36 +73,38 @@ func TestBuildAgentDefaultOperator(t *testing.T) {
exists := make(map[string]bool)

for _, op := range ops {
if op.ID() == "$.noop" {
require.Equal(t, 1, len(ops[0].GetOutputIDs()))
require.Equal(t, "$.noop1", ops[0].GetOutputIDs()[0])
switch op.ID() {
case "$.noop":
require.Equal(t, 1, len(op.GetOutputIDs()))
require.Equal(t, "$.noop1", op.GetOutputIDs()[0])
exists["$.noop"] = true
} else if op.ID() == "$.noop1" {
require.Equal(t, 1, len(ops[1].GetOutputIDs()))
require.Equal(t, "$.fake", ops[1].GetOutputIDs()[0])
case "$.noop1":
require.Equal(t, 1, len(op.GetOutputIDs()))
require.Equal(t, "$.fake", op.GetOutputIDs()[0])
exists["$.noop1"] = true
} else if op.ID() == "$.fake" {
require.Equal(t, 0, len(ops[2].GetOutputIDs()))
case "$.fake":
require.Equal(t, 0, len(op.GetOutputIDs()))
exists["$.fake"] = true
}
}
require.Equal(t, true, exists["$.noop"])
require.Equal(t, true, exists["$.noop1"])
require.Equal(t, true, exists["$.fake"])
require.True(t, exists["$.noop"])
require.True(t, exists["$.noop1"])
require.True(t, exists["$.fake"])
}

func TestBuildAgentFailureOnPluginRegistry(t *testing.T) {
mockCfg := Config{}
mockLogger := zap.NewNop().Sugar()
mockPluginDir := "[]"
mockOutput := testutil.NewFakeOutput(t)

_, err := NewBuilder(mockLogger).
agent, err := NewBuilder(mockLogger).
WithConfig(&mockCfg).
WithPluginDir(mockPluginDir).
WithDefaultOutput(mockOutput).
Build()
require.NoError(t, err)
require.Error(t, err)
require.Contains(t, err.Error(), "empty pipeline not allowed")
require.Nil(t, agent)
}

func TestBuildAgentFailureNoConfigOrGlobs(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions pipeline/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ func (c Config) BuildOperators(bc operator.BuildContext, defaultOperator operato
operators = append(operators, op...)
}

if defaultOperator != nil {
bc.DefaultOutputIDs = []string{defaultOperator.ID()}
if defaultOperator != nil && operators[len(operators)-1].CanOutput() {
operators = append(operators, defaultOperator)
}

Expand Down

0 comments on commit 6a2bc34

Please sign in to comment.