Skip to content

Commit bde51bf

Browse files
refactor: clean up dead testing code
Improve the testing logic to allow each testcase to specify which part of the logRecord the jmespath query should be executed, rather than deciding it once for all testcases of the test function. Remove unused fields + logic that allowed testing w/ custom functions, since we can do everything with jmespath
1 parent 7cd4fbf commit bde51bf

19 files changed

+263
-139
lines changed

components/processors/observek8sattributesprocessor/configmapactions_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ func TestConfigMapActions(t *testing.T) {
88
name: "ConfigMap data",
99
inLogs: resourceLogsFromSingleJsonEvent("./testdata/configMapEvent.json"),
1010
expectedResults: []queryWithResult{
11-
{"observe_transform.facets.data", int64(1)},
11+
{path: "observe_transform.facets.data", expResult: int64(1)},
1212
},
1313
},
1414
} {
15-
runTest(t, testCase, LogLocationAttributes)
15+
runTest(t, testCase)
1616
}
1717
}

components/processors/observek8sattributesprocessor/cronjobactions_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ func TestCronJobActions(t *testing.T) {
1111
name: "Active CronJob jobs",
1212
inLogs: resourceLogsFromSingleJsonEvent("./testdata/cronJobEvent.json"),
1313
expectedResults: []queryWithResult{
14-
{fmt.Sprintf("observe_transform.facets.%s", CronJobActiveKey), int64(1)},
14+
{path: fmt.Sprintf("observe_transform.facets.%s", CronJobActiveKey), expResult: int64(1)},
1515
},
1616
},
1717
{
1818
name: "Idle CronJob jobs",
1919
inLogs: resourceLogsFromSingleJsonEvent("./testdata/cronJobEventNotActive.json"),
2020
expectedResults: []queryWithResult{
21-
{fmt.Sprintf("observe_transform.facets.%s", CronJobActiveKey), int64(0)},
21+
{path: fmt.Sprintf("observe_transform.facets.%s", CronJobActiveKey), expResult: int64(0)},
2222
},
2323
},
2424
} {
25-
runTest(t, testCase, LogLocationAttributes)
25+
runTest(t, testCase)
2626
}
2727
}

components/processors/observek8sattributesprocessor/daemonsetactions_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ func TestDaemonSetActions(t *testing.T) {
88
name: "Pretty print of a DaemonSet's selector",
99
inLogs: resourceLogsFromSingleJsonEvent("./testdata/daemonSetEvent.json"),
1010
expectedResults: []queryWithResult{
11-
{"observe_transform.facets.selector", "app.kubernetes.io/instance=observe-agent,app.kubernetes.io/name=daemonset-logs-metrics,component=agent-collector"},
11+
{
12+
path: "observe_transform.facets.selector",
13+
expResult: "app.kubernetes.io/instance=observe-agent,app.kubernetes.io/name=daemonset-logs-metrics,component=agent-collector",
14+
},
1215
},
1316
},
1417
} {
15-
runTest(t, testCase, LogLocationAttributes)
18+
runTest(t, testCase)
1619
}
1720
}

components/processors/observek8sattributesprocessor/deploymentactions_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ func TestDeploymentActions(t *testing.T) {
88
name: "Pretty print of a DaemonSet's selector",
99
inLogs: resourceLogsFromSingleJsonEvent("./testdata/deploymentEvent.json"),
1010
expectedResults: []queryWithResult{
11-
{"observe_transform.facets.selector", "app.kubernetes.io/instance=observe-agent,app.kubernetes.io/name=deployment-cluster-events,component=standalone-collector"},
11+
{
12+
path: "observe_transform.facets.selector",
13+
expResult: "app.kubernetes.io/instance=observe-agent,app.kubernetes.io/name=deployment-cluster-events,component=standalone-collector",
14+
},
1215
},
1316
},
1417
} {
15-
runTest(t, testCase, LogLocationAttributes)
18+
runTest(t, testCase)
1619
}
1720
}

components/processors/observek8sattributesprocessor/endpointsactions_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ func TestEndpointsActions(t *testing.T) {
88
name: "Endpoints",
99
inLogs: resourceLogsFromSingleJsonEvent("./testdata/endpointsEvent.json"),
1010
expectedResults: []queryWithResult{
11-
{"observe_transform.facets.endpoints", []any{"10.244.0.53:5432"}},
11+
{
12+
path: "observe_transform.facets.endpoints",
13+
expResult: []any{"10.244.0.53:5432"},
14+
},
1215
},
1316
},
1417
} {
15-
runTest(t, testCase, LogLocationAttributes)
18+
runTest(t, testCase)
1619
}
1720
}

