github.com/ks888/tgo@v0.0.0-20190130135156-80bf89407292/tracee/version_test.go (about)

     1  package tracee
     2  
     3  import "testing"
     4  
     5  func TestParseGoVersion(t *testing.T) {
     6  	for i, testdata := range []struct {
     7  		input  string
     8  		expect GoVersion
     9  	}{
    10  		{input: "go1.11.1", expect: GoVersion{Raw: "go1.11.1", MajorVersion: 1, MinorVersion: 11, PatchVersion: 1}},
    11  		{input: "go1.11", expect: GoVersion{Raw: "go1.11", MajorVersion: 1, MinorVersion: 11}},
    12  		{input: "devel", expect: GoVersion{Raw: "devel", Devel: true}},
    13  	} {
    14  		actual := ParseGoVersion(testdata.input)
    15  		if actual != testdata.expect {
    16  			t.Errorf("[%d] wrong result: %v", i, actual)
    17  		}
    18  	}
    19  }
    20  
    21  func TestGoVersion_LaterThan(t *testing.T) {
    22  	for i, testdata := range []struct {
    23  		a, b   GoVersion
    24  		expect bool
    25  	}{
    26  		{
    27  			a:      GoVersion{Devel: true},
    28  			b:      GoVersion{MajorVersion: 1},
    29  			expect: true,
    30  		},
    31  		{
    32  			a:      GoVersion{MajorVersion: 2},
    33  			b:      GoVersion{MajorVersion: 1},
    34  			expect: true,
    35  		},
    36  		{
    37  			a:      GoVersion{MajorVersion: 0},
    38  			b:      GoVersion{MajorVersion: 1},
    39  			expect: false,
    40  		},
    41  		{
    42  			a:      GoVersion{MajorVersion: 1, MinorVersion: 12},
    43  			b:      GoVersion{MajorVersion: 1, MinorVersion: 11},
    44  			expect: true,
    45  		},
    46  		{
    47  			a:      GoVersion{MajorVersion: 1, MinorVersion: 10},
    48  			b:      GoVersion{MajorVersion: 1, MinorVersion: 11},
    49  			expect: false,
    50  		},
    51  		{
    52  			a:      GoVersion{MajorVersion: 1, MinorVersion: 11, PatchVersion: 1},
    53  			b:      GoVersion{MajorVersion: 1, MinorVersion: 11},
    54  			expect: true,
    55  		},
    56  		{
    57  			a:      GoVersion{MajorVersion: 1, MinorVersion: 11, PatchVersion: 1},
    58  			b:      GoVersion{MajorVersion: 1, MinorVersion: 11, PatchVersion: 1},
    59  			expect: true,
    60  		},
    61  		{
    62  			a:      GoVersion{MajorVersion: 1, MinorVersion: 11, PatchVersion: 1},
    63  			b:      GoVersion{MajorVersion: 1, MinorVersion: 11, PatchVersion: 2},
    64  			expect: false,
    65  		},
    66  	} {
    67  		actual := testdata.a.LaterThan(testdata.b)
    68  		if actual != testdata.expect {
    69  			t.Errorf("[%d] wrong result: %v", i, actual)
    70  		}
    71  	}
    72  }