diff --git a/tests/integration/plugins/data_plane/data_plane.go b/tests/integration/plugins/data_plane/data_plane.go index e17646870..dc3a7d6db 100644 --- a/tests/integration/plugins/data_plane/data_plane.go +++ b/tests/integration/plugins/data_plane/data_plane.go @@ -1,6 +1,7 @@ package data_plane import ( + "bufio" "context" "io" "net" @@ -13,6 +14,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" + "mosn.io/moe/pkg/log" ) @@ -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 { @@ -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() diff --git a/tests/integration/plugins/demo_test.go b/tests/integration/plugins/demo_test.go index 60cea74e1..c3aaec84d 100644 --- a/tests/integration/plugins/demo_test.go +++ b/tests/integration/plugins/demo_test.go @@ -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 diff --git a/tests/integration/plugins/filtermanager_test.go b/tests/integration/plugins/filtermanager_test.go index bb3efc760..ec950e357 100644 --- a/tests/integration/plugins/filtermanager_test.go +++ b/tests/integration/plugins/filtermanager_test.go @@ -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 @@ -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