PT-2453 - Add -skip-pod-summary for pt-k8s-debug-collector

- Added test case
This commit is contained in:
Sveta Smirnova
2025-06-09 16:46:40 +03:00
parent 6e7a867fed
commit 554d8294e1

View File

@@ -365,6 +365,106 @@ func TestSSLResourceOption(t *testing.T) {
}
}
/*
Tests for option --skip-pod-summary
*/
func TestPT_2453(t *testing.T) {
testcmd := []string{"sh", "-c", "tar -tf cluster-dump.tar.gz --wildcards '*/summary.txt' 2>/dev/null | wc -l"}
tests := []struct {
name string
resource string
want string
kubeconfig string
}{
{
name: "none",
resource: "none",
want: "0",
kubeconfig: "",
},
{
name: "pxc",
resource: "pxc",
want: "0",
kubeconfig: os.Getenv("KUBECONFIG_PXC"),
},
{
name: "ps",
resource: "ps",
want: "0",
kubeconfig: os.Getenv("KUBECONFIG_PS"),
},
{
name: "psmdb",
resource: "psmdb",
want: "0",
kubeconfig: os.Getenv("KUBECONFIG_PSMDB"),
},
{
name: "pg",
resource: "pg",
want: "0",
kubeconfig: os.Getenv("KUBECONFIG_PG"),
},
{
name: "pgv2",
resource: "pgv2",
want: "0",
kubeconfig: os.Getenv("KUBECONFIG_PG2"),
},
{
name: "auto pxc",
resource: "auto",
want: "0",
kubeconfig: os.Getenv("KUBECONFIG_PXC"),
},
{
name: "auto ps",
resource: "auto",
want: "0",
kubeconfig: os.Getenv("KUBECONFIG_PS"),
},
{
name: "auto psmdb",
resource: "auto",
want: "0",
kubeconfig: os.Getenv("KUBECONFIG_PSMDB"),
},
{
name: "auto pg",
resource: "auto",
want: "0",
kubeconfig: os.Getenv("KUBECONFIG_PG"),
},
{
name: "auto pgv2",
resource: "auto",
want: "0",
kubeconfig: os.Getenv("KUBECONFIG_PG2"),
},
}
for _, test := range tests {
cmd := exec.Command("../../../bin/pt-k8s-debug-collector", "--kubeconfig", test.kubeconfig, "--forwardport", os.Getenv("FORWARDPORT"), "--resource", test.resource, "--skip-pod-summary")
if err := cmd.Run(); err != nil {
t.Errorf("error executing pt-k8s-debug-collector: %s\nCommand: %s", err.Error(), cmd.String())
}
defer func() {
cmd = exec.Command("rm", "-f", "cluster-dump.tar.gz")
if err := cmd.Run(); err != nil {
t.Errorf("error cleaning up test data: %s", err.Error())
}
}()
out, err := exec.Command(testcmd[0], testcmd[1:]...).Output()
if err != nil {
t.Errorf("test %s, error running command %s:\n%s\n\nCommand output:\n%s", test.name, testcmd, err.Error(), out)
}
if strings.TrimRight(bytes.NewBuffer(out).String(), "\n") != test.want {
t.Errorf("test %s, output is not as expected\nOutput: %s\nWanted: %s", test.name, out, test.want)
}
}
}
/*
Option --version
*/