package updater import ( "context" "fmt" "math/rand" "testing" "time" "forge.cadoles.com/Pyxis/orion/emlid" ) func TestClientSavedWiFiNetworks(t *testing.T) { if !*runUpdaterIntegrationTests { t.Skip("To run this test, use: go test -updater-integration") } client := NewClient( emlid.WithStandardLogger(), emlid.WithEndpoint(*reachHost, 80), ) if err := client.Connect(); err != nil { t.Fatal(err) } ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() _, err := client.WifiNetworks(ctx) if err != nil { t.Error(err) } defer client.Close() } func TestClientCRUDWiFiNetwork(t *testing.T) { if !*runUpdaterIntegrationTests { t.Skip("To run this test, use: go test -updater-integration") } client := NewClient( emlid.WithStandardLogger(), emlid.WithEndpoint(*reachHost, 80), ) if err := client.Connect(); err != nil { t.Fatal(err) } ssid := fmt.Sprintf("wifi_test_%d", rand.Uint32()) ctx := context.Background() addWifiContext, addWifiCancel := context.WithTimeout(ctx, 5*time.Second) defer addWifiCancel() done, err := client.AddWifiNetwork(addWifiContext, ssid, SecurityOpen, "") if err != nil { t.Error(err) } if g, e := done, true; g != e { t.Errorf("AddWifiNetwork() -> done: got '%v', expected '%v'", g, e) } wifiContext, wifiCancel := context.WithTimeout(ctx, 5*time.Second) defer wifiCancel() networks, err := client.WifiNetworks(wifiContext) if err != nil { t.Error(err) } found := false for _, n := range networks { if n.SSID == ssid { found = true break } } if g, e := found, true; g != e { t.Errorf("wifi network '%s' should exists", ssid) } removeWifiContext, removeWifiCancel := context.WithTimeout(ctx, 5*time.Second) defer removeWifiCancel() done, err = client.RemoveWifiNetwork(removeWifiContext, ssid) if err != nil { t.Error(err) } if g, e := done, true; g != e { t.Errorf("RemoveWifiNetwork() -> done: got '%v', expected '%v'", g, e) } defer client.Close() } func TestClientWifiNetworkJoin(t *testing.T) { if !*runUpdaterIntegrationTests { t.Skip("To run this test, use: go test -updater-integration") } if !*runJoinNetworkTest { t.Skip("To run this test, use: go test -updater-join-network-test") } client := NewClient( emlid.WithStandardLogger(), emlid.WithEndpoint(*reachHost, 80), ) if err := client.Connect(); err != nil { t.Fatal(err) } ssid := fmt.Sprintf("wifi_test_%d", rand.Uint32()) ctx := context.Background() addWifiContext, addWifiCancel := context.WithTimeout(ctx, 5*time.Second) defer addWifiCancel() done, err := client.AddWifiNetwork(addWifiContext, ssid, SecurityOpen, "") if err != nil { t.Error(err) } if g, e := done, true; g != e { t.Errorf("AddWifiNetwork() -> done: got '%v', expected '%v'", g, e) } joinWifiContext, joinWifiCancel := context.WithTimeout(ctx, 5*time.Second) defer joinWifiCancel() if err := client.JoinWifiNetwork(joinWifiContext, ssid, true); err != nil { t.Error(err) } time.Sleep(5 * time.Second) defer client.Close() }