mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-02-14 10:19:54 +00:00
* feat(redactors): Run redactors on an existing support bundle Add redact subcommand to support-bundle to allow running redactors on an existing bundle to creating a new redacted bundle. The command will be launched like so support-bundle redact <redactor urls> --bundle support-bundle.tar.gz Fixes: #705
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package collect
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/replicatedhq/troubleshoot/internal/testutils"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCollectorResult_AddResult(t *testing.T) {
|
|
r := CollectorResult{"a": []byte("a")}
|
|
|
|
other := CollectorResult{"b": []byte("b")}
|
|
r.AddResult(other)
|
|
|
|
assert.Equal(t, 2, len(r))
|
|
assert.Equal(t, []byte("a"), r["a"])
|
|
assert.Equal(t, []byte("b"), r["b"])
|
|
}
|
|
|
|
func TestCollectorResultFromBundle(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
bundleDir string
|
|
want CollectorResult
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "creates collector results from a bundle successfully",
|
|
bundleDir: filepath.Join(testutils.FileDir(), "../../testdata/supportbundle/extracted-sb"),
|
|
want: CollectorResult{
|
|
"cluster-resources/pods/logs/default/static-hi/static-hi.log": nil,
|
|
"static-hi.log": nil,
|
|
},
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "fails to create collector results from a missing directory",
|
|
bundleDir: "gibberish",
|
|
want: nil,
|
|
wantErr: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := CollectorResultFromBundle(tt.bundleDir)
|
|
assert.Equal(t, tt.want, got)
|
|
assert.Equal(t, (err != nil), tt.wantErr)
|
|
})
|
|
}
|
|
}
|