-
Notifications
You must be signed in to change notification settings - Fork 553
/
plugin_test.go
66 lines (55 loc) · 1.37 KB
/
plugin_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//go:build integration || !race
// +build integration !race
// SPDX-License-Identifier: Apache-2.0
package plugin
import (
"bytes"
"context"
"fmt"
"io"
"net/http"
"testing"
"github.com/luraproject/lura/v2/config"
"github.com/luraproject/lura/v2/logging"
"github.com/luraproject/lura/v2/transport/http/client"
)
func TestLoadWithLogger(t *testing.T) {
buff := new(bytes.Buffer)
l, _ := logging.NewLogger("DEBUG", buff, "")
total, err := LoadWithLogger("./tests", ".so", RegisterClient, l)
if err != nil {
t.Error(err.Error())
t.Fail()
}
if total != 1 {
t.Errorf("unexpected number of loaded plugins!. have %d, want 1", total)
}
hre := HTTPRequestExecutor(l, func(_ *config.Backend) client.HTTPRequestExecutor {
t.Error("this factory should not been called")
t.Fail()
return nil
})
h := hre(&config.Backend{
ExtraConfig: map[string]interface{}{
Namespace: map[string]interface{}{
"name": "krakend-client-example",
},
},
})
req, _ := http.NewRequest("GET", "http://some.example.tld/path", http.NoBody)
resp, err := h(context.Background(), req)
if err != nil {
t.Errorf("unexpected error: %s", err.Error())
return
}
b, err := io.ReadAll(resp.Body)
if err != nil {
t.Error(err)
return
}
resp.Body.Close()
if string(b) != "Hello, \"/path\"" {
t.Errorf("unexpected response body: %s", string(b))
}
fmt.Println(buff.String())
}