status-go/connection/state_test.go

65 lines
1.1 KiB
Go
Raw Permalink Normal View History

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