github.com/kubewharf/katalyst-core@v0.5.3/pkg/util/external/network/manager_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 network
    21  
    22  import (
    23  	"testing"
    24  
    25  	"github.com/stretchr/testify/assert"
    26  
    27  	"github.com/kubewharf/katalyst-core/pkg/util/cgroup/common"
    28  )
    29  
    30  var (
    31  	podUID             = "pod-id-1"
    32  	containerID        = "container-id-1"
    33  	classID     uint32 = 1
    34  	cgID        uint64 = 1
    35  )
    36  
    37  func TestNewDefaultManager(t *testing.T) {
    38  	t.Parallel()
    39  
    40  	defaultManager := NewNetworkManager()
    41  	assert.NotNil(t, defaultManager)
    42  
    43  	return
    44  }
    45  
    46  func TestApplyNetClass(t *testing.T) {
    47  	t.Parallel()
    48  
    49  	defaultManager := NewNetworkManager()
    50  	assert.NotNil(t, defaultManager)
    51  
    52  	err := defaultManager.ApplyNetClass(podUID, containerID, &common.NetClsData{
    53  		ClassID:  classID,
    54  		CgroupID: cgID,
    55  	})
    56  	assert.Error(t, err)
    57  
    58  	return
    59  }
    60  
    61  func TestClearNetClass(t *testing.T) {
    62  	t.Parallel()
    63  
    64  	defaultManager := NewNetworkManager()
    65  	assert.NotNil(t, defaultManager)
    66  
    67  	err := defaultManager.ClearNetClass(cgID)
    68  	assert.Error(t, err)
    69  
    70  	return
    71  }