@@ -19,15 +19,17 @@ options edns0
1919
2020func TestNew (t * testing.T ) {
2121 tests := []struct {
22- name string
23- baseContent string
24- nameservers []string
25- options []string
26- searches []string
27- ipv6 bool
28- hostns bool
29- keepHostServers bool
30- want string
22+ name string
23+ baseContent string
24+ nameservers []string
25+ options []string
26+ searches []string
27+ ipv6 bool
28+ hostns bool
29+ keepHostServers bool
30+ keepHostSearches bool
31+ keepHostOptions bool
32+ want string
3133 }{
3234 {
3335 name : "simple resolv.conf" ,
@@ -98,7 +100,36 @@ func TestNew(t *testing.T) {
98100 options : []string {"ndots:2" },
99101 searches : []string {"test.com" },
100102 keepHostServers : true ,
101- want : "search test.com example.com\n nameserver 1.2.3.4\n nameserver 5.6.7.8\n nameserver 1.1.1.1\n options ndots:2 edns0\n " ,
103+ want : "search test.com\n nameserver 1.2.3.4\n nameserver 5.6.7.8\n nameserver 1.1.1.1\n options ndots:2\n " ,
104+ },
105+ {
106+ name : "set all and keep host searches" ,
107+ baseContent : resolv2 ,
108+ nameservers : []string {"1.2.3.4" , "5.6.7.8" },
109+ options : []string {"ndots:2" },
110+ searches : []string {"test.com" },
111+ keepHostSearches : true ,
112+ want : "search test.com example.com\n nameserver 1.2.3.4\n nameserver 5.6.7.8\n options ndots:2\n " ,
113+ },
114+ {
115+ name : "set all and keep host options" ,
116+ baseContent : resolv2 ,
117+ nameservers : []string {"1.2.3.4" , "5.6.7.8" },
118+ options : []string {"ndots:2" },
119+ searches : []string {"test.com" },
120+ keepHostOptions : true ,
121+ want : "search test.com\n nameserver 1.2.3.4\n nameserver 5.6.7.8\n options ndots:2 edns0\n " ,
122+ },
123+ {
124+ name : "set all and keep all options" ,
125+ baseContent : resolv2 ,
126+ nameservers : []string {"1.2.3.4" , "5.6.7.8" },
127+ options : []string {"ndots:2" },
128+ searches : []string {"test.com" },
129+ keepHostServers : true ,
130+ keepHostSearches : true ,
131+ keepHostOptions : true ,
132+ want : "search test.com example.com\n nameserver 1.2.3.4\n nameserver 5.6.7.8\n nameserver 1.1.1.1\n options ndots:2 edns0\n " ,
102133 },
103134 {
104135 name : "localhost nameservers should be filtered and use defaults instead" ,
@@ -148,14 +179,16 @@ func TestNew(t *testing.T) {
148179 }
149180 }
150181 err = New (& Params {
151- Path : target ,
152- Nameservers : tt .nameservers ,
153- Searches : tt .searches ,
154- Options : tt .options ,
155- IPv6Enabled : tt .ipv6 ,
156- KeepHostServers : tt .keepHostServers ,
157- Namespaces : namespaces ,
158- resolvConfPath : base ,
182+ Path : target ,
183+ Nameservers : tt .nameservers ,
184+ Searches : tt .searches ,
185+ Options : tt .options ,
186+ IPv6Enabled : tt .ipv6 ,
187+ KeepHostServers : tt .keepHostServers ,
188+ KeepHostSearches : tt .keepHostSearches ,
189+ KeepHostOptions : tt .keepHostOptions ,
190+ Namespaces : namespaces ,
191+ resolvConfPath : base ,
159192 })
160193 assert .NoError (t , err , "New()" )
161194 content , err := os .ReadFile (target )
0 commit comments