Skip to content

Commit

Permalink
linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
leehinman committed Sep 5, 2023
1 parent 707f496 commit 4c599cc
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions libbeat/tests/integration/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ func NewBeat(t *testing.T, beatName, binary string, args ...string) *BeatProc {

glob := fmt.Sprintf("%s-*.ndjson", filepath.Join(tempDir, beatName))
files, err := filepath.Glob(glob)
if err != nil {
t.Logf("glob error with: %s: %s", glob, err)
}
for _, f := range files {
contents, err := readLastNBytes(f, maxlen)
if err != nil {
Expand Down Expand Up @@ -210,10 +213,10 @@ func (b *BeatProc) Start(args ...string) {
func (b *BeatProc) startBeat() {
b.cmdMutex.Lock()
defer b.cmdMutex.Unlock()
b.stdout.Seek(0, 0)
b.stdout.Truncate(0)
b.stderr.Seek(0, 0)
b.stderr.Truncate(0)
_, _ = b.stdout.Seek(0, 0)
_ = b.stdout.Truncate(0)
_, _ = b.stderr.Seek(0, 0)
_ = b.stderr.Truncate(0)
var procAttr os.ProcAttr
procAttr.Files = []*os.File{os.Stdin, b.stdout, b.stderr}
process, err := os.StartProcess(b.fullPath, b.Args, &procAttr)
Expand Down Expand Up @@ -254,7 +257,7 @@ func (b *BeatProc) Stop() {
func (b *BeatProc) LogMatch(match string) bool {
re := regexp.MustCompile(match)
logFile := b.openLogFile()
_, err := logFile.Seek(b.logFileOffset, os.SEEK_SET)
_, err := logFile.Seek(b.logFileOffset, io.SeekStart)
if err != nil {
b.t.Fatalf("could not set offset for '%s': %s", logFile.Name(), err)
}
Expand Down Expand Up @@ -294,7 +297,7 @@ func (b *BeatProc) LogMatch(match string) bool {
func (b *BeatProc) LogContains(s string) bool {
t := b.t
logFile := b.openLogFile()
_, err := logFile.Seek(b.logFileOffset, os.SEEK_SET)
_, err := logFile.Seek(b.logFileOffset, io.SeekStart)
if err != nil {
t.Fatalf("could not set offset for '%s': %s", logFile.Name(), err)
}
Expand Down Expand Up @@ -453,6 +456,7 @@ func EnsureESIsRunning(t *testing.T) {
// containers required for integration tests
t.Fatalf("cannot execute HTTP request to ES: '%s', check to make sure ES is running (mage compose:Up)", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
t.Errorf("unexpected HTTP status: %d, expecting 200 - OK", resp.StatusCode)
}
Expand Down Expand Up @@ -573,7 +577,10 @@ func GetKibana(t *testing.T) (url.URL, *url.Userinfo) {
func HttpDo(t *testing.T, method string, targetURL url.URL) (statusCode int, body []byte, err error) {
t.Helper()
client := &http.Client{}
req, err := http.NewRequest(method, targetURL.String(), nil)

ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(30*time.Second))
defer cancel()
req, err := http.NewRequestWithContext(ctx, method, targetURL.String(), nil)
if err != nil {
return 0, nil, fmt.Errorf("error making request, method: %s, url: %s, error: %w", method, targetURL.String(), err)
}
Expand Down

0 comments on commit 4c599cc

Please sign in to comment.