github.com/dylandreimerink/gobpfld@v0.6.1-0.20220205171531-e79c330ad608/kernelsupport/kernelsupport_test.go (about)

     1  package kernelsupport
     2  
     3  import "testing"
     4  
     5  func Test_kernelVersion_Higher(t *testing.T) {
     6  	tests := []struct {
     7  		name string
     8  		a    KernelVersion
     9  		b    KernelVersion
    10  		want bool
    11  	}{
    12  		{
    13  			name: "2.0.0 >= 1.0.0 - major",
    14  			a:    KernelVersion{Major: 2},
    15  			b:    KernelVersion{Major: 1},
    16  			want: true,
    17  		},
    18  		{
    19  			name: "2.1.0 >= 2.0.0 - minor",
    20  			a:    KernelVersion{Major: 2, Minor: 1},
    21  			b:    KernelVersion{Major: 2},
    22  			want: true,
    23  		},
    24  		{
    25  			name: "2.1.1 >= 2.1.0 - patch",
    26  			a:    KernelVersion{Major: 2, Minor: 1, Patch: 1},
    27  			b:    KernelVersion{Major: 2, Minor: 1},
    28  			want: true,
    29  		},
    30  		{
    31  			name: "2.2.2 >= 2.2.2 - exact",
    32  			a:    KernelVersion{Major: 2, Minor: 2, Patch: 2},
    33  			b:    KernelVersion{Major: 2, Minor: 2, Patch: 2},
    34  			want: true,
    35  		},
    36  		{
    37  			name: "1.1.0 >= 2.0.0 - major false",
    38  			a:    KernelVersion{Major: 1, Minor: 1},
    39  			b:    KernelVersion{Major: 2},
    40  			want: false,
    41  		},
    42  		{
    43  			name: "2.1.0 >= 2.2.0 - minor false",
    44  			a:    KernelVersion{Major: 2, Minor: 1},
    45  			b:    KernelVersion{Major: 2, Minor: 2},
    46  			want: false,
    47  		},
    48  		{
    49  			name: "2.2.0 >= 2.2.2 - patch false",
    50  			a:    KernelVersion{Major: 2, Minor: 2},
    51  			b:    KernelVersion{Major: 2, Minor: 2, Patch: 1},
    52  			want: false,
    53  		},
    54  	}
    55  	for _, tt := range tests {
    56  		t.Run(tt.name, func(t *testing.T) {
    57  			if got := tt.a.Higher(tt.b); got != tt.want {
    58  				t.Errorf("kernelVersion.Higher() = %v, want %v", got, tt.want)
    59  			}
    60  		})
    61  	}
    62  }