Skip to content

Commit

Permalink
feat: support to pass env in the grpc server (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxSuRen committed Apr 6, 2023
1 parent 82f2fdf commit 578e64b
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 229 deletions.
18 changes: 18 additions & 0 deletions pkg/server/remote_server.go
Expand Up @@ -5,6 +5,7 @@ import (
"bytes"
context "context"
"fmt"
"os"
"strings"

"github.com/linuxsuren/api-testing/pkg/render"
Expand All @@ -25,6 +26,22 @@ func NewRemoteServer() RunnerServer {
// Run start to run the test task
func (s *server) Run(ctx context.Context, task *TestTask) (reply *HelloReply, err error) {
var suite *testing.TestSuite
if task.Env == nil {
task.Env = map[string]string{}
}

// TODO may not safe in multiple threads
oldEnv := map[string]string{}
for key, val := range task.Env {
oldEnv[key] = os.Getenv(key)
os.Setenv(key, val)
}

defer func() {
for key, val := range oldEnv {
os.Setenv(key, val)
}
}()

switch task.Kind {
case "suite":
Expand Down Expand Up @@ -69,6 +86,7 @@ func (s *server) Run(ctx context.Context, task *TestTask) (reply *HelloReply, er
return
}

fmt.Println("prepare to run:", suite.Name)
dataContext := map[string]interface{}{}

var result string
Expand Down
3 changes: 3 additions & 0 deletions pkg/server/remote_server_test.go
Expand Up @@ -46,6 +46,9 @@ func TestRemoteServer(t *testing.T) {
Kind: "testcaseInSuite",
Data: simpleSuite,
CaseName: "fake",
Env: map[string]string{
"SERVER": "http://localhost:9090",
},
})
assert.NotNil(t, err)

Expand Down

0 comments on commit 578e64b

Please sign in to comment.