github.com/elfadel/cilium@v1.6.12/pkg/version/version_test.go (about)

     1  // Copyright 2017 Authors of Cilium
     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  // +build !privileged_tests
    16  
    17  package version
    18  
    19  import (
    20  	"testing"
    21  
    22  	. "gopkg.in/check.v1"
    23  )
    24  
    25  // Hook up gocheck into the "go test" runner.
    26  func Test(t *testing.T) { TestingT(t) }
    27  
    28  type VersionSuite struct {
    29  }
    30  
    31  var _ = Suite(&VersionSuite{})
    32  
    33  func (vs *VersionSuite) TestStructIsSet(c *C) {
    34  	var versionDataList = []struct {
    35  		in  string
    36  		out CiliumVersion
    37  	}{
    38  		{
    39  			"0.11.90 774ecd3 2018-01-09T22:32:37+01:00 go version go1.8.3 linux/amd64",
    40  			CiliumVersion{
    41  				Version:          "0.11.90",
    42  				Revision:         "774ecd3",
    43  				GoRuntimeVersion: "go1.8.3",
    44  				Arch:             "linux/amd64",
    45  				AuthorDate:       "2018-01-09T22:32:37+01:00",
    46  			},
    47  		},
    48  		{
    49  			"0.11.90 774ecd3 2018-01-09T22:32:37+01:00 go version go1.9 someArch/i8726",
    50  			CiliumVersion{
    51  				Version:          "0.11.90",
    52  				Revision:         "774ecd3",
    53  				GoRuntimeVersion: "go1.9",
    54  				Arch:             "someArch/i8726",
    55  				AuthorDate:       "2018-01-09T22:32:37+01:00",
    56  			},
    57  		},
    58  		{
    59  			"278.121.290 774ecd3 2018-01-09T22:32:37+01:00 go version go2522.2520.25251 windows/amd64",
    60  			CiliumVersion{
    61  				Version:          "278.121.290",
    62  				Revision:         "774ecd3",
    63  				GoRuntimeVersion: "go2522.2520.25251",
    64  				Arch:             "windows/amd64",
    65  				AuthorDate:       "2018-01-09T22:32:37+01:00",
    66  			},
    67  		},
    68  		{
    69  			"0.13.90 7330b8d 2018-01-09T22:32:37+01:00 go version go1.8.3 linux/arm",
    70  			CiliumVersion{
    71  				Version:          "0.13.90",
    72  				Revision:         "7330b8d",
    73  				GoRuntimeVersion: "go1.8.3",
    74  				Arch:             "linux/arm",
    75  				AuthorDate:       "2018-01-09T22:32:37+01:00",
    76  			},
    77  		},
    78  		// Unformatted string should return empty struct
    79  		{
    80  			"0.13.90 7330b8d linux/arm",
    81  			CiliumVersion{
    82  				Version:          "",
    83  				Revision:         "",
    84  				GoRuntimeVersion: "",
    85  				Arch:             "",
    86  				AuthorDate:       "",
    87  			},
    88  		},
    89  	}
    90  
    91  	for _, tt := range versionDataList {
    92  		cver := FromString(tt.in)
    93  		c.Assert(cver.Version, Equals, tt.out.Version)
    94  		c.Assert(cver.Revision, Equals, tt.out.Revision)
    95  		c.Assert(cver.GoRuntimeVersion, Equals, tt.out.GoRuntimeVersion)
    96  		c.Assert(cver.Arch, Equals, tt.out.Arch)
    97  		c.Assert(cver.AuthorDate, Equals, tt.out.AuthorDate)
    98  	}
    99  }