2018-09-21 12:31:52 +02:00
|
|
|
package updater
|
2018-09-19 13:00:08 +02:00
|
|
|
|
|
|
|
import (
|
2018-09-26 12:05:55 +02:00
|
|
|
"context"
|
2018-09-19 13:00:08 +02:00
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"testing"
|
2018-09-20 10:59:39 +02:00
|
|
|
"time"
|
2018-09-21 12:31:52 +02:00
|
|
|
|
|
|
|
"forge.cadoles.com/Pyxis/orion/emlid"
|
2018-09-19 13:00:08 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestClientSavedWiFiNetworks(t *testing.T) {
|
|
|
|
|
2018-09-19 17:13:45 +02:00
|
|
|
if !*runUpdaterIntegrationTests {
|
2018-09-19 17:24:17 +02:00
|
|
|
t.Skip("To run this test, use: go test -updater-integration")
|
2018-09-19 15:29:44 +02:00
|
|
|
}
|
|
|
|
|
2018-09-21 12:31:52 +02:00
|
|
|
client := NewClient(
|
|
|
|
emlid.WithStandardLogger(),
|
|
|
|
emlid.WithEndpoint(*reachHost, 80),
|
2018-09-19 13:00:08 +02:00
|
|
|
)
|
|
|
|
if err := client.Connect(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-09-26 12:05:55 +02:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
_, err := client.WifiNetworks(ctx)
|
2018-09-19 13:00:08 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer client.Close()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientCRUDWiFiNetwork(t *testing.T) {
|
|
|
|
|
2018-09-19 17:13:45 +02:00
|
|
|
if !*runUpdaterIntegrationTests {
|
2018-09-19 17:24:17 +02:00
|
|
|
t.Skip("To run this test, use: go test -updater-integration")
|
2018-09-19 15:29:44 +02:00
|
|
|
}
|
|
|
|
|
2018-09-21 12:31:52 +02:00
|
|
|
client := NewClient(
|
|
|
|
emlid.WithStandardLogger(),
|
|
|
|
emlid.WithEndpoint(*reachHost, 80),
|
2018-09-19 13:00:08 +02:00
|
|
|
)
|
|
|
|
if err := client.Connect(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ssid := fmt.Sprintf("wifi_test_%d", rand.Uint32())
|
|
|
|
|
2018-09-26 12:05:55 +02:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
addWifiContext, addWifiCancel := context.WithTimeout(ctx, 5*time.Second)
|
|
|
|
defer addWifiCancel()
|
|
|
|
done, err := client.AddWifiNetwork(addWifiContext, ssid, SecurityOpen, "")
|
2018-09-19 13:00:08 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if g, e := done, true; g != e {
|
|
|
|
t.Errorf("AddWifiNetwork() -> done: got '%v', expected '%v'", g, e)
|
|
|
|
}
|
|
|
|
|
2018-09-26 12:05:55 +02:00
|
|
|
wifiContext, wifiCancel := context.WithTimeout(ctx, 5*time.Second)
|
|
|
|
defer wifiCancel()
|
|
|
|
networks, err := client.WifiNetworks(wifiContext)
|
2018-09-19 13:00:08 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2018-09-26 12:05:55 +02:00
|
|
|
removeWifiContext, removeWifiCancel := context.WithTimeout(ctx, 5*time.Second)
|
|
|
|
defer removeWifiCancel()
|
|
|
|
done, err = client.RemoveWifiNetwork(removeWifiContext, ssid)
|
2018-09-19 13:00:08 +02:00
|
|
|
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()
|
|
|
|
|
|
|
|
}
|
2018-09-20 10:59:39 +02:00
|
|
|
|
2018-09-20 12:08:20 +02:00
|
|
|
func TestClientWifiNetworkJoin(t *testing.T) {
|
2018-09-20 10:59:39 +02:00
|
|
|
|
|
|
|
if !*runUpdaterIntegrationTests {
|
|
|
|
t.Skip("To run this test, use: go test -updater-integration")
|
|
|
|
}
|
|
|
|
|
2018-09-21 12:31:52 +02:00
|
|
|
if !*runJoinNetworkTest {
|
|
|
|
t.Skip("To run this test, use: go test -updater-join-network-test")
|
|
|
|
}
|
|
|
|
|
|
|
|
client := NewClient(
|
|
|
|
emlid.WithStandardLogger(),
|
|
|
|
emlid.WithEndpoint(*reachHost, 80),
|
2018-09-20 10:59:39 +02:00
|
|
|
)
|
|
|
|
if err := client.Connect(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ssid := fmt.Sprintf("wifi_test_%d", rand.Uint32())
|
|
|
|
|
2018-09-26 12:05:55 +02:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
addWifiContext, addWifiCancel := context.WithTimeout(ctx, 5*time.Second)
|
|
|
|
defer addWifiCancel()
|
|
|
|
|
|
|
|
done, err := client.AddWifiNetwork(addWifiContext, ssid, SecurityOpen, "")
|
2018-09-20 10:59:39 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if g, e := done, true; g != e {
|
|
|
|
t.Errorf("AddWifiNetwork() -> done: got '%v', expected '%v'", g, e)
|
|
|
|
}
|
|
|
|
|
2018-09-26 12:05:55 +02:00
|
|
|
joinWifiContext, joinWifiCancel := context.WithTimeout(ctx, 5*time.Second)
|
|
|
|
defer joinWifiCancel()
|
|
|
|
if err := client.JoinWifiNetwork(joinWifiContext, ssid, true); err != nil {
|
2018-09-20 10:59:39 +02:00
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(5 * time.Second)
|
|
|
|
|
|
|
|
defer client.Close()
|
|
|
|
|
|
|
|
}
|