Skip to content

Commit

Permalink
Merge pull request #8 from LeslieRan/rf-dev
Browse files Browse the repository at this point in the history
add unit test
  • Loading branch information
dumbFeng authored Jan 11, 2021
2 parents 59b2f05 + 27807a1 commit 5d40d5f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .traefik.yml
Original file line number Diff line number Diff line change
@@ -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
Info: hello
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# pluginDemo
traefic-plugin
traefik-plugin
36 changes: 36 additions & 0 deletions demo_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 5d40d5f

Please sign in to comment.