Skip to content

Commit

Permalink
fix(misconf): init frameworks before updating them
Browse files Browse the repository at this point in the history
Signed-off-by: nikpivkin <[email protected]>
  • Loading branch information
nikpivkin committed Aug 23, 2024
1 parent 6fe6727 commit 2ac74a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/iac/rego/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func NewStaticMetadata(pkgPath string, inputOpt InputOptions) *StaticMetadata {
}

func (sm *StaticMetadata) Update(meta map[string]any) error {
if sm.Frameworks == nil {
sm.Frameworks = make(map[framework.Framework][]string)
}

upd := func(field *string, key string) {
if raw, ok := meta[key]; ok {
Expand Down
8 changes: 8 additions & 0 deletions pkg/iac/rego/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ func Test_UpdateStaticMetadata(t *testing.T) {

assert.Equal(t, expected, sm)
})

t.Run("frameworks is not initialized", func(t *testing.T) {
sm := StaticMetadata{}
err := sm.Update(map[string]any{
"frameworks": map[string]any{"all": []any{"a", "b", "c"}},
})
require.NoError(t, err)
})
}

func Test_NewEngineMetadata(t *testing.T) {
Expand Down

0 comments on commit 2ac74a7

Please sign in to comment.