mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Merge pull request #125545 from claudiubelu/unittests-12
unittests: Fixes unit tests for Windows (part 12)
This commit is contained in:
commit
e832b70230
@ -455,8 +455,10 @@ func TestMigrateOldConfig(t *testing.T) {
|
||||
// - JoinConfiguration.Discovery.Timeout -> JoinConfiguration.Timeout.Discovery
|
||||
func TestMigrateV1Beta3WithBreakingChanges(t *testing.T) {
|
||||
var (
|
||||
gv = kubeadmapiv1old.SchemeGroupVersion.String()
|
||||
gvNew = kubeadmapiv1.SchemeGroupVersion.String()
|
||||
gv = kubeadmapiv1old.SchemeGroupVersion.String()
|
||||
gvNew = kubeadmapiv1.SchemeGroupVersion.String()
|
||||
criSocket = fmt.Sprintf("%s:///some-socket-path", kubeadmapiv1.DefaultContainerRuntimeURLScheme)
|
||||
caCertPath = kubeadmapiv1.DefaultCACertPath
|
||||
|
||||
input = dedent.Dedent(fmt.Sprintf(`
|
||||
apiVersion: %s
|
||||
@ -473,7 +475,7 @@ func TestMigrateV1Beta3WithBreakingChanges(t *testing.T) {
|
||||
advertiseAddress: 1.2.3.4
|
||||
bindPort: 6443
|
||||
nodeRegistration:
|
||||
criSocket: unix:///some-socket-path
|
||||
criSocket: %[2]s
|
||||
kubeletExtraArgs: # MIGRATED
|
||||
foo: bar
|
||||
name: node
|
||||
@ -499,7 +501,7 @@ func TestMigrateV1Beta3WithBreakingChanges(t *testing.T) {
|
||||
apiVersion: %[1]s
|
||||
kind: JoinConfiguration
|
||||
nodeRegistration:
|
||||
criSocket: unix:///some-socket-path
|
||||
criSocket: %[2]s
|
||||
imagePullPolicy: IfNotPresent
|
||||
kubeletExtraArgs: # MIGRATED
|
||||
foo: baz
|
||||
@ -512,7 +514,7 @@ func TestMigrateV1Beta3WithBreakingChanges(t *testing.T) {
|
||||
unsafeSkipCAVerification: true
|
||||
tlsBootstrapToken: abcdef.0123456789abcdef
|
||||
timeout: 2m10s # MIGRATED
|
||||
`, gv))
|
||||
`, gv, criSocket))
|
||||
|
||||
expectedOutput = dedent.Dedent(fmt.Sprintf(`
|
||||
apiVersion: %s
|
||||
@ -529,7 +531,7 @@ func TestMigrateV1Beta3WithBreakingChanges(t *testing.T) {
|
||||
advertiseAddress: 1.2.3.4
|
||||
bindPort: 6443
|
||||
nodeRegistration:
|
||||
criSocket: unix:///some-socket-path
|
||||
criSocket: %[2]s
|
||||
imagePullPolicy: IfNotPresent
|
||||
imagePullSerial: true
|
||||
kubeletExtraArgs:
|
||||
@ -582,7 +584,7 @@ func TestMigrateV1Beta3WithBreakingChanges(t *testing.T) {
|
||||
value: bar
|
||||
---
|
||||
apiVersion: %[1]s
|
||||
caCertPath: /etc/kubernetes/pki/ca.crt
|
||||
caCertPath: %[3]s
|
||||
discovery:
|
||||
bootstrapToken:
|
||||
apiServerEndpoint: some-address:6443
|
||||
@ -591,7 +593,7 @@ func TestMigrateV1Beta3WithBreakingChanges(t *testing.T) {
|
||||
tlsBootstrapToken: abcdef.0123456789abcdef
|
||||
kind: JoinConfiguration
|
||||
nodeRegistration:
|
||||
criSocket: unix:///some-socket-path
|
||||
criSocket: %[2]s
|
||||
imagePullPolicy: IfNotPresent
|
||||
imagePullSerial: true
|
||||
kubeletExtraArgs:
|
||||
@ -607,7 +609,7 @@ func TestMigrateV1Beta3WithBreakingChanges(t *testing.T) {
|
||||
kubernetesAPICall: 1m0s
|
||||
tlsBootstrap: 5m0s
|
||||
upgradeManifests: 5m0s
|
||||
`, gvNew))
|
||||
`, gvNew, criSocket, caCertPath))
|
||||
)
|
||||
|
||||
b, err := MigrateOldConfig([]byte(input), false, defaultEmptyMigrateMutators())
|
||||
|
@ -20,13 +20,12 @@ limitations under the License.
|
||||
package util
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/Microsoft/go-winio"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@ -98,13 +97,10 @@ func TestLocalEndpoint(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func npipeDial(ctx context.Context, addr string) (net.Conn, error) {
|
||||
return winio.DialPipeContext(ctx, addr)
|
||||
}
|
||||
|
||||
func TestLocalEndpointRoundTrip(t *testing.T) {
|
||||
npipeDialPointer := reflect.ValueOf(npipeDial).Pointer()
|
||||
expectedDialerName := runtime.FuncForPC(npipeDialPointer).Name()
|
||||
functionPointer := reflect.ValueOf(util.GetAddressAndDialer).Pointer()
|
||||
functionName := runtime.FuncForPC(functionPointer).Name()
|
||||
expectedDialerName := fmt.Sprintf("%s.npipeDial", functionName[:strings.LastIndex(functionName, ".")])
|
||||
expectedAddress := "//./pipe/kubelet-pod-resources"
|
||||
|
||||
fullPath, err := LocalEndpoint(`pod-resources`, "kubelet")
|
||||
@ -116,8 +112,6 @@ func TestLocalEndpointRoundTrip(t *testing.T) {
|
||||
dialerPointer := reflect.ValueOf(dialer).Pointer()
|
||||
actualDialerName := runtime.FuncForPC(dialerPointer).Name()
|
||||
|
||||
assert.Equalf(t, npipeDialPointer, dialerPointer,
|
||||
"Expected dialer %s, but get %s", expectedDialerName, actualDialerName)
|
||||
|
||||
assert.Equal(t, expectedDialerName, actualDialerName)
|
||||
assert.Equal(t, expectedAddress, address)
|
||||
}
|
||||
|
42
pkg/proxy/apis/config/validation/validation_other_test.go
Normal file
42
pkg/proxy/apis/config/validation/validation_other_test.go
Normal file
@ -0,0 +1,42 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
/*
|
||||
Copyright 2024 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package validation
|
||||
|
||||
import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
kubeproxyconfig "k8s.io/kubernetes/pkg/proxy/apis/config"
|
||||
)
|
||||
|
||||
var (
|
||||
kubeProxyConfigNewPath = field.NewPath("KubeProxyConfiguration")
|
||||
osKubeProxyConfigTestCases = map[string]struct {
|
||||
mutateConfigFunc func(*kubeproxyconfig.KubeProxyConfiguration)
|
||||
expectedErrs field.ErrorList
|
||||
}{
|
||||
// Windows doesn't support IPVS, so this test will fail.
|
||||
"IPVS mode selected without providing required SyncPeriod": {
|
||||
mutateConfigFunc: func(config *kubeproxyconfig.KubeProxyConfiguration) {
|
||||
config.Mode = kubeproxyconfig.ProxyModeIPVS
|
||||
},
|
||||
expectedErrs: field.ErrorList{field.Invalid(kubeProxyConfigNewPath.Child("KubeProxyIPVSConfiguration.SyncPeriod"), metav1.Duration{Duration: 0}, "must be greater than 0")},
|
||||
},
|
||||
}
|
||||
)
|
@ -55,7 +55,7 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
|
||||
}
|
||||
newPath := field.NewPath("KubeProxyConfiguration")
|
||||
|
||||
for name, testCase := range map[string]struct {
|
||||
testCases := map[string]struct {
|
||||
mutateConfigFunc func(*kubeproxyconfig.KubeProxyConfiguration)
|
||||
expectedErrs field.ErrorList
|
||||
}{
|
||||
@ -155,12 +155,6 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
|
||||
},
|
||||
expectedErrs: field.ErrorList{field.Invalid(newPath.Child("ConfigSyncPeriod"), metav1.Duration{Duration: -1 * time.Second}, "must be greater than 0")},
|
||||
},
|
||||
"IPVS mode selected without providing required SyncPeriod": {
|
||||
mutateConfigFunc: func(config *kubeproxyconfig.KubeProxyConfiguration) {
|
||||
config.Mode = kubeproxyconfig.ProxyModeIPVS
|
||||
},
|
||||
expectedErrs: field.ErrorList{field.Invalid(newPath.Child("KubeProxyIPVSConfiguration.SyncPeriod"), metav1.Duration{Duration: 0}, "must be greater than 0")},
|
||||
},
|
||||
"interfacePrefix is empty": {
|
||||
mutateConfigFunc: func(config *kubeproxyconfig.KubeProxyConfiguration) {
|
||||
config.DetectLocalMode = kubeproxyconfig.LocalModeInterfaceNamePrefix
|
||||
@ -193,7 +187,13 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
|
||||
},
|
||||
expectedErrs: field.ErrorList{field.Invalid(newPath.Child("logging.format"), "unsupported format", "Unsupported log format")},
|
||||
},
|
||||
} {
|
||||
}
|
||||
|
||||
for name, testCase := range osKubeProxyConfigTestCases {
|
||||
testCases[name] = testCase
|
||||
}
|
||||
|
||||
for name, testCase := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
config := baseConfig.DeepCopy()
|
||||
testCase.mutateConfigFunc(config)
|
||||
|
32
pkg/proxy/apis/config/validation/validation_windows_test.go
Normal file
32
pkg/proxy/apis/config/validation/validation_windows_test.go
Normal file
@ -0,0 +1,32 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
/*
|
||||
Copyright 2024 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package validation
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
kubeproxyconfig "k8s.io/kubernetes/pkg/proxy/apis/config"
|
||||
)
|
||||
|
||||
var (
|
||||
osKubeProxyConfigTestCases = map[string]struct {
|
||||
mutateConfigFunc func(*kubeproxyconfig.KubeProxyConfiguration)
|
||||
expectedErrs field.ErrorList
|
||||
}{}
|
||||
)
|
Loading…
Reference in New Issue
Block a user