Skip to content

Commit

Permalink
fix: Do not panic on invalid air-gapped bundle (#586)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmidyson authored Dec 18, 2023
1 parent 21b5da8 commit e544b4a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
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)"))
})
})

0 comments on commit e544b4a

Please sign in to comment.