bettercap/network/net_linux_test.go
eenblam 56d1655727 Add initial test for net_linux.go
More tests needed based on iwlist output, but the side-effect-free
part of GetSupportedFrequencies() has been been broken out into a function
that can now be tested without calling core.Exec().
2018-08-31 14:09:54 -07:00

40 lines
927 B
Go

package network
import (
"errors"
"reflect"
"testing"
)
func TestProcessSupportedFrequencies(t *testing.T) {
// Actually test processSupportedFrequencies; IO is lifted out.
cases := []struct {
Name string
InputString string
InputError error
ExpectedFreqs []int
ExpectedError bool
}{
{
"Returns empty with an error",
"Shouldn't matter",
errors.New("iwlist must have failed"),
[]int{},
true,
},
}
for _, test := range cases {
t.Run(test.Name, func(t *testing.T) {
freqs, err := processSupportedFrequencies(test.InputString, test.InputError)
if err != nil && !test.ExpectedError {
t.Errorf("unexpected error: %s", err)
}
if err == nil && test.ExpectedError {
t.Error("expected error, but got none")
}
if !test.ExpectedError && !reflect.DeepEqual(freqs, test.ExpectedFreqs) {
t.Errorf("got %v, want %v", freqs, test.ExpectedFreqs)
}
})
}
}