Skip to content
Open
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
43 changes: 42 additions & 1 deletion src/go/pt-k8s-debug-collector/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,11 @@ func (s *CollectorSuite) TestIndividualFiles() {
var result []string
for _, f := range files {
b := path.Base(f)
if !slices.Contains(result, b) && b != "." && b != "" {
if b == "." || b == "" {
continue
}

if !slices.Contains(result, b) {
result = append(result, b)
}
}
Expand All @@ -328,6 +332,43 @@ func (s *CollectorSuite) TestIndividualFiles() {
return in[:nl]
},
},
{
namespace: "pxc",
// If pod logs are exported as one file per container
name: "pxc_container_logs_split_by_container",
// tar -tf cluster-dump.tar.gz --wildcards 'cluster-dump/pxc/*/*.log'
cmd: []string{"tar", "-tf", "cluster-dump.tar.gz", "--wildcards", "cluster-dump/pxc/*/*.log"},
want: []string{"logrotate.log", "logs.log", "pxc-init.log", "pxc.log"},
preprocessor: func(in string) string {
required := map[string]struct{}{
"logrotate.log": {},
"logs.log": {},
"pxc-init.log": {},
"pxc.log": {},
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: It's better to implement sets like map[string]struct{} and use _, ok := required[b] to check if value is there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


files := strings.Split(in, "\n")
var result []string
for _, f := range files {
rel := strings.TrimPrefix(f, "cluster-dump/pxc/")
parts := strings.Split(rel, "/")
if len(parts) != 2 {
continue
}

b := parts[1]
if _, ok := required[b]; !ok {
continue
}

if !slices.Contains(result, b) {
result = append(result, b)
}
}
slices.Sort(result)
return strings.Join(result, "\n")
},
},
}

if s.Namespace != "pxc" {
Expand Down
Loading