Skip to content

Commit

Permalink
test: add error log check and fix default option not apply
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <[email protected]>
  • Loading branch information
spacewander committed Nov 8, 2023
1 parent d5d0da4 commit 6d3e385
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
25 changes: 22 additions & 3 deletions tests/integration/plugins/data_plane/data_plane.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package data_plane

import (
"bufio"
"context"
"io"
"net"
Expand All @@ -13,6 +14,8 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"

"mosn.io/moe/pkg/log"
)

Expand All @@ -26,21 +29,25 @@ var (
type DataPlane struct {
cmd *exec.Cmd
t *testing.T
opt *Option
}

type Option struct {
LogLevel string
LogLevel string
CheckErrorLog bool
}

func StartDataPlane(t *testing.T, opt *Option) (*DataPlane, error) {
if opt == nil {
opt = &Option{
LogLevel: "debug",
LogLevel: "debug",
CheckErrorLog: true,
}
}

dp := &DataPlane{
t: t,
t: t,
opt: opt,
}
err := dp.cleanup(t)
if err != nil {
Expand Down Expand Up @@ -153,6 +160,18 @@ func (dp *DataPlane) Stop() {
logger.Info("envoy stopped")

f := dp.cmd.Stdout.(*os.File)
if dp.opt.CheckErrorLog {
f.Seek(0, 0)
sc := bufio.NewScanner(f)
for sc.Scan() {
s := sc.Text()
if strings.Contains(s, "[error]") || strings.Contains(s, "[critical]") {
assert.Falsef(dp.t, true, "error/critical level log found: %s", s)
break
}
}
}

f.Close()
f = dp.cmd.Stderr.(*os.File)
f.Close()
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/plugins/demo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestDemo(t *testing.T) {
dp, err := data_plane.StartDataPlane(t, &data_plane.Option{})
dp, err := data_plane.StartDataPlane(t, nil)
if err != nil {
t.Fatalf("failed to start data plane: %v", err)
return
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/plugins/filtermanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func assertBody(t *testing.T, exp string, resp *http.Response) {
}

func TestFilterManagerDecode(t *testing.T) {
dp, err := data_plane.StartDataPlane(t, &data_plane.Option{})
dp, err := data_plane.StartDataPlane(t, nil)
if err != nil {
t.Fatalf("failed to start data plane: %v", err)
return
Expand Down Expand Up @@ -246,7 +246,7 @@ func assertBodyHas(t *testing.T, exp string, resp *http.Response) {
}

func TestFilterManagerEncode(t *testing.T) {
dp, err := data_plane.StartDataPlane(t, &data_plane.Option{})
dp, err := data_plane.StartDataPlane(t, nil)
if err != nil {
t.Fatalf("failed to start data plane: %v", err)
return
Expand Down

0 comments on commit 6d3e385

Please sign in to comment.