-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated the files lock.go and update.go
Signed-off-by: BalaadityaPatanjali <[email protected]> added the required changes Signed-off-by: BalaadityaPatanjali <[email protected]> added the required changes Signed-off-by: BalaadityaPatanjali <[email protected]>
- Loading branch information
1 parent
0cb31b1
commit f7cb3a3
Showing
4 changed files
with
93 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package hcl2nix | |
import ( | ||
"reflect" | ||
"testing" | ||
"sort" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/google/go-cmp/cmp/cmpopts" | ||
|
@@ -130,7 +131,7 @@ func TestMapPackageCategory(t *testing.T) { | |
}, | ||
|
||
{ | ||
name: "Test Case 2", | ||
name: "Test Case 3", | ||
packages: Packages{ | ||
Runtime: []string{"[email protected]", "[email protected]"}, | ||
Development: []string{"[email protected]", "[email protected]"}, | ||
|
@@ -150,3 +151,79 @@ func TestMapPackageCategory(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func TestResolvePackagesSorting(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
pkgVersions []LockPackage | ||
sortedExpected []LockPackage | ||
}{ | ||
{ | ||
name: "test sorting", | ||
pkgVersions: []LockPackage{ | ||
{ | ||
Package: &buildsafev1.Package{ | ||
Name: "pkgB", | ||
Version: "1.1.0", | ||
}, | ||
Runtime: true, | ||
}, | ||
{ | ||
Package: &buildsafev1.Package{ | ||
Name: "pkgA", | ||
Version: "1.2.0", | ||
}, | ||
Runtime: false, | ||
}, | ||
{ | ||
Package: &buildsafev1.Package{ | ||
Name: "pkgA", | ||
Version: "1.0.0", | ||
}, | ||
Runtime: false, | ||
}, | ||
}, | ||
sortedExpected: []LockPackage{ | ||
{ | ||
Package: &buildsafev1.Package{ | ||
Name: "pkgA", | ||
Version: "1.0.0", | ||
}, | ||
Runtime: false, | ||
}, | ||
{ | ||
Package: &buildsafev1.Package{ | ||
Name: "pkgA", | ||
Version: "1.2.0", | ||
}, | ||
Runtime: false, | ||
}, | ||
{ | ||
Package: &buildsafev1.Package{ | ||
Name: "pkgB", | ||
Version: "1.1.0", | ||
}, | ||
Runtime: true, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
// Sort the package versions | ||
sortedPackages := tt.pkgVersions | ||
sort.Slice(sortedPackages, func(i, j int) bool { | ||
pi, pj := sortedPackages[i].Package, sortedPackages[j].Package | ||
if pi.Name != pj.Name { | ||
return pi.Name < pj.Name | ||
} | ||
return pi.Version < pj.Version | ||
}) | ||
|
||
if !reflect.DeepEqual(sortedPackages, tt.sortedExpected) { | ||
t.Errorf("sortedPackages = %v, want %v", sortedPackages, tt.sortedExpected) | ||
} | ||
}) | ||
} | ||
} |