...

Source file src/k8s.io/kubernetes/pkg/kubelet/cm/cgroup_manager_test.go

Documentation: k8s.io/kubernetes/pkg/kubelet/cm

     1  //go:build linux
     2  // +build linux
     3  
     4  /*
     5  Copyright 2016 The Kubernetes Authors.
     6  
     7  Licensed under the Apache License, Version 2.0 (the "License");
     8  you may not use this file except in compliance with the License.
     9  You may obtain a copy of the License at
    10  
    11      http://www.apache.org/licenses/LICENSE-2.0
    12  
    13  Unless required by applicable law or agreed to in writing, software
    14  distributed under the License is distributed on an "AS IS" BASIS,
    15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16  See the License for the specific language governing permissions and
    17  limitations under the License.
    18  */
    19  
    20  package cm
    21  
    22  import (
    23  	"reflect"
    24  	"testing"
    25  
    26  	"k8s.io/api/core/v1"
    27  )
    28  
    29  func Test(t *testing.T) {
    30  	tests := []struct {
    31  		input    map[string]string
    32  		expected *map[v1.ResourceName]int64
    33  	}{
    34  		{
    35  			input:    map[string]string{"memory": ""},
    36  			expected: nil,
    37  		},
    38  		{
    39  			input:    map[string]string{"memory": "a"},
    40  			expected: nil,
    41  		},
    42  		{
    43  			input:    map[string]string{"memory": "a%"},
    44  			expected: nil,
    45  		},
    46  		{
    47  			input:    map[string]string{"memory": "200%"},
    48  			expected: nil,
    49  		},
    50  		{
    51  			input: map[string]string{"memory": "0%"},
    52  			expected: &map[v1.ResourceName]int64{
    53  				v1.ResourceMemory: 0,
    54  			},
    55  		},
    56  		{
    57  			input: map[string]string{"memory": "100%"},
    58  			expected: &map[v1.ResourceName]int64{
    59  				v1.ResourceMemory: 100,
    60  			},
    61  		},
    62  		{
    63  			// need to change this when CPU is added as a supported resource
    64  			input:    map[string]string{"memory": "100%", "cpu": "50%"},
    65  			expected: nil,
    66  		},
    67  	}
    68  	for _, test := range tests {
    69  		actual, err := ParseQOSReserved(test.input)
    70  		if actual != nil && test.expected == nil {
    71  			t.Errorf("Unexpected success, input: %v, expected: %v, actual: %v, err: %v", test.input, test.expected, actual, err)
    72  		}
    73  		if actual == nil && test.expected != nil {
    74  			t.Errorf("Unexpected failure, input: %v, expected: %v, actual: %v, err: %v", test.input, test.expected, actual, err)
    75  		}
    76  		if (actual == nil && test.expected == nil) || reflect.DeepEqual(*actual, *test.expected) {
    77  			continue
    78  		}
    79  		t.Errorf("Unexpected result, input: %v, expected: %v, actual: %v, err: %v", test.input, test.expected, actual, err)
    80  	}
    81  }
    82  

View as plain text