From 23e39ec7cfd1c5cad3c132b2f951027ae75266e9 Mon Sep 17 00:00:00 2001 From: nathannaveen <42319948+nathannaveen@users.noreply.github.com> Date: Wed, 27 Mar 2024 08:27:41 -0500 Subject: [PATCH] Fixed Tests Signed-off-by: nathannaveen <42319948+nathannaveen@users.noreply.github.com> --- .../parser/cyclonedx/parser_cyclonedx_test.go | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/pkg/ingestor/parser/cyclonedx/parser_cyclonedx_test.go b/pkg/ingestor/parser/cyclonedx/parser_cyclonedx_test.go index 646cb2516d2..b304d53a7d0 100644 --- a/pkg/ingestor/parser/cyclonedx/parser_cyclonedx_test.go +++ b/pkg/ingestor/parser/cyclonedx/parser_cyclonedx_test.go @@ -620,21 +620,34 @@ func Test_findCDXPkgVersionIDs(t *testing.T) { wantErr: false, }, } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - getPackages = tt.getPackages + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + getPackages = test.getPackages c := cyclonedxParser{ gqlClient: nil, } - got, err := c.findCDXPkgVersionIDs(tt.args.ctx, tt.args.pkgIdentifier, tt.args.versionRange) - if (err != nil) != tt.wantErr { - t.Errorf("findCDXPkgVersionIDs() error = %v, wantErr %v", err, tt.wantErr) + got, err := c.findCDXPkgVersionIDs(test.args.ctx, test.args.pkgIdentifier, test.args.versionRange) + if (err != nil) != test.wantErr { + t.Errorf("findCDXPkgVersionIDs() error = %v, wantErr %v", err, test.wantErr) return } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("findCDXPkgVersionIDs() got = %v, want %v", got, tt.want) + if len(got) != len(test.want) { + t.Errorf("findCDXPkgVersionIDs() got = %v, want = %v", got, test.want) + return + } + wantValues := map[string]bool{} + for _, val := range test.want { + wantValues[val] = true + } + for _, val := range got { + if wantValues[val] { + delete(wantValues, val) + } else { + t.Errorf("findCDXPkgVersionIDs() got = %v, want = %v", got, test.want) + return + } } }) }