Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <ondrej.dubaj@dynatrace.com>
  • Loading branch information
odubajDT committed Jan 28, 2025
1 parent 28ef9e4 commit 8e0c7a7
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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,
},
}

Expand All @@ -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)
Expand Down

0 comments on commit 8e0c7a7

Please sign in to comment.