2018-09-19 13:00:08 +02:00
|
|
|
package reach
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestClientSavedWiFiNetworks(t *testing.T) {
|
|
|
|
|
2018-09-19 17:13:45 +02:00
|
|
|
if !*runUpdaterIntegrationTests {
|
2018-09-19 15:29:44 +02:00
|
|
|
t.Skip("To run this test, use: go test -integration")
|
|
|
|
}
|
|
|
|
|
2018-09-19 17:13:45 +02:00
|
|
|
client := NewUpdaterClient(
|
2018-09-19 13:00:08 +02:00
|
|
|
WithStandardLogger(),
|
2018-09-19 15:29:44 +02:00
|
|
|
WithEndpoint(*reachHost, 80),
|
2018-09-19 13:00:08 +02:00
|
|
|
)
|
|
|
|
if err := client.Connect(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := client.SavedWifiNetworks()
|
|
|
|
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 15:29:44 +02:00
|
|
|
t.Skip("To run this test, use: go test -integration")
|
|
|
|
}
|
|
|
|
|
2018-09-19 17:13:45 +02:00
|
|
|
client := NewUpdaterClient(
|
2018-09-19 13:00:08 +02:00
|
|
|
WithStandardLogger(),
|
2018-09-19 15:29:44 +02:00
|
|
|
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())
|
|
|
|
|
|
|
|
done, err := client.AddWifiNetwork(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)
|
|
|
|
}
|
|
|
|
|
|
|
|
networks, err := client.SavedWifiNetworks()
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
done, err = client.RemoveWifiNetwork(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()
|
|
|
|
|
|
|
|
}
|