2021-05-14 10:55:42 +00:00
|
|
|
package connection
|
2018-02-09 20:28:16 +00:00
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestConnectionType(t *testing.T) {
|
2022-03-28 10:10:40 +00:00
|
|
|
c := NewType("wifi")
|
2018-06-27 08:11:45 +00:00
|
|
|
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
|
|
|
}
|
2022-03-28 10:10:40 +00:00
|
|
|
c = NewType("cellular")
|
2018-06-27 08:11:45 +00:00
|
|
|
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
|
|
|
}
|
2022-03-28 10:10:40 +00:00
|
|
|
c = NewType("bluetooth")
|
2018-06-27 08:11:45 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-14 10:55:42 +00:00
|
|
|
func TestState(t *testing.T) {
|
2018-02-09 20:28:16 +00:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
2021-05-14 10:55:42 +00:00
|
|
|
state State
|
2018-02-09 20:28:16 +00:00
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"zero value",
|
2021-05-14 10:55:42 +00:00
|
|
|
State{},
|
2018-02-16 02:48:19 +00:00
|
|
|
"unknown",
|
2018-02-09 20:28:16 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"offline",
|
2021-05-14 10:55:42 +00:00
|
|
|
State{Offline: true},
|
2018-02-09 20:28:16 +00:00
|
|
|
"offline",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"wifi",
|
2021-05-14 10:55:42 +00:00
|
|
|
State{Type: connectionWifi},
|
2018-02-09 20:28:16 +00:00
|
|
|
"wifi",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"wifi tethered",
|
2021-05-14 10:55:42 +00:00
|
|
|
State{Type: connectionWifi, Expensive: true},
|
2018-02-09 20:28:16 +00:00
|
|
|
"wifi (expensive)",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"unknown",
|
2021-05-14 10:55:42 +00:00
|
|
|
State{Type: connectionUnknown},
|
2018-02-09 20:28:16 +00:00
|
|
|
"unknown",
|
|
|
|
},
|
2018-06-27 08:11:45 +00:00
|
|
|
{
|
|
|
|
"cellular",
|
2021-05-14 10:55:42 +00:00
|
|
|
State{Type: connectionCellular},
|
2018-06-27 08:11:45 +00:00
|
|
|
"cellular",
|
|
|
|
},
|
2018-02-09 20:28:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
str := test.state.String()
|
|
|
|
if str != test.expected {
|
|
|
|
t.Fatalf("Expected String() to return '%s', got '%s'", test.expected, str)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|