From 8e0c7a7e0072e964e806ac313d17181ccf68dde1 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Tue, 28 Jan 2025 10:03:54 +0100 Subject: [PATCH] unit tests Signed-off-by: odubajDT --- .../internal/resourcedetection_test.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/processor/resourcedetectionprocessor/internal/resourcedetection_test.go b/processor/resourcedetectionprocessor/internal/resourcedetection_test.go index 4d1f84503d48..f1dfb1d40482 100644 --- a/processor/resourcedetectionprocessor/internal/resourcedetection_test.go +++ b/processor/resourcedetectionprocessor/internal/resourcedetection_test.go @@ -42,6 +42,7 @@ func TestDetect(t *testing.T) { detectedResources []map[string]any expectedResource map[string]any attributes []string + keepOrder bool }{ { name: "Detect three resources", @@ -52,6 +53,7 @@ func TestDetect(t *testing.T) { }, expectedResource: map[string]any{"a": "1", "b": "2", "c": "3"}, attributes: nil, + keepOrder: true, }, { name: "Detect empty resources", detectedResources: []map[string]any{ @@ -61,6 +63,7 @@ func TestDetect(t *testing.T) { }, expectedResource: map[string]any{"a": "1", "b": "2"}, attributes: nil, + keepOrder: true, }, { name: "Detect non-string resources", detectedResources: []map[string]any{ @@ -70,6 +73,7 @@ func TestDetect(t *testing.T) { }, expectedResource: map[string]any{"a": "11", "bool": true, "int": int64(2), "double": 0.5}, attributes: nil, + keepOrder: true, }, { name: "Filter to one attribute", detectedResources: []map[string]any{ @@ -79,6 +83,17 @@ func TestDetect(t *testing.T) { }, expectedResource: map[string]any{"a": "1"}, attributes: []string{"a"}, + keepOrder: true, + }, { + name: "Detect resources without order", + detectedResources: []map[string]any{ + {"a": "1", "b": "2"}, + {"c": "3"}, + {"d": "3"}, + }, + expectedResource: map[string]any{"a": "1", "b": "2", "c": "3", "d": "3"}, + attributes: nil, + keepOrder: false, }, } @@ -101,7 +116,7 @@ func TestDetect(t *testing.T) { } f := NewProviderFactory(mockDetectors) - p, err := f.CreateResourceProvider(processortest.NewNopSettings(), time.Second, tt.attributes, &mockDetectorConfig{}, true, mockDetectorTypes...) + p, err := f.CreateResourceProvider(processortest.NewNopSettings(), time.Second, tt.attributes, &mockDetectorConfig{}, tt.keepOrder, mockDetectorTypes...) require.NoError(t, err) got, _, err := p.Get(context.Background(), http.DefaultClient)