github.com/kubewharf/katalyst-core@v0.5.3/pkg/util/cgroup/manager/v1/fs_linux_test.go (about)

     1  //go:build linux
     2  // +build linux
     3  
     4  /*
     5  Copyright 2022 The Katalyst 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 v1
    21  
    22  import (
    23  	"reflect"
    24  	"testing"
    25  
    26  	"github.com/kubewharf/katalyst-core/pkg/util/cgroup/common"
    27  )
    28  
    29  func TestNewManager(t *testing.T) {
    30  	t.Parallel()
    31  
    32  	tests := []struct {
    33  		name string
    34  		want *manager
    35  	}{
    36  		{
    37  			name: "test new manager",
    38  			want: &manager{},
    39  		},
    40  	}
    41  	for _, tt := range tests {
    42  		tt := tt
    43  		t.Run(tt.name, func(t *testing.T) {
    44  			t.Parallel()
    45  			if got := NewManager(); !reflect.DeepEqual(got, tt.want) {
    46  				t.Errorf("NewManager() = %v, want %v", got, tt.want)
    47  			}
    48  		})
    49  	}
    50  }
    51  
    52  func Test_manager_ApplyMemory(t *testing.T) {
    53  	t.Parallel()
    54  
    55  	type args struct {
    56  		absCgroupPath string
    57  		data          *common.MemoryData
    58  	}
    59  	tests := []struct {
    60  		name    string
    61  		m       *manager
    62  		args    args
    63  		wantErr bool
    64  	}{
    65  		{
    66  			name: "test apply memory with LimitInBytes",
    67  			m:    NewManager(),
    68  			args: args{
    69  				absCgroupPath: "test-fake-path",
    70  				data: &common.MemoryData{
    71  					LimitInBytes: 1234,
    72  				},
    73  			},
    74  			wantErr: true,
    75  		},
    76  		{
    77  			name: "test apply memory with SoftLimitInBytes",
    78  			m:    NewManager(),
    79  			args: args{
    80  				absCgroupPath: "test-fake-path",
    81  				data: &common.MemoryData{
    82  					SoftLimitInBytes: 2234,
    83  				},
    84  			},
    85  			wantErr: true,
    86  		},
    87  	}
    88  	for _, tt := range tests {
    89  		tt := tt
    90  		t.Run(tt.name, func(t *testing.T) {
    91  			t.Parallel()
    92  
    93  			m := &manager{}
    94  			if err := m.ApplyMemory(tt.args.absCgroupPath, tt.args.data); (err != nil) != tt.wantErr {
    95  				t.Errorf("manager.ApplyMemory() error = %v, wantErr %v", err, tt.wantErr)
    96  			}
    97  		})
    98  	}
    99  }