@@ -55,8 +55,21 @@ function TestUpdateConfig.test_update()
5555 local networkFile = io.open (config_dir .. ' network' )
5656 luaunit .assertNotNil (networkFile )
5757 local networkContents = networkFile :read (' *all' )
58+ -- ensure interface added is present
5859 luaunit .assertNotNil (string.find (networkContents , " config interface 'added'" ))
5960 luaunit .assertNotNil (string.find (networkContents , " option ifname 'added0'" ))
61+ -- ensure wg1 added via remote previously is present
62+ luaunit .assertNotNil (string.find (networkContents , " config interface 'wg1'" ))
63+ luaunit .assertNotNil (string.find (networkContents , " option proto 'static'" ))
64+ -- ensure network file is stored for backup
65+ local storedNetworkFile = io.open (stored_dir .. ' /etc/config/network' )
66+ luaunit .assertNotNil (storedNetworkFile )
67+ local storedNetworkContents = storedNetworkFile :read (' *all' )
68+ -- ensure wg1 is not added that is downloaded from remote
69+ luaunit .assertNil (string.find (storedNetworkContents , " config interface 'wg1'" ))
70+ -- ensure wan and wg0 are present
71+ luaunit .assertNotNil (string.find (storedNetworkContents , " config interface 'wan'" ))
72+ luaunit .assertNotNil (string.find (storedNetworkContents , " config interface 'wg0'" ))
6073 -- check system
6174 local systemFile = io.open (config_dir .. ' system' )
6275 luaunit .assertNotNil (systemFile )
@@ -69,6 +82,16 @@ function TestUpdateConfig.test_update()
6982 -- ensure rest of config options are present
7083 luaunit .assertNotNil (string.find (systemContents , " config timeserver 'ntp'" ))
7184 luaunit .assertNotNil (string.find (systemContents , " list server '3.openwrt.pool.ntp.org'" ))
85+ -- ensure system file is stored for backup
86+ local storedSystemFile = io.open (stored_dir .. ' /etc/config/network' )
87+ luaunit .assertNotNil (storedSystemFile )
88+ local storedSystemContents = storedSystemFile :read (' *all' )
89+ -- ensure hostname is not added that is updated from remote
90+ luaunit .assertNil (string.find (storedSystemContents , " option hostname" ))
91+ -- ensure custom is not added that is downloaded from remote
92+ luaunit .assertNil (string.find (storedSystemContents , " option custom 'custom'" ))
93+ -- ensure new is not added that is downloaded from remote
94+ luaunit .assertNil (string.find (storedSystemContents , " config new 'new'" ))
7295 -- ensure test file is present
7396 local testFile = io.open (write_dir .. ' etc/test' )
7497 luaunit .assertNotNil (testFile )
@@ -109,7 +132,7 @@ function TestUpdateConfig.test_update()
109132 local modifiedListFile = io.open (openwisp_dir .. ' /modified.list' )
110133 luaunit .assertNotNil (modifiedListFile )
111134 luaunit .assertEquals (modifiedListFile :read (' *all' ), ' /etc/existing\n ' )
112- local storedExisitngFile = io.open (openwisp_dir .. ' /stored /etc/existing' )
135+ local storedExisitngFile = io.open (stored_dir .. ' /etc/existing' )
113136 luaunit .assertNotNil (storedExisitngFile )
114137 luaunit .assertEquals (storedExisitngFile :read (' *all' ), ' original\n ' )
115138 -- ensure it has been modified
@@ -122,12 +145,7 @@ function TestUpdateConfig.test_update()
122145 local restoreFile = io.open (write_dir .. ' /etc/restore-me' )
123146 luaunit .assertNotNil (restoreFile )
124147 luaunit .assertEquals (restoreFile :read (' *all' ), ' restore-me\n ' )
125- luaunit .assertNil (io.open (openwisp_dir .. ' /stored/etc/restore-me' ))
126- -- ensure network and configuration file is not backed up as it is overwritten by remote
127- local storedNetworkFile = io.open (openwisp_dir .. ' /etc/config/network' )
128- luaunit .assertNil (storedNetworkFile )
129- local storedSystemFile = io.open (openwisp_dir .. ' /etc/config/system' )
130- luaunit .assertNil (storedSystemFile )
148+ luaunit .assertNil (io.open (stored_dir .. ' /etc/restore-me' ))
131149end
132150
133151function TestUpdateConfig .test_update_conf_arg ()
@@ -160,7 +178,7 @@ function TestUpdateConfig.test_duplicate_list_options()
160178 luaunit .assertEquals (string_count (networkContents , " list ipaddr '192.168.10.3/24'" ), 1 )
161179 luaunit .assertEquals (string_count (networkContents , " list addresses '10.0.0.2'" ), 1 )
162180 luaunit .assertEquals (string_count (networkContents , " list addresses '10.0.0.3'" ), 1 )
163- luaunit .assertEquals (string_count (networkContents , " list addresses '10.0.0.4'" ), 1 )
181+ luaunit .assertEquals (string_count (networkContents , " list addresses '10.0.0.4'" ), 2 )
164182 luaunit .assertNotNil (string.find (networkContents , " option test_restore '2'" ))
165183 -- repeating the operation has the same result
166184 update_config (' --test=1' , ' --conf=./test-duplicate-list.tar.gz' )
@@ -172,7 +190,7 @@ function TestUpdateConfig.test_duplicate_list_options()
172190 luaunit .assertEquals (string_count (networkContents , " list ipaddr '192.168.10.3/24'" ), 1 )
173191 luaunit .assertEquals (string_count (networkContents , " list addresses '10.0.0.2'" ), 1 )
174192 luaunit .assertEquals (string_count (networkContents , " list addresses '10.0.0.3'" ), 1 )
175- luaunit .assertEquals (string_count (networkContents , " list addresses '10.0.0.4'" ), 1 )
193+ luaunit .assertEquals (string_count (networkContents , " list addresses '10.0.0.4'" ), 2 )
176194 luaunit .assertNotNil (string.find (networkContents , " option test_restore '2'" ))
177195end
178196
@@ -187,7 +205,7 @@ function TestUpdateConfig.test_removal_list_options()
187205 luaunit .assertEquals (string_count (networkContents , " list ipaddr '192.168.10.3/24'" ), 1 )
188206 luaunit .assertEquals (string_count (networkContents , " list addresses '10.0.0.2'" ), 0 )
189207 luaunit .assertEquals (string_count (networkContents , " list addresses '10.0.0.3'" ), 1 )
190- luaunit .assertEquals (string_count (networkContents , " list addresses '10.0.0.4'" ), 1 )
208+ luaunit .assertEquals (string_count (networkContents , " list addresses '10.0.0.4'" ), 2 )
191209 luaunit .assertNotNil (string.find (networkContents , " option test_restore '2'" ))
192210end
193211
0 commit comments