status-go/api/connection_test.go

65 lines
1.2 KiB
Go
Raw Normal View History

package api
import "testing"
func TestConnectionType(t *testing.T) {
2018-06-27 08:11:45 +00:00
c := newConnectionType("wifi")
if c != connectionWifi {
2018-02-09 20:55:05 +00:00
t.Fatalf("Wrong connection type: %v", c)
}
2018-06-27 08:11:45 +00:00
c = newConnectionType("cellular")
if c != connectionCellular {
2018-02-09 20:55:05 +00:00
t.Fatalf("Wrong connection type: %v", c)
}
2018-06-27 08:11:45 +00:00
c = newConnectionType("bluetooth")
if c != connectionUnknown {
2018-02-09 20:55:05 +00:00
t.Fatalf("Wrong connection type: %v", c)
}
}
func TestConnectionState(t *testing.T) {
tests := []struct {
name string
2018-06-27 08:11:45 +00:00
state connectionState
expected string
}{
{
"zero value",
2018-06-27 08:11:45 +00:00
connectionState{},
"unknown",
},
{
"offline",
2018-06-27 08:11:45 +00:00
connectionState{Offline: true},
"offline",
},
{
"wifi",
2018-06-27 08:11:45 +00:00
connectionState{Type: connectionWifi},
"wifi",
},
{
"wifi tethered",
2018-06-27 08:11:45 +00:00
connectionState{Type: connectionWifi, Expensive: true},
"wifi (expensive)",
},
{
"unknown",
2018-06-27 08:11:45 +00:00
connectionState{Type: connectionUnknown},
"unknown",
},
2018-06-27 08:11:45 +00:00
{
"cellular",
connectionState{Type: connectionCellular},
"cellular",
},
}
for _, test := range tests {
str := test.state.String()
if str != test.expected {
t.Fatalf("Expected String() to return '%s', got '%s'", test.expected, str)
}
}
}