github.com/mizzy/docker@v1.5.0/pkg/parsers/kernel/kernel_test.go (about)

     1  package kernel
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func assertParseRelease(t *testing.T, release string, b *KernelVersionInfo, result int) {
     8  	var (
     9  		a *KernelVersionInfo
    10  	)
    11  	a, _ = ParseRelease(release)
    12  
    13  	if r := CompareKernelVersion(a, b); r != result {
    14  		t.Fatalf("Unexpected kernel version comparison result. Found %d, expected %d", r, result)
    15  	}
    16  	if a.Flavor != b.Flavor {
    17  		t.Fatalf("Unexpected parsed kernel flavor.  Found %s, expected %s", a.Flavor, b.Flavor)
    18  	}
    19  }
    20  
    21  func TestParseRelease(t *testing.T) {
    22  	assertParseRelease(t, "3.8.0", &KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0}, 0)
    23  	assertParseRelease(t, "3.4.54.longterm-1", &KernelVersionInfo{Kernel: 3, Major: 4, Minor: 54, Flavor: ".longterm-1"}, 0)
    24  	assertParseRelease(t, "3.4.54.longterm-1", &KernelVersionInfo{Kernel: 3, Major: 4, Minor: 54, Flavor: ".longterm-1"}, 0)
    25  	assertParseRelease(t, "3.8.0-19-generic", &KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0, Flavor: "-19-generic"}, 0)
    26  	assertParseRelease(t, "3.12.8tag", &KernelVersionInfo{Kernel: 3, Major: 12, Minor: 8, Flavor: "tag"}, 0)
    27  	assertParseRelease(t, "3.12-1-amd64", &KernelVersionInfo{Kernel: 3, Major: 12, Minor: 0, Flavor: "-1-amd64"}, 0)
    28  }
    29  
    30  func assertKernelVersion(t *testing.T, a, b *KernelVersionInfo, result int) {
    31  	if r := CompareKernelVersion(a, b); r != result {
    32  		t.Fatalf("Unexpected kernel version comparison result. Found %d, expected %d", r, result)
    33  	}
    34  }
    35  
    36  func TestCompareKernelVersion(t *testing.T) {
    37  	assertKernelVersion(t,
    38  		&KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0},
    39  		&KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0},
    40  		0)
    41  	assertKernelVersion(t,
    42  		&KernelVersionInfo{Kernel: 2, Major: 6, Minor: 0},
    43  		&KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0},
    44  		-1)
    45  	assertKernelVersion(t,
    46  		&KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0},
    47  		&KernelVersionInfo{Kernel: 2, Major: 6, Minor: 0},
    48  		1)
    49  	assertKernelVersion(t,
    50  		&KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0},
    51  		&KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0},
    52  		0)
    53  	assertKernelVersion(t,
    54  		&KernelVersionInfo{Kernel: 3, Major: 8, Minor: 5},
    55  		&KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0},
    56  		1)
    57  	assertKernelVersion(t,
    58  		&KernelVersionInfo{Kernel: 3, Major: 0, Minor: 20},
    59  		&KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0},
    60  		-1)
    61  }