github.com/google/osv-scalibr@v0.4.1/testing/extracttest/compare_test.go (about)

     1  // Copyright 2025 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package extracttest
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/google/osv-scalibr/extractor"
    21  )
    22  
    23  func TestPackageCmpLess(t *testing.T) {
    24  	type args struct {
    25  		a *extractor.Package
    26  		b *extractor.Package
    27  	}
    28  	tests := []struct {
    29  		name string
    30  		args args
    31  		want bool
    32  	}{
    33  		{
    34  			name: "Location_difference",
    35  			args: args{
    36  				a: &extractor.Package{
    37  					Name:      "a",
    38  					Version:   "2.0.0",
    39  					Locations: []string{"aaa/bbb"},
    40  				},
    41  				b: &extractor.Package{
    42  					Name:      "a",
    43  					Version:   "1.0.0",
    44  					Locations: []string{"ccc/ddd"},
    45  				},
    46  			},
    47  			want: true,
    48  		},
    49  		{
    50  			name: "Version_difference",
    51  			args: args{
    52  				a: &extractor.Package{
    53  					Name:      "a",
    54  					Version:   "2.0.0",
    55  					Locations: []string{"aaa/bbb"},
    56  				},
    57  				b: &extractor.Package{
    58  					Name:      "a",
    59  					Version:   "1.0.0",
    60  					Locations: []string{"aaa/bbb"},
    61  				},
    62  			},
    63  			want: false,
    64  		},
    65  	}
    66  	for _, tt := range tests {
    67  		t.Run(tt.name, func(t *testing.T) {
    68  			if got := PackageCmpLess(tt.args.a, tt.args.b); got != tt.want {
    69  				t.Errorf("PackageCmpLess() = %v, want %v", got, tt.want)
    70  			}
    71  		})
    72  	}
    73  }