Skip to content

Commit

Permalink
fix 2
Browse files Browse the repository at this point in the history
  • Loading branch information
jj22ee committed Nov 14, 2024
1 parent 87eefad commit 83cc4eb
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion exporter/awscloudwatchlogsexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/cwlogs"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/exporter/exportertest"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/plog"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/cwlogs"
)

func init() {
Expand Down Expand Up @@ -464,6 +465,47 @@ func TestConsumeLogs(t *testing.T) {
}
}

// Remove the following test in OCB branch as upstream "internal/aws/cwlogs" is depended on
// as opposed to the forked version. This means the "exp.start(ctx, host)" method that was added
// in the fork is not available to test in the OCB branch.
// func TestMiddleware(t *testing.T) {
// testType, _ := component.NewType("test")
// id := component.NewID(testType)
// ctx, cancel := context.WithCancel(context.Background())
// defer cancel()
// factory := NewFactory()
// expCfg := factory.CreateDefaultConfig().(*Config)
// expCfg.Region = "us-west-2"
// expCfg.LogGroupName = "testGroup"
// expCfg.LogStreamName = "testStream"
// expCfg.MaxRetries = 0
// expCfg.MiddlewareID = &id
// handler := new(awsmiddleware.MockHandler)
// handler.On("ID").Return("test")
// handler.On("Position").Return(awsmiddleware.After)
// handler.On("HandleRequest", mock.Anything, mock.Anything)
// handler.On("HandleResponse", mock.Anything, mock.Anything)
// middleware := new(awsmiddleware.MockMiddlewareExtension)
// middleware.On("Handlers").Return([]awsmiddleware.RequestHandler{handler}, []awsmiddleware.ResponseHandler{handler})
// extensions := map[component.ID]component.Component{id: middleware}
// exp, err := newCwLogsPusher(expCfg, exportertest.NewNopSettings())
// assert.Nil(t, err)
// assert.NotNil(t, exp)
// host := new(awsmiddleware.MockExtensionsHost)
// host.On("GetExtensions").Return(extensions)
// assert.NoError(t, exp.start(ctx, host))
// ld := plog.NewLogs()
// r := ld.ResourceLogs().AppendEmpty()
// r.Resource().Attributes().PutStr("hello", "test")
// logRecords := r.ScopeLogs().AppendEmpty().LogRecords()
// logRecords.EnsureCapacity(5)
// logRecords.AppendEmpty()
// require.Error(t, exp.consumeLogs(ctx, ld))
// require.NoError(t, exp.shutdown(ctx))
// handler.AssertCalled(t, "HandleRequest", mock.Anything, mock.Anything)
// handler.AssertCalled(t, "HandleResponse", mock.Anything, mock.Anything)
// }

func TestNewExporterWithoutRegionErr(t *testing.T) {
factory := NewFactory()
expCfg := factory.CreateDefaultConfig().(*Config)
Expand Down

0 comments on commit 83cc4eb

Please sign in to comment.