Skip to content

Commit 06dd5b8

Browse files
fix pmd test
1 parent 8c1f73a commit 06dd5b8

File tree

1 file changed

+40
-8
lines changed

1 file changed

+40
-8
lines changed

tools/pmdRunner_test.go

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"strings"
1010
"testing"
1111

12+
"codacy/cli-v2/plugins"
13+
1214
"github.com/stretchr/testify/assert"
1315
)
1416

@@ -58,18 +60,48 @@ func TestRunPmdToFile(t *testing.T) {
5860
tempResultFile := filepath.Join(os.TempDir(), "pmd.sarif")
5961
defer os.Remove(tempResultFile)
6062

61-
config := *config.NewConfigType(testDirectory, repositoryCache, globalCache)
63+
// Create a test configuration with PMD tool info
64+
config := config.NewConfigType(testDirectory, repositoryCache, globalCache)
65+
66+
// Add PMD tool configuration
67+
pmdBinaryPath := filepath.Join(globalCache, "tools/[email protected]/pmd-bin-6.55.0/bin/run.sh")
68+
69+
// Process runtime configuration
70+
javaRuntime := plugins.RuntimeConfig{
71+
Name: "java",
72+
Version: "17.0.10",
73+
}
74+
runtimesDir := filepath.Join(globalCache, "runtimes")
75+
runtimeInfoMap, err := plugins.ProcessRuntimes([]plugins.RuntimeConfig{javaRuntime}, runtimesDir)
76+
if err != nil {
77+
t.Fatalf("Failed to process runtime configuration: %v", err)
78+
}
79+
80+
// Process tool configuration
81+
pmdTool := plugins.ToolConfig{
82+
Name: "pmd",
83+
Version: "6.55.0",
84+
}
85+
toolsDir := filepath.Join(globalCache, "tools")
86+
_, err = plugins.ProcessTools([]plugins.ToolConfig{pmdTool}, toolsDir, runtimeInfoMap)
87+
if err != nil {
88+
t.Fatalf("Failed to process tool configuration: %v", err)
89+
}
90+
91+
// Add configurations to config object
92+
err = config.AddRuntimes([]plugins.RuntimeConfig{javaRuntime})
93+
if err != nil {
94+
t.Fatalf("Failed to add runtime configuration: %v", err)
95+
}
96+
err = config.AddTools([]plugins.ToolConfig{pmdTool})
97+
if err != nil {
98+
t.Fatalf("Failed to add tool configuration: %v", err)
99+
}
62100

63101
// Use absolute paths
64102
repositoryToAnalyze := testDirectory
65-
// Use the standard ruleset file for testing the PMD runner functionality
66-
//rulesetFile := filepath.Join(testDirectory, "ruleset.xml")
67-
68-
// Use the same path as defined in plugin.yaml
69-
pmdBinary := filepath.Join(globalCache, "tools/[email protected]/pmd-bin-6.55.0/bin/run.sh")
70103

71-
// Run PMD
72-
err = RunPmd(repositoryToAnalyze, pmdBinary, nil, tempResultFile, "sarif", config)
104+
err = RunPmd(repositoryToAnalyze, pmdBinaryPath, nil, tempResultFile, "sarif", *config)
73105
if err != nil {
74106
t.Fatalf("Failed to run pmd: %v", err)
75107
}

0 commit comments

Comments
 (0)