components/processors/observek8sattributesprocessor/ingressactions_test.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ func TestIngressActions(t *testing.T) {
99
inLogs: resourceLogsFromSingleJsonEvent("./testdata/ingressEvent.json"),
1010
expectedResults: []queryWithResult{
1111
{
12-
"observe_transform.facets.rules", []any{
12+
path: "observe_transform.facets.rules",
13+
expResult: []any{
1314
map[string]any{
1415
"host": "prometheus.observe-eng.com",
1516
"httpRules": []any{
@@ -21,14 +22,17 @@ func TestIngressActions(t *testing.T) {
2122
},
2223
},
2324
"path": "/",
24-
}}}}}},
25+
}}}},
26+
},
27+
},
2528
},
2629
{
2730
name: "Ingress rules without host",
2831
inLogs: resourceLogsFromSingleJsonEvent("./testdata/ingressEvent2.json"),
2932
expectedResults: []queryWithResult{
3033
{
31-
"observe_transform.facets.rules", []any{
34+
path: "observe_transform.facets.rules",
35+
expResult: []any{
3236
map[string]any{
3337
"host": "*",
3438
"httpRules": []any{
@@ -53,16 +57,20 @@ func TestIngressActions(t *testing.T) {
5357
"path": "/testpath2",
5458
}},
5559
},
56-
}}},
60+
}},
61+
},
5762
},
5863
{
5964
name: "Load Balancer",
6065
inLogs: resourceLogsFromSingleJsonEvent("./testdata/ingressEvent.json"),
6166
expectedResults: []queryWithResult{
62-
{"observe_transform.facets.loadBalancer", "someUniqueElbIdentifier.elb.us-west-2.amazonaws.com"},
67+
{
68+
path: "observe_transform.facets.loadBalancer",
69+
expResult: "someUniqueElbIdentifier.elb.us-west-2.amazonaws.com",
70+
},
6371
},
6472
},
6573
} {
66-
runTest(t, testCase, LogLocationAttributes)
74+
runTest(t, testCase)
6775
}
6876
}

components/processors/observek8sattributesprocessor/jobactions_test.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,43 @@ func TestJobActions(t *testing.T) {
88
name: "Running Job",
99
inLogs: resourceLogsFromSingleJsonEvent("./testdata/jobRunningEvent.json"),
1010
expectedResults: []queryWithResult{
11-
{"observe_transform.facets.status", "Running"},
11+
{
12+
path: "observe_transform.facets.status",
13+
expResult: "Running",
14+
},
1215
},
1316
},
1417
{
1518
name: "Completed Job",
1619
inLogs: resourceLogsFromSingleJsonEvent("./testdata/jobCompletedEvent.json"),
1720
expectedResults: []queryWithResult{
18-
{"observe_transform.facets.status", "Complete"},
21+
{
22+
path: "observe_transform.facets.status",
23+
expResult: "Complete",
24+
},
1925
},
2026
},
2127
{
2228
name: "Failed Job",
2329
inLogs: resourceLogsFromSingleJsonEvent("./testdata/jobCompletedEvent.json"),
2430
expectedResults: []queryWithResult{
25-
{"observe_transform.facets.status", "Complete"},
31+
{
32+
path: "observe_transform.facets.status",
33+
expResult: "Complete",
34+
},
2635
},
2736
},
2837
{
2938
name: "Duration of completed job",
3039
inLogs: resourceLogsFromSingleJsonEvent("./testdata/jobCompletedEvent.json"),
3140
expectedResults: []queryWithResult{
32-
{"observe_transform.facets.duration", "3m23s"},
41+
{
42+
path: "observe_transform.facets.duration",
43+
expResult: "3m23s",
44+
},
3345
},
3446
},
3547
} {
36-
runTest(t, testCase, LogLocationAttributes)
48+
runTest(t, testCase)
3749
}
3850
}

