mirror of
https://github.com/bettercap/bettercap
synced 2025-07-11 07:37:00 -07:00
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().
This commit is contained in:
parent
3c3ed30001
commit
56d1655727
2 changed files with 48 additions and 4 deletions
40
network/net_linux_test.go
Normal file
40
network/net_linux_test.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue