Skip to content

Commit

Permalink
use filepath.Join to make pathes
Browse files Browse the repository at this point in the history
  • Loading branch information
cuixq committed Jan 20, 2025
1 parent 6533f01 commit 4a5099b
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions internal/mavenutil/maven_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package mavenutil_test

import (
"path/filepath"
"testing"

"github.com/google/osv-scalibr/internal/mavenutil"
"github.com/google/osv-scalibr/testing/extracttest"
)

func TestParentPOMPath(t *testing.T) {
input := extracttest.GenerateScanInputMock(t, extracttest.ScanInputMockConfig{
Path: "fixtures/my-app/pom.xml",
})
input := extracttest.GenerateScanInputMock(t, extracttest.ScanInputMockConfig{})
defer extracttest.CloseTestScanInput(t, input)

tests := []struct {
currentPath, relativePath string
want string
Expand All @@ -24,37 +25,37 @@ func TestParentPOMPath(t *testing.T) {
// |- pom.xml
{
// Parent path is specified correctly.
currentPath: "fixtures/my-app/pom.xml",
currentPath: filepath.Join("fixtures", "my-app", "pom.xml"),
relativePath: "../parent/pom.xml",
want: "fixtures/parent/pom.xml",
want: filepath.Join("fixtures", "parent", "pom.xml"),
},
{
// Wrong file name is specified in relative path.
currentPath: "fixtures/my-app/pom.xml",
currentPath: filepath.Join("fixtures", "my-app", "pom.xml"),
relativePath: "../parent/abc.xml",
want: "",
},
{
// Wrong directory is specified in relative path.
currentPath: "fixtures/my-app/pom.xml",
currentPath: filepath.Join("fixtures", "my-app", "pom.xml"),
relativePath: "../not-found/pom.xml",
want: "",
},
{
// Only directory is specified.
currentPath: "fixtures/my-app/pom.xml",
currentPath: filepath.Join("fixtures", "my-app", "pom.xml"),
relativePath: "../parent",
want: "fixtures/parent/pom.xml",
want: filepath.Join("fixtures", "parent", "pom.xml"),
},
{
// Parent relative path is default to '../pom.xml'.
currentPath: "fixtures/my-app/pom.xml",
currentPath: filepath.Join("fixtures", "my-app", "pom.xml"),
relativePath: "",
want: "fixtures/pom.xml",
want: filepath.Join("fixtures", "pom.xml"),
},
{
// No pom.xml is found even in the default path.
currentPath: "fixtures/pom.xml",
currentPath: filepath.Join("fixtures", "pom.xml"),
relativePath: "",
want: "",
},
Expand Down

0 comments on commit 4a5099b

Please sign in to comment.