From 3bbd025982be4c530b0187485760164921c57da5 Mon Sep 17 00:00:00 2001 From: Paco Xu Date: Tue, 20 Sep 2022 11:45:33 +0800 Subject: [PATCH] ut: compare dns options without order --- pkg/kubelet/network/dns/dns.go | 40 ++++++++++++++--------------- pkg/kubelet/network/dns/dns_test.go | 2 +- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pkg/kubelet/network/dns/dns.go b/pkg/kubelet/network/dns/dns.go index 061730261c8..1767c85fc7c 100644 --- a/pkg/kubelet/network/dns/dns.go +++ b/pkg/kubelet/network/dns/dns.go @@ -280,26 +280,6 @@ func parseResolvConf(reader io.Reader) (nameservers []string, searches []string, return nameservers, searches, options, utilerrors.NewAggregate(allErrors) } -// appendOptions appends options to the given list, but does not add duplicates. -// append option will overwrite the previous one either in new line or in the same line. -func appendOptions(options []string, newOption ...string) []string { - var optionMap = make(map[string]string) - for _, option := range options { - optName := strings.Split(option, ":")[0] - optionMap[optName] = option - } - for _, option := range newOption { - optName := strings.Split(option, ":")[0] - optionMap[optName] = option - } - - options = []string{} - for _, v := range optionMap { - options = append(options, v) - } - return options -} - func (c *Configurer) getHostDNSConfig() (*runtimeapi.DNSConfig, error) { var hostDNS, hostSearch, hostOptions []string // Get host DNS settings @@ -373,6 +353,26 @@ func mergeDNSOptions(existingDNSConfigOptions []string, dnsConfigOptions []v1.Po return options } +// appendOptions appends options to the given list, but does not add duplicates. +// append option will overwrite the previous one either in new line or in the same line. +func appendOptions(options []string, newOption ...string) []string { + var optionMap = make(map[string]string) + for _, option := range options { + optName := strings.Split(option, ":")[0] + optionMap[optName] = option + } + for _, option := range newOption { + optName := strings.Split(option, ":")[0] + optionMap[optName] = option + } + + options = []string{} + for _, v := range optionMap { + options = append(options, v) + } + return options +} + // appendDNSConfig appends DNS servers, search paths and options given by // PodDNSConfig to the existing DNS config. Duplicated entries will be merged. // This assumes existingDNSConfig and dnsConfig are not nil. diff --git a/pkg/kubelet/network/dns/dns_test.go b/pkg/kubelet/network/dns/dns_test.go index ad451a15c1e..664ca1c22bb 100644 --- a/pkg/kubelet/network/dns/dns_test.go +++ b/pkg/kubelet/network/dns/dns_test.go @@ -105,7 +105,7 @@ func TestParseResolvConf(t *testing.T) { require.NoError(t, err) assert.EqualValues(t, tc.nameservers, ns, "test case [%d]: name servers", i) assert.EqualValues(t, tc.searches, srch, "test case [%d] searches", i) - assert.EqualValues(t, tc.options, opts, "test case [%d] options", i) + assert.EqualValues(t, sets.NewString(tc.options...), sets.NewString(opts...), "test case [%d] options", i) } else { require.Error(t, err, "tc.searches %v", tc.searches) }