Skip to content

Commit

Permalink
Merge pull request #459 from officialasishkumar/sparse-checkout-kcl-m…
Browse files Browse the repository at this point in the history
…od-add

fix vendor mode for metadata and test case
  • Loading branch information
Peefy committed Aug 22, 2024
2 parents 33115fb + 749e5c6 commit ce9dfee
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
16 changes: 8 additions & 8 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,14 +902,6 @@ func (c *KpmClient) vendorDeps(kclPkg *pkg.KclPkg, vendorPath string) error {
} else {
vendorFullPath := filepath.Join(vendorPath, d.GenPathSuffix())

if d.GetPackage() != "" {
tempVendorFullPath, err := utils.FindPackage(vendorFullPath, d.GetPackage())
if err != nil {
return err
}
vendorFullPath = tempVendorFullPath
}

// If the package already exists in the 'vendor', do nothing.
if utils.DirExists(vendorFullPath) {
d.LocalFullPath = vendorFullPath
Expand Down Expand Up @@ -939,6 +931,14 @@ func (c *KpmClient) vendorDeps(kclPkg *pkg.KclPkg, vendorPath string) error {
}
}

if d.GetPackage() != "" {
tempVendorFullPath, err := utils.FindPackage(vendorFullPath, d.GetPackage())
if err != nil {
return err
}
vendorFullPath = tempVendorFullPath
}

dpkg, err := c.LoadPkgFromPath(vendorFullPath)
if err != nil {
return err
Expand Down
32 changes: 30 additions & 2 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,19 +822,47 @@ func TestResolveMetadataInJsonStr(t *testing.T) {
err = fmt.Errorf("panic: %v", r)
}
}()
}

func TestTestResolveMetadataInJsonStrWithPackage(t *testing.T) {
// Unit tests for package flag
testDir = filepath.Join(getTestDir("resolve_metadata"), "with_package")
testDir := filepath.Join(getTestDir("resolve_metadata"), "with_package")

kpmcli, err := NewKpmClient()
assert.Equal(t, err, nil)

kclpkg, err := kpmcli.LoadPkgFromPath(testDir)
assert.Equal(t, err, nil)

_, err = kpmcli.ResolveDepsMetadataInJsonStr(kclpkg, true)
fmt.Printf("err: %v\n", err)
assert.Equal(t, err, nil)

vendorDir := filepath.Join(testDir, "vendor")

kpmcli, err = NewKpmClient()
assert.Equal(t, err, nil)

kclpkg, err = kpmcli.LoadPkgFromPath(testDir)
assert.Equal(t, err, nil)

if utils.DirExists(vendorDir) {
err = os.RemoveAll(vendorDir)
assert.Equal(t, err, nil)
}

kclpkg.SetVendorMode(true)

_, err = kpmcli.ResolveDepsMetadataInJsonStr(kclpkg, true)
fmt.Printf("err: %v\n", err)
assert.Equal(t, err, nil)

assert.Equal(t, utils.DirExists(vendorDir), true)
assert.Equal(t, utils.DirExists(filepath.Join(vendorDir, "add-capabilities_16eab4efa2af84d7d641b23f3a3d14d4d891cb9e")), true)

defer func() {
err = os.RemoveAll(vendorDir)
assert.Equal(t, err, nil)
} ()
}

func TestPkgWithInVendorMode(t *testing.T) {
Expand Down

0 comments on commit ce9dfee

Please sign in to comment.