@@ -47,10 +47,10 @@ import (
4747)
4848
4949func TestNewPlatform (t * testing.T ) {
50- _ , err := NewPlatform (WarmpoolPlatform , nil , "" , nil )
50+ _ , err := NewPlatform (Config { Name : WarmpoolPlatform } , nil , "" , nil )
5151 assert .NoError (t , err )
5252
53- _ , err = NewPlatform ("invalid-platform" , nil , "" , nil )
53+ _ , err = NewPlatform (Config { Name : "invalid-platform" } , nil , "" , nil )
5454 assert .Error (t , err )
5555}
5656
@@ -170,6 +170,77 @@ func TestCommon_CreateDNSFiles(t *testing.T) {
170170 require .NoError (t , err )
171171}
172172
173+ func TestCommon_CreateDNSFilesForDebug (t * testing.T ) {
174+ ctrl := gomock .NewController (t )
175+ defer ctrl .Finish ()
176+
177+ for _ , testCase := range []struct {
178+ name string
179+ resolvConfPath string
180+ }{
181+ {name : "al" , resolvConfPath : "/etc" },
182+ {name : "br" , resolvConfPath : "/run/netdog" },
183+ } {
184+ t .Run (testCase .name , func (t * testing.T ) {
185+ netNSName := "netns-name"
186+ netNSPath := "/etc/netns/" + netNSName
187+ iface := getTestInterface ()
188+
189+ netns := & tasknetworkconfig.NetworkNamespace {
190+ Name : netNSName ,
191+ Path : netNSPath ,
192+ NetworkInterfaces : []* networkinterface.NetworkInterface {iface },
193+ }
194+
195+ ioutil := mock_ioutilwrapper .NewMockIOUtil (ctrl )
196+ nsUtil := mock_ecscni .NewMockNetNSUtil (ctrl )
197+ osWrapper := mock_oswrapper .NewMockOS (ctrl )
198+ mockFile := mock_oswrapper .NewMockFile (ctrl )
199+ volumeAccessor := mock_volume .NewMockTaskVolumeAccessor (ctrl )
200+ commonPlatform := & common {
201+ ioutil : ioutil ,
202+ nsUtil : nsUtil ,
203+ os : osWrapper ,
204+ dnsVolumeAccessor : volumeAccessor ,
205+ resolvConfPath : testCase .resolvConfPath ,
206+ }
207+
208+ hostnameData := fmt .Sprintf ("%s\n " , iface .GetHostname ())
209+
210+ taskID := "taskID"
211+ gomock .InOrder (
212+ // Read hostname file.
213+ osWrapper .EXPECT ().OpenFile ("/etc/hostname" , os .O_RDONLY | os .O_CREATE , fs .FileMode (0644 )).Return (mockFile , nil ).Times (1 ),
214+ mockFile .EXPECT ().Close ().Times (1 ),
215+
216+ // Creation of netns path.
217+ osWrapper .EXPECT ().Stat (netNSPath ).Return (nil , os .ErrNotExist ).Times (1 ),
218+ osWrapper .EXPECT ().IsNotExist (os .ErrNotExist ).Return (true ).Times (1 ),
219+ osWrapper .EXPECT ().MkdirAll (netNSPath , fs .FileMode (0644 )),
220+
221+ // Write hostname file.
222+ ioutil .EXPECT ().WriteFile (netNSPath + "/hostname" , []byte (hostnameData ), fs .FileMode (0644 )),
223+
224+ // Copy resolv.conf file.
225+ ioutil .EXPECT ().ReadFile (testCase .resolvConfPath + "/resolv.conf" ),
226+ ioutil .EXPECT ().WriteFile (netNSPath + "/resolv.conf" , gomock .Any (), gomock .Any ()),
227+
228+ // Creation of hosts file.
229+ ioutil .EXPECT ().ReadFile ("/etc/hosts" ),
230+ ioutil .EXPECT ().WriteFile (netNSPath + "/hosts" , gomock .Any (), gomock .Any ()),
231+
232+ // CopyToVolume created files into task volume.
233+ volumeAccessor .EXPECT ().CopyToVolume (taskID , netNSPath + "/hosts" , "hosts" , fs .FileMode (0644 )).Return (nil ).Times (1 ),
234+ volumeAccessor .EXPECT ().CopyToVolume (taskID , netNSPath + "/resolv.conf" , "resolv.conf" , fs .FileMode (0644 )).Return (nil ).Times (1 ),
235+ volumeAccessor .EXPECT ().CopyToVolume (taskID , netNSPath + "/hostname" , "hostname" , fs .FileMode (0644 )).Return (nil ).Times (1 ),
236+ )
237+ err := commonPlatform .createDNSConfig (taskID , true , netns )
238+ require .NoError (t , err )
239+ })
240+ }
241+
242+ }
243+
173244func TestCommon_ConfigureInterface (t * testing.T ) {
174245 t .Run ("regular-eni" , testRegularENIConfiguration )
175246 t .Run ("branch-eni" , testBranchENIConfiguration )
0 commit comments