未验证 提交 cb470ad4 编写于 作者: Y Young Bu Park 提交者: GitHub

Add unit-test tracing enabled (#1285)

上级 7168ba17
......@@ -15,6 +15,7 @@ import (
"testing"
"github.com/dapr/dapr/pkg/channel"
"github.com/dapr/dapr/pkg/config"
"github.com/stretchr/testify/assert"
"github.com/valyala/fasthttp"
)
......@@ -51,9 +52,13 @@ func (t *testContentTypeHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
}
type testHandler struct {
serverURL string
t *testing.T
}
func (t *testHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func (th *testHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
assert.Equal(th.t, th.serverURL, r.Host)
io.WriteString(w, r.URL.RawQuery)
}
......@@ -69,14 +74,42 @@ func (t *testHandlerHeaders) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
func TestInvokeMethod(t *testing.T) {
server := httptest.NewServer(&testHandler{})
c := Channel{baseAddress: server.URL, client: &fasthttp.Client{}}
request := &channel.InvokeRequest{
Metadata: map[string]string{QueryString: "param1=val1&param2=val2"},
}
response, err := c.InvokeMethod(request)
assert.NoError(t, err)
assert.Equal(t, "param1=val1&param2=val2", string(response.Data))
th := &testHandler{t: t, serverURL: ""}
server := httptest.NewServer(th)
t.Run("query string", func(t *testing.T) {
c := Channel{
baseAddress: server.URL,
client: &fasthttp.Client{},
tracingSpec: config.TracingSpec{
Enabled: false,
},
}
th.serverURL = server.URL[len("http://"):]
request := &channel.InvokeRequest{
Metadata: map[string]string{QueryString: "param1=val1&param2=val2"},
}
response, err := c.InvokeMethod(request)
assert.NoError(t, err)
assert.Equal(t, "param1=val1&param2=val2", string(response.Data))
})
t.Run("tracing is enabled", func(t *testing.T) {
c := Channel{
baseAddress: server.URL,
client: &fasthttp.Client{},
tracingSpec: config.TracingSpec{
Enabled: true,
},
}
th.serverURL = server.URL[len("http://"):]
request := &channel.InvokeRequest{
Method: "method",
}
response, err := c.InvokeMethod(request)
assert.NoError(t, err)
assert.Equal(t, "", string(response.Data))
})
server.Close()
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册