This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-go-plugin-runner.git

commit 669598cd58bd7e6769a40b7c97dfe4d3d68f676b
Author: spacewander <[email protected]>
AuthorDate: Thu May 20 18:07:13 2021 +0800

    chore: tweak for test
---
 internal/http/http.go          | 30 ++++++++++++++++++++++++++++++
 internal/server/server.go      |  8 ++++++--
 internal/server/server_test.go |  8 ++++----
 3 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/internal/http/http.go b/internal/http/http.go
new file mode 100644
index 0000000..d946102
--- /dev/null
+++ b/internal/http/http.go
@@ -0,0 +1,30 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package http
+
+import (
+       flatbuffers "github.com/google/flatbuffers/go"
+
+       "github.com/apache/apisix-go-plugin-runner/internal/util"
+       hrc "github.com/api7/ext-plugin-proto/go/A6/HTTPReqCall"
+)
+
+func HTTPReqCall(buf []byte) (*flatbuffers.Builder, error) {
+       builder := util.GetBuilder()
+       hrc.RespStart(builder)
+       resp := hrc.RespEnd(builder)
+       builder.Finish(resp)
+       return builder, nil
+}
diff --git a/internal/server/server.go b/internal/server/server.go
index 52c5624..88f2a17 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -23,9 +23,11 @@ import (
        "os"
        "os/signal"
        "strconv"
+       "strings"
        "syscall"
        "time"
 
+       "github.com/apache/apisix-go-plugin-runner/internal/http"
        "github.com/apache/apisix-go-plugin-runner/internal/log"
        "github.com/apache/apisix-go-plugin-runner/internal/plugin"
        "github.com/apache/apisix-go-plugin-runner/internal/util"
@@ -98,6 +100,8 @@ func handleConn(c net.Conn) {
                switch ty {
                case RPCPrepareConf:
                        bd, err = plugin.PrepareConf(buf)
+               case RPCHTTPReqCall:
+                       bd, err = http.HTTPReqCall(buf)
                default:
                        err = fmt.Errorf("unknown type %d", ty)
                }
@@ -148,11 +152,11 @@ func getConfCacheTTL() time.Duration {
 
 func getSockAddr() string {
        path := os.Getenv(SockAddrEnv)
-       if path == "" {
+       if !strings.HasPrefix(path, "unix:") {
                log.Errorf("invalid socket address: %s", path)
                return ""
        }
-       return path
+       return path[len("unix:"):]
 }
 
 func Run() {
diff --git a/internal/server/server_test.go b/internal/server/server_test.go
index bd483eb..4a5b3dd 100644
--- a/internal/server/server_test.go
+++ b/internal/server/server_test.go
@@ -29,12 +29,12 @@ func TestGetSockAddr(t *testing.T) {
        os.Unsetenv(SockAddrEnv)
        assert.Equal(t, "", getSockAddr())
 
-       os.Setenv(SockAddrEnv, "/tmp/x.sock")
+       os.Setenv(SockAddrEnv, "unix:/tmp/x.sock")
        assert.Equal(t, "/tmp/x.sock", getSockAddr())
 }
 
 func TestRun(t *testing.T) {
-       addr := "/tmp/x.sock"
+       addr := "unix:/tmp/x.sock"
        os.Setenv(SockAddrEnv, addr)
        os.Setenv(ConfCacheTTLEnv, "60")
 
@@ -60,9 +60,9 @@ func TestRun(t *testing.T) {
        }
 
        for _, c := range cases {
-               conn, err := net.DialTimeout("unix", addr, 1*time.Second)
-               defer conn.Close()
+               conn, err := net.DialTimeout("unix", addr[len("unix:"):], 
1*time.Second)
                assert.NotNil(t, conn, err)
+               defer conn.Close()
                conn.Write(c.header)
        }
 }

Reply via email to