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 10:11:45 +02:00
c := newConnectionType("wifi")
if c != connectionWifi {
2018-02-09 21:55:05 +01:00
t.Fatalf("Wrong connection type: %v", c)
}
2018-06-27 10:11:45 +02:00
c = newConnectionType("cellular")
if c != connectionCellular {
2018-02-09 21:55:05 +01:00
t.Fatalf("Wrong connection type: %v", c)
}
2018-06-27 10:11:45 +02:00
c = newConnectionType("bluetooth")
if c != connectionUnknown {
2018-02-09 21:55:05 +01:00
t.Fatalf("Wrong connection type: %v", c)
}
}
func TestConnectionState(t *testing.T) {
tests := []struct {
name string
2018-06-27 10:11:45 +02:00
state connectionState
expected string
}{
{
"zero value",
2018-06-27 10:11:45 +02:00
connectionState{},
"unknown",
},
{
"offline",
2018-06-27 10:11:45 +02:00
connectionState{Offline: true},
"offline",
},
{
"wifi",
2018-06-27 10:11:45 +02:00
connectionState{Type: connectionWifi},
"wifi",
},
{
"wifi tethered",
2018-06-27 10:11:45 +02:00
connectionState{Type: connectionWifi, Expensive: true},
"wifi (expensive)",
},
{
"unknown",
2018-06-27 10:11:45 +02:00
connectionState{Type: connectionUnknown},
"unknown",
},
2018-06-27 10:11:45 +02: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)
}
}
}