mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 02:36:57 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
6dd86c44fa
commit
0d17ba3573
2 changed files with 3 additions and 62 deletions
|
@ -69,12 +69,12 @@ var iwlistFreqParser = regexp.MustCompile(`^\s+Channel.([0-9]+)\s+:\s+([0-9\.]+)
|
|||
func iwlistSupportedFrequencies(iface string) ([]int, error) {
|
||||
out, err := core.Exec("iwlist", []string{iface, "freq"})
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
freqs := make([]int, 0)
|
||||
if output != "" {
|
||||
scanner := bufio.NewScanner(strings.NewReader(output))
|
||||
if out != "" {
|
||||
scanner := bufio.NewScanner(strings.NewReader(out))
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
matches := iwlistFreqParser.FindStringSubmatch(line)
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
package network
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestProcessSupportedFrequencies(t *testing.T) {
|
||||
// Actually test parseIWListFreqs; IO is lifted out.
|
||||
cases := []struct {
|
||||
Name string
|
||||
InputString string
|
||||
InputError error
|
||||
ExpectedFreqs []int
|
||||
ExpectedError bool
|
||||
}{
|
||||
{
|
||||
"Returns appropriately formatted frequencies on valid input",
|
||||
`wlan1 11 channels in total; available frequencies :
|
||||
Channel 01 : 2.412 GHz
|
||||
Channel 02 : 2.417 GHz
|
||||
Channel 03 : 2.422 GHz
|
||||
Channel 04 : 2.427 GHz
|
||||
Channel 05 : 2.432 GHz
|
||||
Channel 06 : 2.437 GHz
|
||||
Channel 07 : 2.442 GHz
|
||||
Channel 08 : 2.447 GHz
|
||||
Channel 09 : 2.452 GHz
|
||||
Channel 10 : 2.457 GHz
|
||||
Channel 11 : 2.462 GHz
|
||||
Current Frequency:2.437 GHz (Channel 6)`,
|
||||
nil,
|
||||
[]int{2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"Returns empty with an error",
|
||||
"Doesn'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