d6375ba921
* verify response body with expected keywords * remove debug log * add extra test case * migrate from ioutil to io * close body and only check for one keyword * cleanup
39 lines
713 B
Go
39 lines
713 B
Go
package common
|
|
|
|
import (
|
|
"bufio"
|
|
"io"
|
|
"strings"
|
|
)
|
|
|
|
func AddStringSliceItem(item string, slice *[]string) {
|
|
for _, i := range *slice {
|
|
if i == item {
|
|
return
|
|
}
|
|
}
|
|
*slice = append(*slice, item)
|
|
}
|
|
|
|
func RemoveStringSliceItem(item string, slice *[]string) {
|
|
for i, listItem := range *slice {
|
|
if item == listItem {
|
|
(*slice)[i] = (*slice)[len(*slice)-1]
|
|
*slice = (*slice)[:len(*slice)-1]
|
|
}
|
|
}
|
|
}
|
|
|
|
func ResponseContainsSubstring(reader io.ReadCloser, target string) (bool, error) {
|
|
scanner := bufio.NewScanner(reader)
|
|
for scanner.Scan() {
|
|
if strings.Contains(scanner.Text(), target) {
|
|
return true, nil
|
|
}
|
|
}
|
|
if err := scanner.Err(); err != nil {
|
|
return false, err
|
|
}
|
|
return false, nil
|
|
}
|