Skip to content

Commit 24a84b3

Browse files
[chore, tests] configuration_switching tests improvements (#1593)
1 parent 0531376 commit 24a84b3

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

functional_tests/configuration_switching/configuration_switching_test.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ import (
1515
"text/template"
1616
"time"
1717

18-
"go.opentelemetry.io/collector/pdata/plog"
19-
"go.opentelemetry.io/collector/pdata/pmetric"
20-
"gopkg.in/yaml.v3"
21-
2218
"github.com/stretchr/testify/assert"
2319
"github.com/stretchr/testify/require"
2420
"go.opentelemetry.io/collector/consumer/consumertest"
21+
"go.opentelemetry.io/collector/pdata/plog"
22+
"go.opentelemetry.io/collector/pdata/pmetric"
23+
"gopkg.in/yaml.v3"
2524
"helm.sh/helm/v3/pkg/action"
2625
"helm.sh/helm/v3/pkg/kube"
2726
corev1 "k8s.io/api/core/v1"
@@ -258,8 +257,15 @@ func testIndexSwitch(t *testing.T) {
258257
var indices []string
259258
logs := agentLogsConsumer.AllLogs()
260259
sourcetypes, indices = getLogsIndexAndSourceType(logs)
261-
assert.True(t, len(sourcetypes) > 1) // we are also receiving logs from other kind containers
262-
assert.Contains(t, sourcetypes, "kube:container:kindnet-cni")
260+
assert.Greater(t, len(sourcetypes), 1) // we are receiving logs from different containers
261+
// check sourcetypes have same prefix
262+
prefix := "kube:container:"
263+
for _, element := range sourcetypes {
264+
if !strings.HasPrefix(element, prefix) {
265+
t.Errorf("Element does not start with the prefix %q: %s", prefix, element)
266+
}
267+
}
268+
assert.NotContains(t, sourcetypes, nonDefaultSourcetype)
263269
assert.True(t, len(indices) == 1)
264270
assert.True(t, indices[0] == logsIndex)
265271

@@ -278,7 +284,6 @@ func testIndexSwitch(t *testing.T) {
278284
internal.ResetLogsSink(t, agentLogsConsumer)
279285
internal.ResetMetricsSink(t, hecMetricsConsumer)
280286

281-
internal.WaitForMetrics(t, 3, hecMetricsConsumer)
282287
internal.WaitForLogs(t, 3, agentLogsConsumer)
283288
logs = agentLogsConsumer.AllLogs()
284289
sourcetypes, indices = getLogsIndexAndSourceType(logs)
@@ -287,6 +292,8 @@ func testIndexSwitch(t *testing.T) {
287292
assert.Contains(t, sourcetypes, nonDefaultSourcetype)
288293
assert.True(t, len(indices) == 1)
289294
assert.True(t, len(sourcetypes) == 1)
295+
296+
internal.WaitForMetrics(t, 3, hecMetricsConsumer)
290297
mIndices = getMetricsIndex(hecMetricsConsumer.AllMetrics())
291298
assert.True(t, len(mIndices) == 1)
292299
assert.True(t, mIndices[0] == newMetricsIndex)
@@ -307,6 +314,7 @@ func testClusterReceiverEnabledOrDisabled(t *testing.T) {
307314
logsObjectsHecEndpoint := fmt.Sprintf("http://%s:%d/services/collector", hostEp, internal.HECObjectsReceiverPort)
308315

309316
t.Run("check cluster receiver enabled", func(t *testing.T) {
317+
internal.ResetLogsSink(t, logsObjectsConsumer)
310318
replacements := map[string]interface{}{
311319
"ClusterReceiverEnabled": false,
312320
"LogObjectsHecEndpoint": logsObjectsHecEndpoint,

0 commit comments

Comments
 (0)