Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not panic on invalid air-gapped bundle #586

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions cmd/mindthegap/importcmd/imagebundle/image_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package imagebundle

import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -67,6 +68,11 @@ func NewCommand(out output.Output) *cobra.Command {
if err != nil {
return err
}
if cfg == nil {
return errors.New(
"no bundle configuration(s) found: please check that you have specified valid air-gapped bundle(s)",
)
}

out.StartOperation("Starting temporary Docker registry")
reg, err := registry.NewRegistry(
Expand Down
17 changes: 17 additions & 0 deletions test/e2e/imagebundle/import_bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,21 @@ var _ = Describe("Import Bundle", Label("import"), Serial, func() {
cmd.Execute(),
).To(MatchError(fmt.Sprintf("did find any matching files for %q", "non-existent-file")))
})

It("Bundle file exists, is a tarball, but not an image bundle", func() {
tmpDir := GinkgoT().TempDir()
nonBundleFile := filepath.Join(tmpDir, "image-bundle.tar")

Expect(archive.ArchiveDirectory("testdata", nonBundleFile)).To(Succeed())

cmd := helpers.NewCommand(GinkgoT(), importimagebundle.NewCommand)

cmd.SetArgs([]string{
"--image-bundle", nonBundleFile,
})

Expect(
cmd.Execute(),
).To(MatchError("no bundle configuration(s) found: please check that you have specified valid air-gapped bundle(s)"))
})
})
Loading