From 27807a1c8aee5f8ec7547f5aa25bb47558faf343 Mon Sep 17 00:00:00 2001 From: LeslieRan <1436703451@qq.com> Date: Mon, 11 Jan 2021 15:45:18 +0800 Subject: [PATCH] add unit test --- .traefik.yml | 4 ++-- README.md | 2 +- demo_test.go | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 demo_test.go diff --git a/.traefik.yml b/.traefik.yml index 81fe10b..0e0149f 100644 --- a/.traefik.yml +++ b/.traefik.yml @@ -1,6 +1,6 @@ displayName: leslieran-demo type: middleware import: github.com/LeslieRan/pluginDemo -summary: just try to develop a Traefic plugin. +summary: just try to develop a Traefik plugin. testData: - info: hello \ No newline at end of file + Info: hello diff --git a/README.md b/README.md index 2278d2a..75602cd 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ # pluginDemo -traefic-plugin +traefik-plugin diff --git a/demo_test.go b/demo_test.go new file mode 100644 index 0000000..17069ae --- /dev/null +++ b/demo_test.go @@ -0,0 +1,36 @@ +package pluginDemo_test + +import ( + "context" + "net/http" + "net/http/httptest" + "testing" + + "github.com/LeslieRan/pluginDemo" +) + +func TestDemo(t *testing.T) { + cfg := pluginDemo.CreateConfig() + cfg.Info = "Hello" + + ctx := context.Background() + next := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {}) + + handler, err := pluginDemo.New(ctx, next, cfg, "demo-plugin") + if err != nil { + t.Fatalf("new plugin:%s\n", err.Error()) + } + + recorder := httptest.NewRecorder() + req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://localhost", nil) + if err != nil { + t.Fatalf("new http request:%s\n", err.Error()) + } + // client := http.DefaultClient + // resp, err := client.Do(req) + // if err != nil { + // t.Fatalf("send http request:%s\n", err.Error()) + // } + // t.Logf("response: %d and %s\n", resp.StatusCode, resp.Status) + handler.ServeHTTP(recorder, req) +}