Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move more tests to assertions in functional tests #1142

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions functional_tests/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,16 @@ func testAgentLogs(t *testing.T) {
assert.True(t, excludePods, "excluded pods should be ignored")
assert.True(t, excludeNs, "excluded namespaces should be ignored")
})
t.Run("check default metadata is attached to all the logs", func(t *testing.T) {
_, ok := helloWorldLogRecord.Attributes().Get("k8s.pod.name")
assert.True(t, ok)
_, ok = helloWorldLogRecord.Attributes().Get("k8s.namespace.name")
assert.True(t, ok)
_, ok = helloWorldLogRecord.Attributes().Get("k8s.container.name")
assert.True(t, ok)
_, ok = helloWorldLogRecord.Attributes().Get("k8s.pod.uid")
assert.True(t, ok)
})
}

func testK8sObjects(t *testing.T) {
Expand All @@ -780,6 +790,8 @@ func testK8sObjects(t *testing.T) {

var kinds []string
var sourceTypes []string
foundCustomField1 := false
foundCustomField2 := false

for i := 0; i < len(logsObjectsConsumer.AllLogs()); i++ {
l := logsObjectsConsumer.AllLogs()[i]
Expand All @@ -794,11 +806,18 @@ func testK8sObjects(t *testing.T) {
kinds = append(kinds, kind.AsString())
}
}
if value, ok := logRecord.Attributes().Get("customfield1"); ok && value.AsString() == "customvalue1" {
foundCustomField1 = true
}
if value, ok := logRecord.Attributes().Get("customfield2"); ok && value.AsString() == "customvalue2" {
foundCustomField2 = true
}
}
}
if value, ok := rl.Resource().Attributes().Get("com.splunk.sourcetype"); ok {
sourceTypes = append(sourceTypes, value.AsString())
}

}
}

Expand All @@ -809,6 +828,9 @@ func testK8sObjects(t *testing.T) {
assert.Contains(t, sourceTypes, "kube:object:pods")
assert.Contains(t, sourceTypes, "kube:object:namespaces")
assert.Contains(t, sourceTypes, "kube:object:nodes")

assert.True(t, foundCustomField1)
assert.True(t, foundCustomField2)
}

func testAgentMetrics(t *testing.T) {
Expand Down
Loading
Loading