2018-02-09 20:28:16 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestConnectionType(t *testing.T) {
|
|
|
|
c := NewConnectionType("wifi")
|
|
|
|
if c != ConnectionWifi {
|
2018-02-09 20:55:05 +00:00
|
|
|
t.Fatalf("Wrong connection type: %v", c)
|
2018-02-09 20:28:16 +00:00
|
|
|
}
|
|
|
|
c = NewConnectionType("cellular")
|
|
|
|
if c != ConnectionCellular {
|
2018-02-09 20:55:05 +00:00
|
|
|
t.Fatalf("Wrong connection type: %v", c)
|
2018-02-09 20:28:16 +00:00
|
|
|
}
|
|
|
|
c = NewConnectionType("bluetooth")
|
|
|
|
if c != ConnectionUnknown {
|
2018-02-09 20:55:05 +00:00
|
|
|
t.Fatalf("Wrong connection type: %v", c)
|
2018-02-09 20:28:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConnectionState(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
state ConnectionState
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"zero value",
|
|
|
|
ConnectionState{},
|
2018-02-16 02:48:19 +00:00
|
|
|
"unknown",
|
2018-02-09 20:28:16 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"offline",
|
|
|
|
ConnectionState{Offline: true},
|
|
|
|
"offline",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"wifi",
|
|
|
|
ConnectionState{Type: ConnectionWifi},
|
|
|
|
"wifi",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"wifi tethered",
|
|
|
|
ConnectionState{Type: ConnectionWifi, Expensive: true},
|
|
|
|
"wifi (expensive)",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"unknown",
|
|
|
|
ConnectionState{Type: ConnectionUnknown},
|
|
|
|
"unknown",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
str := test.state.String()
|
|
|
|
if str != test.expected {
|
|
|
|
t.Fatalf("Expected String() to return '%s', got '%s'", test.expected, str)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|