Skip to content

Commit 65cad85

Browse files
Merge branch 'main' into other/saraChen/AddFFToASPM
2 parents 9c0349d + f2b3f70 commit 65cad85

4 files changed

Lines changed: 83 additions & 14 deletions

File tree

internal/commands/result.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,11 +1543,13 @@ func parseScaExportPackage(packages []wrappers.ScaPackage) *[]wrappers.ScaPackag
15431543
for _, pkg := range packages {
15441544
pkg := pkg
15451545
scaPackages = append(scaPackages, wrappers.ScaPackageCollection{
1546-
ID: pkg.ID,
1547-
Locations: pkg.Locations,
1548-
DependencyPathArray: parsePackagePathToDependencyPath(&pkg),
1549-
Outdated: pkg.Outdated,
1550-
IsDirectDependency: pkg.IsDirectDependency,
1546+
ID: pkg.ID,
1547+
Locations: pkg.Locations,
1548+
DependencyPathArray: parsePackagePathToDependencyPath(&pkg),
1549+
Outdated: pkg.Outdated,
1550+
IsDirectDependency: pkg.IsDirectDependency,
1551+
IsDevelopmentDependency: pkg.IsDevelopmentDependency,
1552+
IsTestDependency: pkg.IsTestDependency,
15511553
})
15521554
}
15531555
return &scaPackages

internal/commands/result_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,3 +1574,67 @@ func TestRiskManagement(t *testing.T) {
15741574
mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.RiskManagementEnabled, Status: true}
15751575
execCmdNilAssertion(t, "results", "risk-management")
15761576
}
1577+
1578+
func Test_addPackageInformation_DependencyTypes(t *testing.T) {
1579+
// Create dependency paths with different types
1580+
var dependencyPaths = [][]wrappers.DependencyPath{
1581+
{{
1582+
ID: "dev-pkg",
1583+
IsDevelopment: true,
1584+
}},
1585+
{{
1586+
ID: "test-pkg",
1587+
IsDevelopment: false,
1588+
}},
1589+
}
1590+
1591+
// Create results model with two results - one dev and one test
1592+
resultsModel := &wrappers.ScanResultsCollection{
1593+
Results: []*wrappers.ScanResult{
1594+
{
1595+
Type: "sca",
1596+
ScanResultData: wrappers.ScanResultData{
1597+
PackageIdentifier: "dev-pkg",
1598+
},
1599+
},
1600+
{
1601+
Type: "sca",
1602+
ScanResultData: wrappers.ScanResultData{
1603+
PackageIdentifier: "test-pkg",
1604+
},
1605+
},
1606+
},
1607+
}
1608+
1609+
// Create package model with different dev/test settings
1610+
scaPackageModel := &[]wrappers.ScaPackageCollection{
1611+
{
1612+
ID: "dev-pkg",
1613+
DependencyPathArray: dependencyPaths[:1],
1614+
IsDevelopmentDependency: true,
1615+
IsTestDependency: false,
1616+
},
1617+
{
1618+
ID: "test-pkg",
1619+
DependencyPathArray: dependencyPaths[1:],
1620+
IsDevelopmentDependency: false,
1621+
IsTestDependency: true,
1622+
},
1623+
}
1624+
1625+
scaTypeModel := &[]wrappers.ScaTypeCollection{{}}
1626+
1627+
// Execute the function
1628+
resultsModel = addPackageInformation(resultsModel, scaPackageModel, scaTypeModel)
1629+
1630+
// Get the results
1631+
devPackage := resultsModel.Results[0].ScanResultData.ScaPackageCollection
1632+
testPackage := resultsModel.Results[1].ScanResultData.ScaPackageCollection
1633+
1634+
// Verify the fields were transferred correctly
1635+
assert.Equal(t, true, devPackage.IsDevelopmentDependency, "First package should be marked as development dependency")
1636+
assert.Equal(t, false, devPackage.IsTestDependency, "First package should not be marked as test dependency")
1637+
1638+
assert.Equal(t, false, testPackage.IsDevelopmentDependency, "Second package should not be marked as development dependency")
1639+
assert.Equal(t, true, testPackage.IsTestDependency, "Second package should be marked as test dependency")
1640+
}

internal/wrappers/export.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type ScaPackage struct {
2020
Outdated bool `json:"Outdated,omitempty"`
2121
IsDirectDependency bool `json:"IsDirectDependency"`
2222
IsDevelopmentDependency bool `json:"IsDevelopmentDependency"`
23+
IsTestDependency bool `json:"IsTestDependency"`
2324
SupportsQuickFix bool
2425
FixLink string
2526
TypeOfDependency string

internal/wrappers/results-sca-package.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package wrappers
22

33
type ScaPackageCollection struct {
4-
ID string `json:"id,omitempty"`
5-
FixLink string `json:"fixLink,omitempty"`
6-
BestPackageLink string `json:"bestPackageLink,omitempty"`
7-
Locations []*string `json:"locations,omitempty"`
8-
DependencyPathArray [][]DependencyPath `json:"dependencyPaths,omitempty"`
9-
Outdated bool `json:"outdated,omitempty"`
10-
SupportsQuickFix bool `json:"supportsQuickFix"`
11-
IsDirectDependency bool `json:"isDirectDependency"`
12-
TypeOfDependency string `json:"typeOfDependency"`
4+
ID string `json:"id,omitempty"`
5+
FixLink string `json:"fixLink,omitempty"`
6+
BestPackageLink string `json:"bestPackageLink,omitempty"`
7+
Locations []*string `json:"locations,omitempty"`
8+
DependencyPathArray [][]DependencyPath `json:"dependencyPaths,omitempty"`
9+
Outdated bool `json:"outdated,omitempty"`
10+
SupportsQuickFix bool `json:"supportsQuickFix"`
11+
IsDirectDependency bool `json:"isDirectDependency"`
12+
TypeOfDependency string `json:"typeOfDependency"`
13+
IsDevelopmentDependency bool `json:"isDevelopmentDependency"`
14+
IsTestDependency bool `json:"isTestDependency"`
1315
}
1416

1517
type DependencyPath struct {

0 commit comments

Comments
 (0)