github.com/kubewharf/katalyst-core@v0.5.3/pkg/util/native/kubelet_test.go (about)

     1  /*
     2  Copyright 2022 The Katalyst Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package native
    18  
    19  import (
    20  	"context"
    21  	"testing"
    22  
    23  	"github.com/stretchr/testify/assert"
    24  	kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"
    25  )
    26  
    27  func TestGenerateURI(t *testing.T) {
    28  	t.Parallel()
    29  
    30  	port := 10250
    31  	nodeAddress := "127.0.0.1"
    32  	endpoint := "/configz"
    33  
    34  	uri, err := generateURI(port, nodeAddress, endpoint)
    35  	assert.NoError(t, err)
    36  	assert.Equal(t, "https://127.0.0.1:10250/configz", uri)
    37  }
    38  
    39  func TestInsecureConfig(t *testing.T) {
    40  	t.Parallel()
    41  
    42  	host := "https://127.0.0.1:10250/configz"
    43  	authTokenFile := "/var/run/secrets/kubernetes.io/serviceaccount/token"
    44  
    45  	_, err := insecureConfig(host, authTokenFile)
    46  	assert.Error(t, err)
    47  }
    48  
    49  func TestGetAndUnmarshalForHttps(t *testing.T) {
    50  	t.Parallel()
    51  
    52  	port := 10250
    53  	nodeAddress := "127.0.0.1"
    54  	endpoint := "/configz"
    55  	authTokenFile := "/var/run/secrets/kubernetes.io/serviceaccount/token"
    56  
    57  	type configzWrapper struct {
    58  		ComponentConfig kubeletconfigv1beta1.KubeletConfiguration `json:"kubeletconfig"`
    59  	}
    60  	configz := configzWrapper{}
    61  
    62  	err := GetAndUnmarshalForHttps(context.TODO(), port, nodeAddress, endpoint, authTokenFile, &configz)
    63  	assert.Error(t, err)
    64  }