@@ -3,6 +3,7 @@ package main
33import (
44 "log"
55 "os"
6+ "os/exec"
67 "testing"
78 "time"
89
@@ -114,7 +115,7 @@ func TestUninstallGenerateScript(t *testing.T) {
114115
115116 subscribeTopic (s .mqttClient , "0" , "/status/uninstall/post" , s , s .Uninstall , false )
116117
117- resp := dashboard .MqttSendAndReceiveTimeout (t , "/status/uninstall" , "{}" , 50 * time .Millisecond )
118+ resp := dashboard .MqttSendAndReceiveTimeout (t , "/status/uninstall" , "{}" , 500 * time .Millisecond )
118119 assert .True (t , resp == "INFO: OK\n " )
119120
120121 dir , _ := osext .ExecutableFolder ()
@@ -266,3 +267,68 @@ func TestUninstallAllImages(t *testing.T) {
266267 resp := dashboard .MqttSendAndReceiveTimeout (t , "/status/uninstall" , "{}" , 5 * time .Minute )
267268 assert .True (t , resp == "INFO: OK\n " )
268269}
270+
271+ func TestUninstallNetworkManagerNotRemove (t * testing.T ) {
272+ dashboard := newMqttTestClientLocal ()
273+ defer dashboard .Close ()
274+
275+ s := NewStatus (Config {}, nil , nil , "" )
276+ s .mqttClient = mqtt .NewClient (mqtt .NewClientOptions ().AddBroker ("tcp://localhost:1883" ).SetClientID ("arduino-connector" ))
277+ if token := s .mqttClient .Connect (); token .Wait () && token .Error () != nil {
278+ log .Fatal (token .Error ())
279+ }
280+ defer s .mqttClient .Disconnect (100 )
281+
282+ subscribeTopic (s .mqttClient , "0" , "/status/uninstall/post" , s , s .Uninstall , false )
283+
284+ c := exec .Command ("bash" , "-c" , "apt-get install -y network-manager" )
285+ _ , errCmd := c .CombinedOutput ()
286+ assert .True (t , errCmd == nil )
287+
288+ defer func () {
289+ c := exec .Command ("bash" , "-c" , "apt-get remove -y network-manager" )
290+ _ , err := c .CombinedOutput ()
291+ assert .True (t , err == nil )
292+
293+ assert .False (t , isNetManagerInstalled ())
294+ }()
295+
296+ errConfig := createConfig ()
297+ assert .True (t , errConfig == nil )
298+
299+ assert .True (t , isNetManagerInstalled ())
300+
301+ resp := dashboard .MqttSendAndReceiveTimeout (t , "/status/uninstall" , "{}" , 5 * time .Minute )
302+ assert .True (t , resp == "INFO: OK\n " )
303+ assert .True (t , isNetManagerInstalled ())
304+ }
305+
306+ func TestUninstallNetworkManager (t * testing.T ) {
307+ dashboard := newMqttTestClientLocal ()
308+ defer dashboard .Close ()
309+
310+ s := NewStatus (Config {}, nil , nil , "" )
311+ s .mqttClient = mqtt .NewClient (mqtt .NewClientOptions ().AddBroker ("tcp://localhost:1883" ).SetClientID ("arduino-connector" ))
312+ if token := s .mqttClient .Connect (); token .Wait () && token .Error () != nil {
313+ log .Fatal (token .Error ())
314+ }
315+ defer s .mqttClient .Disconnect (100 )
316+
317+ subscribeTopic (s .mqttClient , "0" , "/status/uninstall/post" , s , s .Uninstall , false )
318+
319+ err := createConfig ()
320+ assert .True (t , err == nil )
321+
322+ assert .False (t , isNetManagerInstalled ())
323+
324+ c := exec .Command ("bash" , "-c" , "apt-get install -y network-manager" )
325+ _ , err = c .CombinedOutput ()
326+ assert .True (t , err == nil )
327+
328+ assert .True (t , isNetManagerInstalled ())
329+
330+ resp := dashboard .MqttSendAndReceiveTimeout (t , "/status/uninstall" , "{}" , 5 * time .Minute )
331+ assert .True (t , resp == "INFO: OK\n " )
332+
333+ assert .False (t , isNetManagerInstalled ())
334+ }
0 commit comments