integrationtest/TestCpuProfile: Validate json output
@@ -27,6 +27,7 @@ import (
"time"
. "github.com/inspektor-gadget/inspektor-gadget/integration"
+ cpuprofileTypes "github.com/inspektor-gadget/inspektor-gadget/pkg/gadgets/profile/cpu/types"
processCollectorTypes "github.com/inspektor-gadget/inspektor-gadget/pkg/gadgets/snapshot/process/types"
socketCollectorTypes "github.com/inspektor-gadget/inspektor-gadget/pkg/gadgets/snapshot/socket/types"
biotopTypes "github.com/inspektor-gadget/inspektor-gadget/pkg/gadgets/top/block-io/types"
@@ -1116,8 +1117,8 @@ func TestProcessCollector(t *testing.T) {
RunCommands(commands, t)
}
-func TestProfile(t *testing.T) {
- ns := GenerateTestNamespaceName("test-profile")
+func TestCpuProfile(t *testing.T) {
+ ns := GenerateTestNamespaceName("test-cpu-profile")
t.Parallel()
@@ -1127,8 +1128,23 @@ func TestProfile(t *testing.T) {
WaitUntilTestPodReadyCommand(ns),
{
Name: "RunProfileGadget",
- Cmd: fmt.Sprintf("$KUBECTL_GADGET profile cpu -n %s -p test-pod -K --timeout 15", ns),
- ExpectedRegexp: fmt.Sprintf(`%s\s+test-pod\s+test-pod\s+\d+\s+sh\s+\d`, ns), // echo is builtin.
+ Cmd: fmt.Sprintf("$KUBECTL_GADGET profile cpu -n %s -p test-pod -K --timeout 15 -o json", ns),
+ ExpectedOutputFn: func(output string) error {
+ expectedEntry := &cpuprofileTypes.Report{
+ CommonData: BuildCommonData(ns),
+ Comm: "sh",
+ }
+
+ normalize := func(e *cpuprofileTypes.Report) {
+ e.Node = ""
+ e.Pid = 0
+ e.UserStack = nil
+ e.KernelStack = nil
+ e.Count = 0
+ }
+
+ return ExpectEntriesToMatch(output, normalize, expectedEntry)
+ },
},
DeleteTestNamespaceCommand(ns),
}
