Skip to content
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
4 changes: 4 additions & 0 deletions pkg/osvscanner/osvscanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ func DoScan(actions ScannerActions) (models.VulnerabilityResults, error) {
}

func DoContainerScan(actions ScannerActions) (models.VulnerabilityResults, error) {
if actions.Image == "" {
return models.VulnerabilityResults{}, errors.New("container image must be provided")
}

scanResults := results.ScanResults{
ConfigManager: config.Manager{
DefaultConfig: config.Config{},
Expand Down
13 changes: 13 additions & 0 deletions pkg/osvscanner/osvscanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ import (
"github.com/google/osv-scanner/v2/pkg/osvscanner"
)

func TestDoContainerScan_NoImage(t *testing.T) {
t.Parallel()

_, err := osvscanner.DoContainerScan(osvscanner.ScannerActions{})
if err == nil {
t.Fatal("DoContainerScan() error = nil, want an error")
}

if got, want := err.Error(), "container image must be provided"; got != want {
t.Errorf("DoContainerScan() error = %q, want %q", got, want)
}
}

// TestDoScan_LogHandlerOverride tests that the SetLogger override works correctly
//
//nolint:paralleltest // No parallel test since slog.SetDefault sets global behavior
Expand Down
Loading