Skip to content

Commit

Permalink
🧹 Prevent nil panic when recording is not set
Browse files Browse the repository at this point in the history
In case recording isn't specififed during scanner initialisation, set the NullRecording

Signed-off-by: Christian Zunker <[email protected]>
  • Loading branch information
czunker committed Nov 17, 2023
1 parent e25ee23 commit d8a5bd6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions policy/scan/local_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ func NewLocalScanner(opts ...ScannerOption) *LocalScanner {
opts[i](ls)
}

if ls.recording == nil {
ls.recording = providers.NullRecording{}
}

return ls
}

Expand Down
9 changes: 9 additions & 0 deletions policy/scan/local_scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,12 @@ func TestCreateAssetList(t *testing.T) {
require.Equal(t, "mondoo-operator-123", candidates[2].asset.ManagedBy)
})
}

func TestDefaultConfig(t *testing.T) {
t.Run("without opts", func(t *testing.T) {
scanner := NewLocalScanner()
require.NotNil(t, scanner)

require.Equal(t, providers.NullRecording{}, scanner.recording)
})
}

0 comments on commit d8a5bd6

Please sign in to comment.