Skip to content

Commit

Permalink
MTA-1320: Only create discovery dir for test (#94)
Browse files Browse the repository at this point in the history
* do not create discovery dir for convert

Signed-off-by: Emily McMullan <emcmulla@redhat.com>

* do not pass subcommand value for discovery rules dir

Signed-off-by: Emily McMullan <emcmulla@redhat.com>

---------

Signed-off-by: Emily McMullan <emcmulla@redhat.com>
  • Loading branch information
eemcmullan committed Nov 1, 2023
1 parent e11fdc4 commit e79f657
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
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 @@ -23,11 +23,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

0 comments on commit e79f657

Please sign in to comment.