]> 127.0.0.1 Git - front/.git/commitdiff
1 v0.1.20241031173442
authorqydysky <qydysky@foxmail.com>
Thu, 31 Oct 2024 17:33:10 +0000 (01:33 +0800)
committerqydysky <qydysky@foxmail.com>
Thu, 31 Oct 2024 17:33:10 +0000 (01:33 +0800)
.github/workflows/main.yml
config_test.go [new file with mode: 0644]
go.mod
go.sum

index 932686c0228178dd3d82073917feb56c9c3ca85e..e2af1da952bb0c03f1548dbd017047f04488bf86 100755 (executable)
@@ -41,6 +41,7 @@ jobs:
       run: |
         cd main
         go get .
+        go test -count 1 -timeout 30s -v .
         CGO_ENABLED=0 go build -pgo=auto -v -buildmode=exe main.go
       
     - name: zip
diff --git a/config_test.go b/config_test.go
new file mode 100644 (file)
index 0000000..7afa772
--- /dev/null
@@ -0,0 +1,136 @@
+package front
+
+import (
+       "context"
+       "net/http"
+       "testing"
+       "time"
+
+       "github.com/qydysky/front/filiter"
+       plog "github.com/qydysky/part/log"
+       reqf "github.com/qydysky/part/reqf"
+)
+
+var logger = plog.New(plog.Config{
+       Stdout: true,
+       Prefix_string: map[string]struct{}{
+               `T:`: plog.On,
+               `I:`: plog.On,
+               `W:`: plog.On,
+               `E:`: plog.On,
+       },
+})
+
+func Test_Uri(t *testing.T) {
+       ctx, cancel := context.WithCancel(context.Background())
+       defer cancel()
+
+       conf := &Config{
+               Addr: "127.0.0.1:19000",
+               Routes: []Route{
+                       {
+                               Path:    []string{"/"},
+                               PathAdd: true,
+                               Setting: Setting{
+                                       Filiter: filiter.Filiter{
+                                               ReqUri: filiter.Uri{
+                                                       AccessRule: "!{go}",
+                                                       Items: map[string]string{
+                                                               "go": "\\.go$",
+                                                       },
+                                               },
+                                       },
+                               },
+                               Backs: []Back{
+                                       {
+                                               Name:   "1",
+                                               To:     "./",
+                                               Weight: 1,
+                                       },
+                               },
+                       },
+               },
+       }
+
+       go conf.Run(ctx, logger)
+
+       time.Sleep(time.Second)
+
+       r := reqf.New()
+       if e := r.Reqf(reqf.Rval{
+               Url: "http://127.0.0.1:19000/config_test.go",
+       }); e != nil {
+               if r.Response.StatusCode != http.StatusForbidden {
+                       t.Fail()
+               }
+       } else {
+               t.Fail()
+       }
+
+       conf.Routes[0].Setting.Filiter.ReqUri.AccessRule = "{go}"
+
+       if e := r.Reqf(reqf.Rval{
+               Url: "http://127.0.0.1:19000/config_test.go",
+       }); e != nil {
+               t.Fail()
+       }
+}
+
+func Test_Back(t *testing.T) {
+       ctx, cancel := context.WithCancel(context.Background())
+       defer cancel()
+
+       conf := &Config{
+               Addr: "127.0.0.1:19000",
+               Routes: []Route{
+                       {
+                               Path:    []string{"/"},
+                               PathAdd: true,
+                               Backs:   []Back{},
+                       },
+               },
+       }
+
+       go conf.Run(ctx, logger)
+
+       time.Sleep(time.Second)
+
+       r := reqf.New()
+       if e := r.Reqf(reqf.Rval{
+               Url: "http://127.0.0.1:19000/config_test.go",
+       }); e != nil {
+               if r.Response.StatusCode != http.StatusNotFound {
+                       t.Fail()
+               }
+       } else {
+               t.Fail()
+       }
+
+       conf.Routes[0].Backs = append(conf.Routes[0].Backs,
+               Back{
+                       Name:   "1",
+                       To:     "./",
+                       Weight: 1,
+               },
+       )
+       conf.SwapSign(ctx, logger)
+
+       if e := r.Reqf(reqf.Rval{
+               Url: "http://127.0.0.1:19000/config_test.go",
+       }); e != nil {
+               t.Fail()
+       }
+
+       conf.Routes[0].Backs = conf.Routes[0].Backs[:0]
+       conf.SwapSign(ctx, logger)
+
+       if e := r.Reqf(reqf.Rval{
+               Url: "http://127.0.0.1:19000/config_test.go",
+       }); e != nil {
+               if r.Response.StatusCode != http.StatusNotFound {
+                       t.Fail()
+               }
+       } else {
+               t.Fail()
+       }
+}
diff --git a/go.mod b/go.mod
index b8806584fd748121e07982c7f4078325c375e2da..87160d2f5905a2c6a56ac7c3e7002b36133ad83a 100755 (executable)
--- a/go.mod
+++ b/go.mod
@@ -16,6 +16,7 @@ require (
        github.com/go-ole/go-ole v1.3.0 // indirect
        github.com/google/uuid v1.6.0 // indirect
        github.com/pmezard/go-difflib v1.0.0 // indirect
+       github.com/qydysky/brotli v0.0.0-20240828134800-e9913a6e7ed9 // indirect
        github.com/shirou/gopsutil v3.21.11+incompatible // indirect
        github.com/tklauser/go-sysconf v0.3.14 // indirect
        github.com/tklauser/numcpus v0.8.0 // indirect
diff --git a/go.sum b/go.sum
index b15cda2b7bf084726c81928a36036c6ea79cac18..889b80a6aceafcfba577e498725381db79b316a2 100755 (executable)
--- a/go.sum
+++ b/go.sum
@@ -39,6 +39,8 @@ github.com/tklauser/go-sysconf v0.3.14 h1:g5vzr9iPFFz24v2KZXs/pvpvh8/V9Fw6vQK5ZZ
 github.com/tklauser/go-sysconf v0.3.14/go.mod h1:1ym4lWMLUOhuBOPGtRcJm7tEGX4SCYNEEEtghGG/8uY=
 github.com/tklauser/numcpus v0.8.0 h1:Mx4Wwe/FjZLeQsK/6kt2EOepwwSl7SmJrK5bV/dXYgY=
 github.com/tklauser/numcpus v0.8.0/go.mod h1:ZJZlAY+dmR4eut8epnzf0u/VwodKmryxR8txiloSqBE=
+github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
+github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
 github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
 github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
 golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=