status-go/connection/state_test.go

65 lines
1.1 KiB
Go
Raw Permalink Normal View History

2021-05-14 10:55:42 +00:00
package connection
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)
}
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)
}
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)
}
}
2021-05-14 10:55:42 +00:00
func TestState(t *testing.T) {
tests := []struct {
name string
2021-05-14 10:55:42 +00:00
state State
expected string
}{
{
"zero value",
2021-05-14 10:55:42 +00:00
State{},
"unknown",
},
{
"offline",
2021-05-14 10:55:42 +00:00
State{Offline: true},
"offline",
},
{
"wifi",
2021-05-14 10:55:42 +00:00
State{Type: connectionWifi},
"wifi",
},
{
"wifi tethered",
2021-05-14 10:55:42 +00:00
State{Type: connectionWifi, Expensive: true},
"wifi (expensive)",
},
{
"unknown",
2021-05-14 10:55:42 +00:00
State{Type: connectionUnknown},
"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",
},
}
for _, test := range tests {
str := test.state.String()
if str != test.expected {
t.Fatalf("Expected String() to return '%s', got '%s'", test.expected, str)
}
}
}