Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MTA-1320: Only create discovery dir for test #94

Merged
merged 2 commits into from
Nov 1, 2023
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
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func main() {
if err != nil {
fmt.Println(err)
}
_, err = conversion.ConvertWindupRulesetsToAnalyzer(rulesets, location, outputDir, flattenRulesets)
_, err = conversion.ConvertWindupRulesetsToAnalyzer(rulesets, location, outputDir, flattenRulesets, false)
if err != nil {
log.Fatal(err)
}
Expand All @@ -71,7 +71,7 @@ func main() {
totalTests := 0
for _, test := range ruletests {
fmt.Println("Executing " + test.SourceFile)
successes, total, err := execution.ExecuteTest(test, location)
successes, total, err := execution.ExecuteTest(test, location, true)
if err != nil {
// TODO should we exit here?
fmt.Println(err)
Expand Down Expand Up @@ -104,7 +104,7 @@ func main() {
if err != nil {
fmt.Println(err)
}
output, dir, err := execution.ExecuteRulesets(rulesets, location, data)
output, dir, err := execution.ExecuteRulesets(rulesets, location, data, false)
fmt.Println(output, dir, err)
}
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/conversion/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ type analyzerRules struct {
relativePath string
}

func ConvertWindupRulesetsToAnalyzer(windups []windup.Ruleset, baseLocation, outputDir string, flattenRulesets bool) (map[string]*analyzerRules, error) {
// Write discovery rules
err := writeDiscoveryRules(outputDir)
if err != nil {
return nil, err
func ConvertWindupRulesetsToAnalyzer(windups []windup.Ruleset, baseLocation, outputDir string, flattenRulesets bool, writeDisoveryRule bool) (map[string]*analyzerRules, error) {
if writeDisoveryRule {
err := writeDiscoveryRules(outputDir)
if err != nil {
return nil, err
}
}

outputRulesets := map[string]*analyzerRules{}
Expand Down
12 changes: 6 additions & 6 deletions pkg/execution/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const (
`
)

func ExecuteRulesets(rulesets []windup.Ruleset, baseLocation, datadir string) (string, string, error) {
func ExecuteRulesets(rulesets []windup.Ruleset, baseLocation, datadir string, writeDiscoveryRules bool) (string, string, error) {
datadir, err := filepath.Abs(datadir)
if err != nil {
return "", "", err
Expand Down Expand Up @@ -136,7 +136,7 @@ func ExecuteRulesets(rulesets []windup.Ruleset, baseLocation, datadir string) (s
for _, ruleset := range rulesets {
sourceFiles = append(sourceFiles, ruleset.SourceFile)
}
conversion.ConvertWindupRulesetsToAnalyzer(rulesets, baseLocation, filepath.Join(dir, "rules"), true)
conversion.ConvertWindupRulesetsToAnalyzer(rulesets, baseLocation, filepath.Join(dir, "rules"), true, writeDiscoveryRules)
// Template config file for analyzer
providerConfig := []provider.Config{
{
Expand Down Expand Up @@ -215,8 +215,8 @@ func writeJSON(content interface{}, dest string) error {
return nil
}

func ExecuteTest(test windup.Ruletest, location string) (int, int, error) {
violations, err := getViolations(test, location)
func ExecuteTest(test windup.Ruletest, location string, writeDiscoveryRules bool) (int, int, error) {
violations, err := getViolations(test, location, writeDiscoveryRules)
total := 0
successes := 0
for _, ruleset := range test.Ruleset {
Expand Down Expand Up @@ -254,7 +254,7 @@ func ExecuteTest(test windup.Ruletest, location string) (int, int, error) {
return successes, total, err
}

func getViolations(test windup.Ruletest, baseLocation string) ([]konveyor.RuleSet, error) {
func getViolations(test windup.Ruletest, baseLocation string, writeDiscoveryRules bool) ([]konveyor.RuleSet, error) {
rulesets := []windup.Ruleset{}
if len(test.RulePath) == 0 {
// use the test name, to move up a folder and get the rule
Expand Down Expand Up @@ -300,7 +300,7 @@ func getViolations(test windup.Ruletest, baseLocation string) ([]konveyor.RuleSe
}
}
}
_, dir, err := ExecuteRulesets(rulesets, baseLocation, test.TestDataPath)
_, dir, err := ExecuteRulesets(rulesets, baseLocation, test.TestDataPath, writeDiscoveryRules)
if err != nil {
return nil, err
}
Expand Down
Loading