-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: connect and add basic smoke tests for evaluation and result typ…
…es (#8) Signed-off-by: Christopher Phillips <[email protected]>
- Loading branch information
Showing
9 changed files
with
177 additions
and
89 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,45 @@ | ||
package evalutation | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/anchore/grant/grant" | ||
) | ||
|
||
func Test_NewLicenseEvaluations(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
config EvaluationConfig | ||
caseFixture string | ||
wantFailed bool | ||
}{ | ||
{ | ||
name: "NewLicenseEvaluations returns a slice of LicenseEvaluation that fail for the DefaultPolicy", | ||
config: DefaultEvaluationConfig(), | ||
caseFixture: "../../fixtures/multiple", | ||
wantFailed: true, | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
grantCases := fixtureCase(tc.config, tc.caseFixture) | ||
for _, c := range grantCases { | ||
caseEvaluations := NewLicenseEvaluations(tc.config, c) | ||
if len(caseEvaluations) == 0 { | ||
t.Fatal("could not build license evaluations") | ||
} | ||
if len(caseEvaluations.Licenses()) == 0 { | ||
t.Fatal("could not build list of licenses from evaluations") | ||
} | ||
if tc.wantFailed && !caseEvaluations.IsFailed() { | ||
t.Fatal("expected license evaluations to fail for default config") | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func fixtureCase(ec EvaluationConfig, fixturePath string) []grant.Case { | ||
return grant.NewCases(&ec.Policy, fixturePath) | ||
} |
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,35 @@ | ||
package evalutation | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/anchore/grant/grant" | ||
) | ||
|
||
func Test_NewResults(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
ec EvaluationConfig | ||
fixtures []string | ||
wantPass bool | ||
}{ | ||
{ | ||
name: "NewResults returns results from a group of cases that cannot pass the default config", | ||
ec: DefaultEvaluationConfig(), | ||
fixtures: []string{ | ||
"../../fixtures/multiple", | ||
"../../fixtures/licenses/MIT", | ||
}, | ||
wantPass: false, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
cases := grant.NewCases(&tc.ec.Policy, tc.fixtures...) | ||
results := NewResults(tc.ec, cases...) | ||
if tc.wantPass != results.Pass() { | ||
t.Errorf("NewResults() = %v, want %v", results.Pass(), tc.wantPass) | ||
} | ||
}) | ||
} | ||
} |
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