github.com/google/cadvisor@v0.49.1/container/docker/factory_test.go (about)

     1  // Copyright 2016 Google Inc. All Rights Reserved.
     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 docker
    16  
    17  import "testing"
    18  
    19  func TestEnsureThinLsKernelVersion(t *testing.T) {
    20  	tests := []struct {
    21  		version       string
    22  		expectedError string
    23  	}{
    24  		{"4.4.0-31-generic", ""},
    25  		{"4.4.1", ""},
    26  		{"4.6.4-301.fc24.x86_64", ""},
    27  		{"3.10.0-327.22.2.el7.x86_64", `RHEL/Centos 7.x kernel version 3.10.0-366 or later is required to use thin_ls - you have "3.10.0-327.22.2.el7.x86_64"`},
    28  		{"3.10.0-366.el7.x86_64", ""},
    29  		{"3.10.0-366.el7_3.x86_64", ""},
    30  		{"3.10.0.el7.abc", `unable to determine RHEL/Centos 7.x kernel release from "3.10.0.el7.abc"`},
    31  		{"3.10.0-abc.el7.blarg", `unable to determine RHEL/Centos 7.x kernel release from "3.10.0-abc.el7.blarg"`},
    32  		{"3.10.0-367.el7.x86_64", ""},
    33  		{"3.10.0-366.x86_64", `kernel version 4.4.0 or later is required to use thin_ls - you have "3.10.0-366.x86_64"`},
    34  		{"3.10.1-1.el7.x86_64", ""},
    35  		{"2.0.36", `kernel version 4.4.0 or later is required to use thin_ls - you have "2.0.36"`},
    36  		{"2.1", `error parsing kernel version: "2.1" is not a semver`},
    37  	}
    38  
    39  	for _, test := range tests {
    40  		err := ensureThinLsKernelVersion(test.version)
    41  		if err != nil {
    42  			if len(test.expectedError) == 0 {
    43  				t.Errorf("%s: expected no error, got %v", test.version, err)
    44  			} else if err.Error() != test.expectedError {
    45  				t.Errorf("%s: expected error %v, got %v", test.version, test.expectedError, err)
    46  			}
    47  		} else if err == nil && len(test.expectedError) > 0 {
    48  			t.Errorf("%s: expected error %v", test.version, test.expectedError)
    49  		}
    50  	}
    51  }