Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
attiasas committed Dec 15, 2024
1 parent 3547787 commit 7eaa913
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions commands/audit/sca/pnpm/pnpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pnpm

import (
"path/filepath"
"sort"
"testing"

"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
Expand All @@ -27,33 +28,33 @@ func TestBuildDependencyTreeLimitedDepth(t *testing.T) {
expectedUniqueDeps []string
expectedTree *xrayUtils.GraphNode
}{
// {
// name: "Only direct dependencies",
// treeDepth: "0",
// expectedUniqueDeps: []string{
// "npm://zen-website:1.0.0",
// "npm://balaganjs:1.0.0",
// },
// expectedTree: &xrayUtils.GraphNode{
// Id: "npm://zen-website:1.0.0",
// Nodes: []*xrayUtils.GraphNode{{Id: "npm://balaganjs:1.0.0"}},
// },
// },
{
name: "Only direct dependencies",
treeDepth: "0",
expectedUniqueDeps: []string{
"npm://zen-website:1.0.0",
"npm://balaganjs:1.0.0",
},
expectedTree: &xrayUtils.GraphNode{
Id: "npm://zen-website:1.0.0",
Nodes: []*xrayUtils.GraphNode{{Id: "npm://balaganjs:1.0.0"}},
},
},
{
name: "With transitive dependencies",
treeDepth: "1",
expectedUniqueDeps: []string{
"npm://zen-website:1.0.0",
"npm://axios:1.7.9",
"npm://balaganjs:1.0.0",
"npm://axios:1.7.8",
"npm://yargs:13.3.0",
"npm://zen-website:1.0.0",
},
expectedTree: &xrayUtils.GraphNode{
Id: "npm://zen-website:1.0.0",
Nodes: []*xrayUtils.GraphNode{
{
Id: "npm://balaganjs:1.0.0",
Nodes: []*xrayUtils.GraphNode{{Id: "npm://axios:1.7.8"}, {Id: "npm://yargs:13.3.0"}},
Nodes: []*xrayUtils.GraphNode{{Id: "npm://axios:1.7.9"}, {Id: "npm://yargs:13.3.0"}},
},
},
},
Expand All @@ -66,6 +67,9 @@ func TestBuildDependencyTreeLimitedDepth(t *testing.T) {
params := &utils.AuditBasicParams{}
rootNode, uniqueDeps, err := BuildDependencyTree(params.SetMaxTreeDepth(testCase.treeDepth))
require.NoError(t, err)
sort.Slice(uniqueDeps, func(i, j int) bool {
return uniqueDeps[i] < uniqueDeps[j]
})
// Validations
assert.ElementsMatch(t, uniqueDeps, testCase.expectedUniqueDeps, "First is actual, Second is Expected")
if assert.Len(t, rootNode, 1) {
Expand Down

0 comments on commit 7eaa913

Please sign in to comment.