status-go/geth/api/connection_test.go

60 lines
1.1 KiB
Go
Raw Normal View History

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)
}
c = NewConnectionType("cellular")
if c != ConnectionCellular {
2018-02-09 20:55:05 +00:00
t.Fatalf("Wrong connection type: %v", c)
}
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
state ConnectionState
expected string
}{
{
"zero value",
ConnectionState{},
"unknown",
},
{
"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)
}
}
}