Skip to content

Commit

Permalink
[chore][pkg/stanza] Cleanup noop operator files (#32065)
Browse files Browse the repository at this point in the history
Contributes to #32058
  • Loading branch information
djaglowski authored Apr 2, 2024
1 parent 15581e4 commit a210907
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
package noop // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/transformer/noop"

import (
"context"

"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/entry"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/helper"
)
Expand Down Expand Up @@ -47,14 +44,3 @@ func (c Config) Build(logger *zap.SugaredLogger) (operator.Operator, error) {
TransformerOperator: transformerOperator,
}, nil
}

// Transformer is an operator that performs no operations on an entry.
type Transformer struct {
helper.TransformerOperator
}

// Process will forward the entry to the next output without any alterations.
func (p *Transformer) Process(ctx context.Context, entry *entry.Entry) error {
p.Write(ctx, entry)
return nil
}
26 changes: 26 additions & 0 deletions pkg/stanza/operator/transformer/noop/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package noop

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/testutil"
)

func TestBuildValid(t *testing.T) {
cfg := NewConfigWithID("test")
op, err := cfg.Build(testutil.Logger(t))
require.NoError(t, err)
require.IsType(t, &Transformer{}, op)
}

func TestBuildInvalid(t *testing.T) {
cfg := NewConfigWithID("test")
_, err := cfg.Build(nil)
require.Error(t, err)
require.Contains(t, err.Error(), "build context is missing a logger")
}
22 changes: 22 additions & 0 deletions pkg/stanza/operator/transformer/noop/transformer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package noop // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/transformer/noop"

import (
"context"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/entry"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/helper"
)

// Transformer is an operator that performs no operations on an entry.
type Transformer struct {
helper.TransformerOperator
}

// Process will forward the entry to the next output without any alterations.
func (t *Transformer) Process(ctx context.Context, entry *entry.Entry) error {
t.Write(ctx, entry)
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,6 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/testutil"
)

func TestBuildValid(t *testing.T) {
cfg := NewConfigWithID("test")
op, err := cfg.Build(testutil.Logger(t))
require.NoError(t, err)
require.IsType(t, &Transformer{}, op)
}

func TestBuildInvalid(t *testing.T) {
cfg := NewConfigWithID("test")
_, err := cfg.Build(nil)
require.Error(t, err)
require.Contains(t, err.Error(), "build context is missing a logger")
}

func TestProcess(t *testing.T) {
cfg := NewConfigWithID("test")
cfg.OutputIDs = []string{"fake"}
Expand Down

0 comments on commit a210907

Please sign in to comment.