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:
eenblam 2018-08-31 13:51:49 -07:00
commit 56d1655727
2 changed files with 48 additions and 4 deletions

View file

@ -59,13 +59,12 @@ func SetInterfaceChannel(iface string, channel int) error {
return nil
}
func GetSupportedFrequencies(iface string) ([]int, error) {
func processSupportedFrequencies(output string, err error) ([]int, error) {
freqs := make([]int, 0)
out, err := core.Exec("iwlist", []string{iface, "freq"})
if err != nil {
return freqs, err
} else if out != "" {
scanner := bufio.NewScanner(strings.NewReader(out))
} else if output != "" {
scanner := bufio.NewScanner(strings.NewReader(output))
for scanner.Scan() {
line := scanner.Text()
matches := WiFiFreqParser.FindStringSubmatch(line)
@ -78,3 +77,8 @@ func GetSupportedFrequencies(iface string) ([]int, error) {
}
return freqs, nil
}
func GetSupportedFrequencies(iface string) ([]int, error) {
out, err := core.Exec("iwlist", []string{iface, "freq"})
return processSupportedFrequencies(out, err)
}