-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix e2e tests check for var in component import improve tests changes add test file I forgot to add earlier testing package finding feedback validate schema use built in interface moving change where print happens get package name pass in package move badZarfPackage to better spot better badZarfPackage if to require cleanup tests whoops accidentally committed deletion
- Loading branch information
1 parent
7b8cc2d
commit b48f058
Showing
14 changed files
with
628 additions
and
422 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors | ||
|
||
// Package lint contains functions for verifying zarf yaml files are valid | ||
package lint | ||
|
||
import ( | ||
"github.com/defenseunicorns/pkg/helpers/v2" | ||
"github.com/defenseunicorns/zarf/src/types" | ||
) | ||
|
||
// GroupFindingsByPath groups findings by their package path | ||
func GroupFindingsByPath(findings []types.PackageFinding, severity types.Severity, packageName string) map[string][]types.PackageFinding { | ||
findings = helpers.RemoveMatches(findings, func(finding types.PackageFinding) bool { | ||
return finding.Severity > severity | ||
}) | ||
for i := range findings { | ||
if findings[i].PackageNameOverride == "" { | ||
findings[i].PackageNameOverride = packageName | ||
} | ||
if findings[i].PackagePathOverride == "" { | ||
findings[i].PackagePathOverride = "." | ||
} | ||
} | ||
|
||
mapOfFindingsByPath := make(map[string][]types.PackageFinding) | ||
for _, finding := range findings { | ||
mapOfFindingsByPath[finding.PackagePathOverride] = append(mapOfFindingsByPath[finding.PackagePathOverride], finding) | ||
} | ||
return mapOfFindingsByPath | ||
} | ||
|
||
// HasSeverity returns true if the findings contain a severity equal to or greater than the given severity | ||
func HasSeverity(findings []types.PackageFinding, severity types.Severity) bool { | ||
for _, finding := range findings { | ||
if finding.Severity <= severity { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors | ||
|
||
// Package lint contains functions for verifying zarf yaml files are valid | ||
package lint | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/defenseunicorns/zarf/src/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGroupFindingsByPath(t *testing.T) { | ||
t.Parallel() | ||
tests := []struct { | ||
name string | ||
findings []types.PackageFinding | ||
severity types.Severity | ||
packageName string | ||
want map[string][]types.PackageFinding | ||
}{ | ||
{ | ||
name: "same package multiple findings", | ||
findings: []types.PackageFinding{ | ||
{Severity: types.SevWarn, PackageNameOverride: "import", PackagePathOverride: "path"}, | ||
{Severity: types.SevWarn, PackageNameOverride: "import", PackagePathOverride: "path"}, | ||
}, | ||
severity: types.SevWarn, | ||
packageName: "testPackage", | ||
want: map[string][]types.PackageFinding{ | ||
"path": { | ||
{Severity: types.SevWarn, PackageNameOverride: "import", PackagePathOverride: "path"}, | ||
{Severity: types.SevWarn, PackageNameOverride: "import", PackagePathOverride: "path"}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "different packages single finding", | ||
findings: []types.PackageFinding{ | ||
{Severity: types.SevWarn, PackageNameOverride: "import", PackagePathOverride: "path"}, | ||
{Severity: types.SevErr, PackageNameOverride: "", PackagePathOverride: ""}, | ||
}, | ||
severity: types.SevWarn, | ||
packageName: "testPackage", | ||
want: map[string][]types.PackageFinding{ | ||
"path": {{Severity: types.SevWarn, PackageNameOverride: "import", PackagePathOverride: "path"}}, | ||
".": {{Severity: types.SevErr, PackageNameOverride: "testPackage", PackagePathOverride: "."}}, | ||
}, | ||
}, | ||
{ | ||
name: "Multiple findings, mixed severity", | ||
findings: []types.PackageFinding{ | ||
{Severity: types.SevWarn, PackageNameOverride: "", PackagePathOverride: ""}, | ||
{Severity: types.SevErr, PackageNameOverride: "", PackagePathOverride: ""}, | ||
}, | ||
severity: types.SevErr, | ||
packageName: "testPackage", | ||
want: map[string][]types.PackageFinding{ | ||
".": {{Severity: types.SevErr, PackageNameOverride: "testPackage", PackagePathOverride: "."}}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
require.Equal(t, tt.want, GroupFindingsByPath(tt.findings, tt.severity, tt.packageName)) | ||
}) | ||
} | ||
} | ||
|
||
func TestHasSeverity(t *testing.T) { | ||
t.Parallel() | ||
tests := []struct { | ||
name string | ||
severity types.Severity | ||
expected bool | ||
findings []types.PackageFinding | ||
}{ | ||
{ | ||
name: "error severity present", | ||
findings: []types.PackageFinding{ | ||
{ | ||
Severity: types.SevErr, | ||
}, | ||
}, | ||
severity: types.SevErr, | ||
expected: true, | ||
}, | ||
{ | ||
name: "error severity not present", | ||
findings: []types.PackageFinding{ | ||
{ | ||
Severity: types.SevWarn, | ||
}, | ||
}, | ||
severity: types.SevErr, | ||
expected: false, | ||
}, | ||
{ | ||
name: "err and warning severity present", | ||
findings: []types.PackageFinding{ | ||
{ | ||
Severity: types.SevWarn, | ||
}, | ||
{ | ||
Severity: types.SevErr, | ||
}, | ||
}, | ||
severity: types.SevErr, | ||
expected: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
require.Equal(t, tt.expected, HasSeverity(tt.findings, tt.severity)) | ||
}) | ||
} | ||
} |
Oops, something went wrong.