Files
Evans Mungai a523551da9 feat(redactors): Run redactors on an existing support bundle (#887)
* 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
2023-01-03 18:05:15 +00:00

50 lines
1.3 KiB
Go

package analyzer
import (
"os"
"path/filepath"
"testing"
"github.com/replicatedhq/troubleshoot/internal/testutils"
"github.com/stretchr/testify/assert"
)
func TestDownloadAndExtractSupportBundle(t *testing.T) {
// TODO: Add tests for web url downloads
tests := []struct {
name string
bundleURL string
wantErr bool
}{
{
name: "extract a bundle from a local file path",
bundleURL: filepath.Join(testutils.FileDir(), "../../testdata/supportbundle/support-bundle.tar.gz"),
wantErr: false,
},
{
name: "extract a bundle from a non-existent file path",
bundleURL: "/home/someone/gibberish",
wantErr: true,
},
{
name: "extract an invalid support bundle which has no version file",
bundleURL: filepath.Join(testutils.FileDir(), "../../testdata/supportbundle/missing-version.tar.gz"),
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tmpDir, bundleDir, err := DownloadAndExtractSupportBundle(tt.bundleURL)
defer os.RemoveAll(tmpDir) // clean up. Ignore error
if err == nil {
assert.DirExists(t, bundleDir)
assert.FileExists(t, filepath.Join(bundleDir, "version.yaml"))
} else {
assert.Equal(t, "", tmpDir)
assert.Equal(t, "", bundleDir)
}
})
}
}