Skip to content

Commit

Permalink
fix: fix
Browse files Browse the repository at this point in the history
Signed-off-by: yuluo-yx <[email protected]>
  • Loading branch information
yuluo-yx committed Apr 22, 2024
1 parent 8ff225b commit 1837b57
Show file tree
Hide file tree
Showing 18 changed files with 50 additions and 44 deletions.
4 changes: 2 additions & 2 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (o *runOption) startMonitor() (err error) {
execer := fakeruntime.NewDefaultExecerWithContext(o.context)
go func(socketURL, plugin string) {
if err = execer.RunCommandWithIO(plugin, "", os.Stdout, os.Stderr, nil, "server", "--socket", socketURL); err != nil {
runLogger.Info("failed to start ", socketURL, " error: ", err.Error())
runLogger.Info("failed to start", "socketURL", socketURL, " error", err.Error())
}
}(sockFile, monitorBin)

Expand Down Expand Up @@ -284,7 +284,7 @@ func (o *runOption) runSuiteWithDuration(loader testing.Loader) (err error) {
defer sem.Release(1)
defer wait.Done()
defer func() {
runLogger.Info("routing end with ", time.Since(now))
runLogger.Info("routing end with", "time", time.Since(now))
}()

dataContext := getDefaultContext()
Expand Down
6 changes: 3 additions & 3 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (o *serverOption) runE(cmd *cobra.Command, args []string) (err error) {
reflection.Register(gRPCServer)
}
server.RegisterRunnerServer(s, remoteServer)
serverLogger.Info("gRPC server listening at ", lis.Addr())
serverLogger.Info("gRPC server listening at", "addr", lis.Addr())
s.Serve(lis)
}()

Expand Down Expand Up @@ -285,7 +285,7 @@ func (o *serverOption) runE(cmd *cobra.Command, args []string) (err error) {

debugHandler(mux, remoteServer)
o.httpServer.WithHandler(mux)
serverLogger.Info("HTTP server listening at ", httplis.Addr())
serverLogger.Info("HTTP server listening at", "addr", httplis.Addr())
serverLogger.Info("Server is running.")
err = o.httpServer.Serve(httplis)
err = util.IgnoreErrServerClosed(err)
Expand Down Expand Up @@ -359,7 +359,7 @@ func debugHandler(mux *runtime.ServeMux, remoteServer server.RunnerServer) {
sub := pathParams["sub"]
extName := r.URL.Query().Get("name")
if extName != "" && remoteServer != nil {
serverLogger.Info("get pprof of extension:", extName)
serverLogger.Info("get pprof of extension", "name", extName)

ctx := metadata.NewIncomingContext(r.Context(), metadata.New(map[string]string{
server.HeaderKeyStoreName: extName,
Expand Down
2 changes: 1 addition & 1 deletion pkg/generator/converter_jmeter.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (c *jmeterConverter) buildJmeterTestPlan(testSuite *testing.TestSuite) (res
for _, item := range testSuite.Items {
item.Request.RenderAPI(testSuite.API)
if reqRenderErr := item.Request.Render(emptyCtx, ""); reqRenderErr != nil {
genLogger.Info("Error rendering request: ", reqRenderErr)
genLogger.Info("Error rendering request", "error", reqRenderErr)
}

api, err := url.Parse(item.Request.API)
Expand Down
9 changes: 5 additions & 4 deletions pkg/mock/in_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ package mock
import (
"encoding/json"
"fmt"
"github.com/linuxsuren/api-testing/pkg/version"
"io"
"net"
"net/http"
"strings"

"github.com/linuxsuren/api-testing/pkg/version"

"github.com/linuxsuren/api-testing/pkg/logging"
"github.com/linuxsuren/api-testing/pkg/render"
"github.com/linuxsuren/api-testing/pkg/util"
Expand Down Expand Up @@ -129,7 +130,7 @@ func (s *inMemoryServer) startObject(obj Object) {

_, _ = w.Write(data)
} else {
memLogger.Info("failed to read from body", err)
memLogger.Info("failed to read from body", "error", err)
}
case http.MethodDelete:
// delete an item
Expand All @@ -155,7 +156,7 @@ func (s *inMemoryServer) startObject(obj Object) {

_, _ = w.Write(data)
} else {
memLogger.Info("failed to read from body", err)
memLogger.Info("failed to read from body", "error", err)
}
case http.MethodPut:
if data, err := io.ReadAll(req.Body); err == nil {
Expand All @@ -176,7 +177,7 @@ func (s *inMemoryServer) startObject(obj Object) {

_, _ = w.Write(data)
} else {
memLogger.Info("failed to read from body", err)
memLogger.Info("failed to read from body", "error", err)
}
default:
w.WriteHeader(http.StatusBadRequest)
Expand Down
11 changes: 6 additions & 5 deletions pkg/oauth/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"net/http"

"context"

"github.com/linuxsuren/api-testing/pkg/logging"
"github.com/linuxsuren/api-testing/pkg/util"

Expand Down Expand Up @@ -71,7 +72,7 @@ func (a *auth) Callback(w http.ResponseWriter, r *http.Request, pathParams map[s
http.Error(w, "Code not found", http.StatusBadRequest)
return
}
oauthLogger.Info("get code", code)
oauthLogger.Info("get code", "code" code)

Check failure on line 75 in pkg/oauth/server.go

View workflow job for this annotation

GitHub Actions / Test

syntax error: unexpected code in argument list; possibly missing comma or )

Check failure on line 75 in pkg/oauth/server.go

View workflow job for this annotation

GitHub Actions / APITest

syntax error: unexpected code in argument list; possibly missing comma or )

Check failure on line 75 in pkg/oauth/server.go

View workflow job for this annotation

GitHub Actions / Build

syntax error: unexpected code in argument list; possibly missing comma or )

Check failure on line 75 in pkg/oauth/server.go

View workflow job for this annotation

GitHub Actions / BuildEmbedUI

syntax error: unexpected code in argument list; possibly missing comma or )

sslcli := util.TlsAwareHTTPClient(a.skipTlsVerify)
ctx := context.WithValue(r.Context(), oauth2.HTTPClient, sslcli)
Expand All @@ -90,9 +91,9 @@ func (a *auth) getUserInfo(w http.ResponseWriter, r *http.Request, token *oauth2
// get userInfo, save it to session
if userInfo, err := GetUserInfo(a.provider, token.AccessToken, a.skipTlsVerify); err == nil {
accessToken[token.AccessToken] = userInfo
oauthLogger.Info(userInfo.Name, "has login")
oauthLogger.Info("has login", "username", userInfo.Name)
} else {
oauthLogger.Info("failed to get userinfo", err)
oauthLogger.Info("failed to get userinfo", "error", err)
}

http.Redirect(w, r, "/?access_token="+token.AccessToken, http.StatusFound)
Expand All @@ -115,7 +116,7 @@ var deviceAuthResponseMap = map[string]*oauth2.DeviceAuthResponse{}
func (a *auth) RequestLocalCode(w http.ResponseWriter, r *http.Request, pathParams map[string]string) {
response, err := a.config.DeviceAuth(context.Background())
if err != nil {
oauthLogger.Info("failed to get device auth", err)
oauthLogger.Info("failed to get device auth", "error", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
Expand All @@ -127,7 +128,7 @@ func (a *auth) RequestLocalCode(w http.ResponseWriter, r *http.Request, pathPara

func (a *auth) RequestCode(w http.ResponseWriter, r *http.Request, pathParams map[string]string) {
ref := r.Header.Get("Referer")
oauthLogger.Info("callback host", r.Host)
oauthLogger.Info("callback host", "host", r.Host)

if ref == "" {
a.config.RedirectURL = fmt.Sprintf("https://%s/oauth2/callback", r.Host)
Expand Down
5 changes: 3 additions & 2 deletions pkg/oauth/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ package oauth
import (
"encoding/json"
"fmt"
"github.com/linuxsuren/api-testing/pkg/logging"
"io"
"net/http"
"strings"

"github.com/linuxsuren/api-testing/pkg/logging"

"github.com/linuxsuren/api-testing/pkg/util"
)

Expand Down Expand Up @@ -84,7 +85,7 @@ func GetUserInfo(server OAuthProvider, token string, skipTlsVerify bool) (userIn
}
defer resp.Body.Close()

userLogger.Info("getting userinfo from", server.GetName())
userLogger.Info("getting userinfo from", "name", server.GetName())
if resp.StatusCode == http.StatusOK {
var data []byte
if data, err = io.ReadAll(resp.Body); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/runner/expr_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,20 @@ func ExprFuncHTTPReady(params ...interface{}) (res interface{}, err error) {
unstruct := make(map[string]interface{})

if err = json.Unmarshal(data, &unstruct); err != nil {
runnerLogger.Info("failed to unmarshal the response data ", err)
runnerLogger.Info("failed to unmarshal the response data ", "error", err)
return
}

unstruct["data"] = unstruct
var program *vm.Program
if program, err = expr.Compile(exprText, expr.Env(unstruct)); err != nil {
runnerLogger.Info("failed to compile ", exprText, "error: ", err)
runnerLogger.Info("failed to compile ", "text", exprText, "error: ", err)
return
}

var result interface{}
if result, err = expr.Run(program, unstruct); err != nil {
runnerLogger.Info("failed to Run ", exprText, "error: ", err)
runnerLogger.Info("failed to Run", "text", exprText, "error: ", err)
return
}

Expand All @@ -120,7 +120,7 @@ func ExprFuncHTTPReady(params ...interface{}) (res interface{}, err error) {
return
}

runnerLogger.Info("waiting for", api)
runnerLogger.Info("waiting for", "api", api)
time.Sleep(1 * time.Second)
}
err = fmt.Errorf("failed to wait for the API ready in %d times", retry)
Expand Down
2 changes: 1 addition & 1 deletion pkg/runner/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func compileProto(ctx context.Context, r *gRPCTestCaseRunner) (fileLinker linker
return
}

grpcRunnerLogger.Info("proto import files", importPath)
grpcRunnerLogger.Info("proto import files", "files", importPath)
compiler := protocompile.Compiler{
Resolver: protocompile.WithStandardImports(
&protocompile.SourceResolver{
Expand Down
2 changes: 1 addition & 1 deletion pkg/runner/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func runServer(t *testing.T, s *grpc.Server) net.Listener {
l, err := net.Listen("tcp", "127.0.0.1:0")
assert.NoError(t, err, "Listen port")

runnerLogger.Info("listening at", l.Addr().(*net.TCPAddr).Port)
runnerLogger.Info("listening at", "port", l.Addr().(*net.TCPAddr).Port)
go s.Serve(l)
return l
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/runner/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func verifyResponseBodyData(caseName string, expect testing.Response, responseTy

verifier := NewBodyVerify(responseType, expect)
if verifier == nil {
runnerLogger.Info("no body verify support with ", responseType)
runnerLogger.Info("no body verify support with", "response type", responseType)
return
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/runner/reporter_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (r *memoryTestReporter) PutRecord(record *ReportRecord) {
Name: r.monitorTarget,
})
if err != nil {
runnerLogger.Info("failed to get resource usage:", err)
runnerLogger.Info("failed to get resource usage", "error", err)
} else {
r.resourceUsages = append(r.resourceUsages, ResourceUsage{
Memory: usage.Memory,
Expand Down
5 changes: 3 additions & 2 deletions pkg/runner/writer_github_pr_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/linuxsuren/api-testing/pkg/logging"
"io"
"net/http"
"os"
"strings"

"github.com/linuxsuren/api-testing/pkg/logging"

"github.com/linuxsuren/api-testing/pkg/apispec"
"github.com/linuxsuren/api-testing/pkg/util"
)
Expand Down Expand Up @@ -153,7 +154,7 @@ func (w *githubPRCommentWriter) createOrUpdate(content string, id int) (err erro
Body: content,
}

githubLogger.Info("comment id", id)
githubLogger.Info("comment id", "id", id)
var data []byte
if data, err = json.Marshal(co); err != nil {
err = fmt.Errorf("failed to marshal body when createOrupdate comment: %v", err)
Expand Down
6 changes: 3 additions & 3 deletions pkg/server/fake_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewFakeClient(ctx context.Context, version string, err error) (RunnerClient
RegisterRunnerServer(baseServer, NewServer(version, err))
go func() {
if err := baseServer.Serve(lis); err != nil {
fakeLogger.Info("error serving server: ", err)
fakeLogger.Info("error serving server", "error", err)
}
}()

Expand All @@ -71,13 +71,13 @@ func NewFakeClient(ctx context.Context, version string, err error) (RunnerClient
return lis.Dial()
}), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
fakeLogger.Info("error connecting to server: ", err)
fakeLogger.Info("error connecting to server", "error", err)
}

closer := func() {
err := lis.Close()
if err != nil {
fakeLogger.Info("error closing listener: ", err)
fakeLogger.Info("error closing listener", "error", err)
}
baseServer.Stop()
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/server/remote_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (s *server) getSuiteFromTestTask(task *TestTask) (suite *testing.TestSuite,

if targetTestcase != nil {
parentCases := findParentTestCases(targetTestcase, suite)
remoteServerLogger.Info("find %d parent cases\n", len(parentCases))
remoteServerLogger.Info("find parent cases", "num", len(parentCases))
suite.Items = append(parentCases, *targetTestcase)
} else {
err = fmt.Errorf("cannot found testcase %s", task.CaseName)
Expand Down Expand Up @@ -182,7 +182,7 @@ func (s *server) getLoader(ctx context.Context) (loader testing.Writer) {

var err error
if loader, err = s.getLoaderByStoreName(storeName); err != nil {
remoteServerLogger.Info("failed to get loader", storeName, err)
remoteServerLogger.Info("failed to get loader", "name", storeName, "error", err)
loader = testing.NewNonWriter()
}
}
Expand Down Expand Up @@ -212,8 +212,8 @@ func (s *server) Run(ctx context.Context, task *TestTask) (reply *TestResult, er
return
}

remoteServerLogger.Info("prepare to run: ", suite.Name, " with level: ", task.Level)
remoteServerLogger.Info("task kind: ", task.Kind, len(suite.Items), "to run")
remoteServerLogger.Info("prepare to run", "name", suite.Name, " with level: ", task.Level)
remoteServerLogger.Info("task kind to run", "kind", task.Kind, "lens", len(suite.Items))
dataContext := map[string]interface{}{}

if err = suite.Render(dataContext); err != nil {
Expand Down Expand Up @@ -653,7 +653,7 @@ func (s *server) GetSuggestedAPIs(ctx context.Context, in *TestSuiteIdentity) (r
return
}

remoteServerLogger.Info("Finding APIs from", in.Name, "with loader", reflect.TypeOf(loader))
remoteServerLogger.Info("Finding APIs from", "name", in.Name, "with loader", reflect.TypeOf(loader))

suiteRunner := runner.GetTestSuiteRunner(suite)
var result []*testing.TestCase
Expand Down Expand Up @@ -866,7 +866,7 @@ func findParentTestCases(testcase *testing.TestCase, suite *testing.TestSuite) (
findExpectNames(testcase.Request.API, expectNames)
findExpectNames(testcase.Request.Body.String(), expectNames)

remoteServerLogger.Info("expect test case names", expectNames.GetAll())
remoteServerLogger.Info("expect test case names", "name", expectNames.GetAll())
for _, item := range suite.Items {
if expectNames.Exist(item.Name) {
testcases = append(testcases, item)
Expand Down
5 changes: 3 additions & 2 deletions pkg/server/store_ext_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ package server

import (
"fmt"
"github.com/linuxsuren/api-testing/pkg/logging"
"os"
"strings"
"syscall"

"github.com/linuxsuren/api-testing/pkg/logging"

fakeruntime "github.com/linuxsuren/go-fake-runtime"
)

Expand Down Expand Up @@ -82,7 +83,7 @@ func (s *storeExtManager) Start(name, socket string) (err error) {
}

func (s *storeExtManager) StopAll() error {
serverLogger.Info("stop", len(s.processs), "extensions")
serverLogger.Info("stop", "extensions", len(s.processs))
for _, p := range s.processs {
if p != nil {
p.Signal(syscall.SIGTERM)
Expand Down
9 changes: 5 additions & 4 deletions pkg/testing/loader_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/linuxsuren/api-testing/pkg/logging"
"io"
"net/http"
"net/url"
Expand All @@ -29,6 +28,8 @@ import (
"strings"
"sync"

"github.com/linuxsuren/api-testing/pkg/logging"

"github.com/linuxsuren/api-testing/pkg/util"
)

Expand Down Expand Up @@ -164,13 +165,13 @@ func (l *fileLoader) ListTestSuite() (suites []TestSuite, err error) {
var data []byte
var loadErr error
if data, loadErr = loadData(target); err != nil {
loaderLogger.Info("failed to load data", loadErr)
loaderLogger.Info("failed to load data", "error", loadErr)
continue
}

var testSuite *TestSuite
if testSuite, loadErr = Parse(data); loadErr != nil {
loaderLogger.Info("failed to parse data", loadErr, "from", target)
loaderLogger.Info("failed to parse data", "error", loadErr, "from", target)
continue
}
suites = append(suites, *testSuite)
Expand Down Expand Up @@ -216,7 +217,7 @@ func (l *fileLoader) CreateSuite(name, api string) (err error) {

newSuiteFile := path.Join(l.parent, fmt.Sprintf("%s.yaml", name))
if newSuiteFile, err = filepath.Abs(newSuiteFile); err == nil {
loaderLogger.Info("new suite file:", newSuiteFile)
loaderLogger.Info("new suite file", "file", newSuiteFile)

suite := &TestSuite{
Name: name,
Expand Down
Loading

0 comments on commit 1837b57

Please sign in to comment.