Skip to content

Commit

Permalink
finish converting test_template
Browse files Browse the repository at this point in the history
  • Loading branch information
leehinman committed Jul 22, 2023
1 parent 1a98412 commit ae196da
Show file tree
Hide file tree
Showing 5 changed files with 347 additions and 235 deletions.
2 changes: 1 addition & 1 deletion libbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func IntegTest() {

// GoIntegTest starts the docker containers and executes the Go integration tests.
func GoIntegTest(ctx context.Context) error {
mg.Deps(Fields)
mg.Deps(Fields, devtools.BuildSystemTestBinary)
args := devtools.DefaultGoTestIntegrationFromHostArgs()
// ES_USER must be admin in order for the Go Integration tests to function because they require
// indices:data/read/search
Expand Down
1 change: 0 additions & 1 deletion libbeat/tests/integration/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ output.console:
mockbeat.WriteConfigFile(cfg)
mockbeat.Start()
mockbeat.WaitStdErrContains("mockbeat start running.", 10*time.Second)
// mockbeat.WaitForLogs("Home path", 60*time.Second, "error waiting for mockbeat to start")

metaFile1, err := mockbeat.LoadMeta()
require.NoError(t, err, "error opening meta.json file")
Expand Down
17 changes: 6 additions & 11 deletions libbeat/tests/integration/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (b *BeatProc) Stop() {
// LogContains looks for `s` as a substring of every log line,
// it will open the log file on every call, read it until EOF,
// then close it.
func (b *BeatProc) LogContains(s string) string {
func (b *BeatProc) LogContains(s string) bool {
t := b.t
logFile := b.openLogFile()
_, err := logFile.Seek(b.logFileOffset, os.SEEK_SET)
Expand Down Expand Up @@ -244,25 +244,20 @@ func (b *BeatProc) LogContains(s string) string {
}

if strings.Contains(line, s) {
return line
return true
}
}

return ""
return false
}

// WaitForLogs waits for the specified string s to be present in the logs within
// the given timeout duration and fails the test if s is not found.
func (b *BeatProc) WaitForLogs(s string, timeout time.Duration) string {
func (b *BeatProc) WaitForLogs(s string, timeout time.Duration, msgAndArgs ...any) {
b.t.Helper()
errMsg := fmt.Sprintf("Error waiting for log %s", s)
var returnValue string
require.Eventually(b.t, func() bool {
returnValue = b.LogContains(s)
return returnValue != ""
}, timeout, 100*time.Millisecond, errMsg)

return returnValue
return b.LogContains(s)
}, timeout, 100*time.Millisecond, msgAndArgs...)
}

// TempDir returns the temporary directory
Expand Down
Loading

0 comments on commit ae196da

Please sign in to comment.