components/processors/observek8sattributesprocessor/nodeactions_test.go

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ func TestNodeActions(t *testing.T) {
1212
},
1313
),
1414
expectedResults: []queryWithResult{
15-
{"observe_transform.facets.status", "Ready"},
15+
{
16+
path: "observe_transform.facets.status",
17+
expResult: "Ready",
18+
},
1619
},
1720
},
1821
{
@@ -23,7 +26,10 @@ func TestNodeActions(t *testing.T) {
2326
},
2427
),
2528
expectedResults: []queryWithResult{
26-
{"observe_transform.facets.status", "NotReady"},
29+
{
30+
path: "observe_transform.facets.status",
31+
expResult: "NotReady",
32+
},
2733
},
2834
},
2935
{
@@ -34,8 +40,13 @@ func TestNodeActions(t *testing.T) {
3440
},
3541
),
3642
expectedResults: []queryWithResult{
37-
{"observe_transform.facets.roles | length(@)", float64(1)},
38-
{"observe_transform.facets.roles[0]", "control-plane"},
43+
{
44+
path: "observe_transform.facets.roles | length(@)",
45+
expResult: float64(1)},
46+
{
47+
path: "observe_transform.facets.roles[0]",
48+
expResult: "control-plane",
49+
},
3950
},
4051
},
4152
{
@@ -46,8 +57,13 @@ func TestNodeActions(t *testing.T) {
4657
},
4758
),
4859
expectedResults: []queryWithResult{
49-
{"observe_transform.facets.roles | length(@)", float64(2)},
50-
{"observe_transform.facets.roles", []any{"anotherRole!", "control-plane"}},
60+
{
61+
path: "observe_transform.facets.roles | length(@)",
62+
expResult: float64(2)},
63+
{
64+
path: "observe_transform.facets.roles",
65+
expResult: []any{"anotherRole!", "control-plane"},
66+
},
5167
},
5268
},
5369
{
@@ -58,11 +74,14 @@ func TestNodeActions(t *testing.T) {
5874
},
5975
),
6076
expectedResults: []queryWithResult{
61-
{"observe_transform.facets.nodePool", "test-node-group"},
77+
{
78+
path: "observe_transform.facets.nodePool",
79+
expResult: "test-node-group",
80+
},
6281
},
6382
},
6483
} {
65-
runTest(t, testCase, LogLocationAttributes)
84+
runTest(t, testCase)
6685
}
6786

6887
}

components/processors/observek8sattributesprocessor/persistentvolumeactions_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,23 @@ func TestPersistentVolumeActions(t *testing.T) {
88
name: "Extract PersistentVolume type (AWSElasticBlockStore)",
99
inLogs: resourceLogsFromSingleJsonEvent("./testdata/persistentVolumeAWSElasticBlockStoreEvent.json"),
1010
expectedResults: []queryWithResult{
11-
{"observe_transform.facets.volumeType", "AWSElasticBlockStore"},
11+
{
12+
path: "observe_transform.facets.volumeType",
13+
expResult: "AWSElasticBlockStore",
14+
},
1215
},
1316
},
1417
{
1518
name: "Extract PersistentVolume type (HostPath)",
1619
inLogs: resourceLogsFromSingleJsonEvent("./testdata/persistentVolumeHostPathEvent.json"),
1720
expectedResults: []queryWithResult{
18-
{"observe_transform.facets.volumeType", "HostPath"},
21+
{
22+
path: "observe_transform.facets.volumeType",
23+
expResult: "HostPath",
24+
},
1925
},
2026
},
2127
} {
22-
runTest(t, testCase, LogLocationAttributes)
28+
runTest(t, testCase)
2329
}
2430
}

components/processors/observek8sattributesprocessor/persistentvolumeclaimactions_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ func TestPersistentVolumeClaimActions(t *testing.T) {
88
name: "Pretty print of a PersistentVolumeClaim's selector",
99
inLogs: resourceLogsFromSingleJsonEvent("./testdata/persistentVolumeClaimEvent.json"),
1010
expectedResults: []queryWithResult{
11-
{"observe_transform.facets.selector", "environment in (production,staging),storage-tier=high-performance"},
11+
{
12+
path: "observe_transform.facets.selector",
13+
expResult: "environment in (production,staging),storage-tier=high-performance",
14+
},
1215
},
1316
},
1417
} {
15-
runTest(t, testCase, LogLocationAttributes)
18+
runTest(t, testCase)
1619
}
1720
}

0 commit comments

Comments
 (0)