From 94fd12cbc29bf12879716794c7fbe24f1fb607b0 Mon Sep 17 00:00:00 2001 From: "matt.wear" Date: Wed, 23 Oct 2024 16:51:26 -0700 Subject: [PATCH] Coverage --- exporter/otlpexporter/otlp_test.go | 40 ++++++++++++++++++++++++++ exporter/otlphttpexporter/otlp_test.go | 39 +++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/exporter/otlpexporter/otlp_test.go b/exporter/otlpexporter/otlp_test.go index 4f4fb32e5d7..adc3cc5feb9 100644 --- a/exporter/otlpexporter/otlp_test.go +++ b/exporter/otlpexporter/otlp_test.go @@ -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) diff --git a/exporter/otlphttpexporter/otlp_test.go b/exporter/otlphttpexporter/otlp_test.go index 3a1b049d826..e1eae066100 100644 --- a/exporter/otlphttpexporter/otlp_test.go +++ b/exporter/otlphttpexporter/otlp_test.go @@ -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 {