Skip to content

Commit

Permalink
Coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mwear committed Oct 23, 2024
1 parent f0279bb commit 94fd12c
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
40 changes: 40 additions & 0 deletions exporter/otlpexporter/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,46 @@ func TestComponentStatus(t *testing.T) {
})
}
})

t.Run("profiles", func(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ln, err := net.Listen("tcp", "localhost:")
require.NoError(t, err)

rcv, _ := otlpProfilesReceiverOnGRPCServer(ln, false)
rcv.setExportError(tt.exportError)
defer rcv.srv.GracefulStop()

factory := NewFactory()
cfg := factory.CreateDefaultConfig().(*Config)
cfg.QueueConfig.Enabled = false
cfg.ClientConfig = configgrpc.ClientConfig{
Endpoint: ln.Addr().String(),
TLSSetting: configtls.ClientConfig{
Insecure: true,
},
}

set := exportertest.NewNopSettings()
host := &testHost{Host: componenttest.NewNopHost()}

exp, err := factory.(exporterprofiles.Factory).CreateProfiles(context.Background(), set, cfg)
require.NoError(t, err)
require.NotNil(t, exp)
require.NoError(t, exp.Start(context.Background(), host))

defer func() {
assert.NoError(t, exp.Shutdown(context.Background()))
}()

pd := pprofile.NewProfiles()
err = exp.ConsumeProfiles(context.Background(), pd)
assert.Equal(t, tt.componentStatus != componentstatus.StatusOK, err != nil)
assert.Equal(t, tt.componentStatus, host.lastStatus)
})
}
})
}

var _ component.Host = (*testHost)(nil)
Expand Down
39 changes: 39 additions & 0 deletions exporter/otlphttpexporter/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,45 @@ func TestComponentStatus(t *testing.T) {
})
}
})

t.Run("profiles", func(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
srv := createBackend("/v1development/profiles", func(writer http.ResponseWriter, request *http.Request) {
writer.WriteHeader(tt.responseStatus)
})
defer srv.Close()

cfg := &Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: srv.URL,
},
Encoding: EncodingProto,
}

set := exportertest.NewNopSettings()
host := &testHost{
Host: componenttest.NewNopHost(),
}

exp, err := createProfiles(context.Background(), set, cfg)
require.NoError(t, err)

err = exp.Start(context.Background(), host)
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, exp.Shutdown(context.Background()))
})

pd := pprofile.NewProfiles()
err = exp.ConsumeProfiles(context.Background(), pd)
if tt.componentStatus != componentstatus.StatusOK {
require.Error(t, err)
}
assert.Equal(t, tt.componentStatus, host.lastStatus)
})
}
})
}

func createBackend(endpoint string, handler func(writer http.ResponseWriter, request *http.Request)) *httptest.Server {
Expand Down

0 comments on commit 94fd12c

Please sign in to comment.