From 20b67a4d1aced3c307dac17ef136a015805602a4 Mon Sep 17 00:00:00 2001 From: "xin.li" Date: Fri, 1 Dec 2023 00:09:05 +0800 Subject: [PATCH] kubeadm: increase ut coverage of util/config Signed-off-by: xin.li --- .../util/config/resetconfiguration_test.go | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/cmd/kubeadm/app/util/config/resetconfiguration_test.go b/cmd/kubeadm/app/util/config/resetconfiguration_test.go index a04f81f7acc..1d9676a133f 100644 --- a/cmd/kubeadm/app/util/config/resetconfiguration_test.go +++ b/cmd/kubeadm/app/util/config/resetconfiguration_test.go @@ -22,6 +22,9 @@ import ( "testing" "github.com/lithammer/dedent" + "github.com/stretchr/testify/assert" + + kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm" ) func TestLoadResetConfigurationFromFile(t *testing.T) { @@ -98,3 +101,53 @@ func TestLoadResetConfigurationFromFile(t *testing.T) { }) } } + +func TestSetResetDynamicDefaults(t *testing.T) { + type args struct { + cfg *kubeadmapi.ResetConfiguration + skipCRIDetect bool + } + tests := []struct { + name string + args args + }{ + { + name: "CRISocket is empty and skipCRIDetect is true", + args: args{ + cfg: &kubeadmapi.ResetConfiguration{}, + skipCRIDetect: true, + }, + }, + { + name: "CRISocket is empty and skipCRIDetect is false", + args: args{ + cfg: &kubeadmapi.ResetConfiguration{}, + skipCRIDetect: false, + }, + }, + { + name: "CRISocket is valid", + args: args{ + cfg: &kubeadmapi.ResetConfiguration{ + CRISocket: "unix:///var/run/containerd/containerd.sock", + }, + skipCRIDetect: false, + }, + }, + { + name: "CRISocket is invalid", + args: args{ + cfg: &kubeadmapi.ResetConfiguration{ + CRISocket: "var/run/containerd/containerd.sock", + }, + skipCRIDetect: false, + }, + }, + } + for _, rt := range tests { + t.Run(rt.name, func(t *testing.T) { + err := SetResetDynamicDefaults(rt.args.cfg, rt.args.skipCRIDetect) + assert.NoError(t, err) + }) + } +}