Skip to content

Commit

Permalink
bug-fixing: http probe report the unsupported document type (megaease…
Browse files Browse the repository at this point in the history
…#235)

* bug-fixing: http probe report the unsupported doc type if not configure the

* add the unit test case

* add more retry for windows unit test case failed
  • Loading branch information
haoel authored Oct 18, 2022
1 parent 1821c1e commit 6983ee5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion conf/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
// refer to https://github.com/golang/go/issues/51442
// using the workaround to remove the directory by a retry loop
func removeDir(dir string) {
for i := 0; i < 10; i++ {
for i := 0; i < 100; i++ {
if err := os.RemoveAll(dir); err == nil {
return
}
Expand Down
7 changes: 5 additions & 2 deletions probe/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,11 @@ func (h *HTTP) Config(gConf global.ProbeSettings) error {
return err
}

if err := h.Evaluator.Config(); err != nil {
return err
// if the evaluator is set, config it
if h.Evaluator.DocType != eval.Unsupported && len(strings.TrimSpace(h.Evaluator.Expression)) > 0 {
if err := h.Evaluator.Config(); err != nil {
return err
}
}

h.metrics = newMetrics(kind, tag)
Expand Down
24 changes: 23 additions & 1 deletion probe/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
package http

import (
"bytes"
"context"
"crypto/tls"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"os"
"reflect"
"testing"

Expand All @@ -33,6 +35,7 @@ import (
"github.com/megaease/easeprobe/global"
"github.com/megaease/easeprobe/probe"
"github.com/megaease/easeprobe/probe/base"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -68,9 +71,28 @@ func createHTTP() *HTTP {
},
}
}

func createSimpleHTTP() *HTTP {
return &HTTP{
DefaultProbe: base.DefaultProbe{ProbeName: "dummy http"},
URL: "http://localhost:8888",
ContentEncoding: "text/json",
Headers: map[string]string{"header1": "value1", "header2": "value2", "Host": "host.com"},
Body: "{ \"key1\": \"value1\", \"key2\": \"value2\" }",
}
}

func TestHTTPConfig(t *testing.T) {
h := createHTTP()
h := createSimpleHTTP()
var buf bytes.Buffer
log.SetOutput(&buf)
err := h.Config(global.ProbeSettings{})
assert.NoError(t, err)
assert.NotContains(t, buf.String(), "Unsupported document type")
log.SetOutput(os.Stdout)

h = createHTTP()
err = h.Config(global.ProbeSettings{})
assert.Error(t, err)

//TLS config success
Expand Down

0 comments on commit 6983ee5

Please sign in to comment.