Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"permissions": {
"allow": [
"Bash(go test:*)",
"Bash(go doc:*)",
"WebSearch",
"Bash(go env:*)",
"Bash(docker pull:*)"
]
}
}
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ jobs:
BuildDesktop:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
os: [ubuntu-latest, windows-latest, macos-latest, macos-14]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ jobs:
fail-fast: false
matrix:
# see https://github.com/actions/runner-images
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
os: [ubuntu-latest, windows-latest, macos-latest, macos-14]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
Expand Down
13 changes: 6 additions & 7 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"errors"
"fmt"
"golang.org/x/time/rate"
"io"
"net/http"
"os"
Expand All @@ -32,7 +33,6 @@ import (
"github.com/linuxsuren/api-testing/pkg/util/home"

"github.com/linuxsuren/api-testing/pkg/apispec"
"github.com/linuxsuren/api-testing/pkg/limit"
"github.com/linuxsuren/api-testing/pkg/logging"
"github.com/linuxsuren/api-testing/pkg/runner"
"github.com/linuxsuren/api-testing/pkg/runner/monitor"
Expand All @@ -55,8 +55,8 @@ type runOption struct {
thread int64
context context.Context
qps int32
burst int32
limiter limit.RateLimiter
burst int
limiter *rate.Limiter
startTime time.Time
reporter runner.TestReporter
reportFile string
Expand Down Expand Up @@ -137,7 +137,7 @@ func (o *runOption) addFlags(flags *pflag.FlagSet) {
flags.StringVarP(&o.swaggerURL, "swagger-url", "", "", "The URL of swagger")
flags.Int64VarP(&o.thread, "thread", "", 1, "Threads of the execution")
flags.Int32VarP(&o.qps, "qps", "", 5, "QPS")
flags.Int32VarP(&o.burst, "burst", "", 5, "burst")
flags.IntVarP(&o.burst, "burst", "", 5, "burst")
flags.StringVarP(&o.monitorDocker, "monitor-docker", "", "", "The docker container name to monitor")
}

Expand Down Expand Up @@ -256,10 +256,9 @@ func (o *runOption) startMonitor() (err error) {

func (o *runOption) runE(cmd *cobra.Command, args []string) (err error) {
o.startTime = time.Now()
o.limiter = limit.NewDefaultRateLimiter(o.qps, o.burst)
o.limiter = rate.NewLimiter(rate.Limit(o.qps), o.burst)
defer func() {
cmd.Printf("Consumed: %s\n", time.Since(o.startTime).String())
o.limiter.Stop()
}()

if err = o.loader.Put(o.pattern); err != nil {
Expand Down Expand Up @@ -400,7 +399,7 @@ func (o *runOption) runSuite(loader testing.Loader, dataContext map[string]inter
case <-stopSingal:
return
default:
o.limiter.Accept()
o.limiter.Allow()

ctxWithTimeout, cancel := context.WithTimeout(ctx, o.requestTimeout)
defer cancel() // Ensure context is always cancelled when leaving this scope
Expand Down
4 changes: 2 additions & 2 deletions cmd/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import (
"time"

"github.com/h2non/gock"
"github.com/linuxsuren/api-testing/pkg/limit"
atest "github.com/linuxsuren/api-testing/pkg/testing"
"github.com/linuxsuren/api-testing/pkg/util"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"golang.org/x/time/rate"
)

func TestRunSuite(t *testing.T) {
Expand Down Expand Up @@ -71,7 +71,7 @@ func TestRunSuite(t *testing.T) {
ctx := getDefaultContext()
opt := newDiscardRunOption()
opt.requestTimeout = 30 * time.Second
opt.limiter = limit.NewDefaultRateLimiter(0, 0)
opt.limiter = rate.NewLimiter(rate.Limit(0), 0)
stopSingal := make(chan struct{}, 1)

loader := atest.NewFileLoader()
Expand Down
2 changes: 1 addition & 1 deletion e2e/code-generator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG LAN_ENV=docker.io/library/golang:1.21

FROM ghcr.io/linuxsuren/api-testing:master AS atest
FROM ghcr.io/linuxsuren/hd:v0.0.42 as downloader
FROM ghcr.io/linuxsuren/hd:v0.0.42 AS downloader
RUN hd install jq
FROM $LAN_ENV

Expand Down
4 changes: 2 additions & 2 deletions e2e/code-generator/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
context: .
dockerfile: Dockerfile
args:
- LAN_ENV=docker.io/library/openjdk:23
- LAN_ENV=docker.io/library/openjdk:26-rc-jdk
command:
- /workspace/entrypoint.sh
- java
Expand Down Expand Up @@ -49,7 +49,7 @@ services:
context: .
dockerfile: Dockerfile
args:
- LAN_ENV=docker.io/library/openjdk:23
- LAN_ENV=docker.io/library/openjdk:26-rc-jdk
command:
- /workspace/entrypoint.sh
- curl
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/invopop/jsonschema v0.7.0
github.com/jhump/protoreflect v1.15.3
github.com/linuxsuren/go-fake-runtime v0.0.5
github.com/linuxsuren/go-service v0.0.2-0.20251117091849-c58edc8748d9
github.com/linuxsuren/go-service v0.0.2
github.com/linuxsuren/unstructured v0.0.1
github.com/prometheus/client_golang v1.22.0
github.com/prometheus/common v0.67.2
Expand All @@ -48,6 +48,7 @@ require (
github.com/gorilla/websocket v1.5.3
github.com/linuxsuren/http-downloader v0.0.99
golang.org/x/mod v0.28.0
golang.org/x/time v0.14.0
)

require (
Expand Down
24 changes: 4 additions & 20 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -131,28 +131,10 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/linuxsuren/go-fake-runtime v0.0.5 h1:x1qvuGMfly3L4BTwx6Hq5oUcuf/1u0kSVPzQylHHpwI=
github.com/linuxsuren/go-fake-runtime v0.0.5/go.mod h1:hlE6bZp76N3YPDsKi5YKOf1XmcJy4rvf8EtkTLYRYLw=
github.com/linuxsuren/go-service v0.0.1 h1:GoeK2HLDlRh+QQvFlxOferGtDUwzO3YduumMJ0XYPJ8=
github.com/linuxsuren/go-service v0.0.1/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
github.com/linuxsuren/go-service v0.0.2-0.20251117075600-96234f59e3f2 h1:vy8Y8NA7vjZmHE+28v2Un4mtc4DG1XtXo66hbeQ4pXE=
github.com/linuxsuren/go-service v0.0.2-0.20251117075600-96234f59e3f2/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
github.com/linuxsuren/go-service v0.0.2-0.20251117081324-130f4c6054f7 h1:/xN+kJ5Vo+FCCjasmapVw5lRMwb6sgdJZqTu02kfNag=
github.com/linuxsuren/go-service v0.0.2-0.20251117081324-130f4c6054f7/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
github.com/linuxsuren/go-service v0.0.2-0.20251117081529-39b6694d1e30 h1:C9aOFP9tVFcDKlQAd3X4rU43s+VmS/R/BNzHKWD6uhU=
github.com/linuxsuren/go-service v0.0.2-0.20251117081529-39b6694d1e30/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
github.com/linuxsuren/go-service v0.0.2-0.20251117082747-764ea1ba3825 h1:6CwFWPq2DjFrW1gbH2FtKPlNPCm1j0vgYBl5/LWeT6Y=
github.com/linuxsuren/go-service v0.0.2-0.20251117082747-764ea1ba3825/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
github.com/linuxsuren/go-service v0.0.2-0.20251117083110-fbec39b2f85d h1:+kMcMI8rB9VbpcfWH8h3lOH7sYjT0+uq0EWsDf1byf4=
github.com/linuxsuren/go-service v0.0.2-0.20251117083110-fbec39b2f85d/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
github.com/linuxsuren/go-service v0.0.2-0.20251117083330-afb28a74b935 h1:bAFGUhlWuRla9Di1Fq7alY9Q9lXeLDgHMQdyLPVbVOg=
github.com/linuxsuren/go-service v0.0.2-0.20251117083330-afb28a74b935/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
github.com/linuxsuren/go-service v0.0.2-0.20251117083554-81682ffea100 h1:7uMuI3tJB53C4+dlBrfF4FaQ9YxY3KvatUSZL9Kgo8A=
github.com/linuxsuren/go-service v0.0.2-0.20251117083554-81682ffea100/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
github.com/linuxsuren/go-service v0.0.2-0.20251117084203-71bf4d3ebe0f h1:XYw35A2a2XafK57MSSoyDICrTw+TOcUWWT0cqHE/Khw=
github.com/linuxsuren/go-service v0.0.2-0.20251117084203-71bf4d3ebe0f/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
github.com/linuxsuren/go-service v0.0.2-0.20251117091757-3ae9fc74c5b9 h1:5jCZ8Xh4Bxpq9pwrs+T4CBVCfG4gVTpx45t3s/0gnxI=
github.com/linuxsuren/go-service v0.0.2-0.20251117091757-3ae9fc74c5b9/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
github.com/linuxsuren/go-service v0.0.2-0.20251117091849-c58edc8748d9 h1:w5prP6ROOxInPV38KL+0laf7ZDIHlidBerhrphHqWHU=
github.com/linuxsuren/go-service v0.0.2-0.20251117091849-c58edc8748d9/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
github.com/linuxsuren/go-service v0.0.2 h1:4pq+LEXs1/V6qBCVW749PZbaXSQb3dyz/VR+xsdf95o=
github.com/linuxsuren/go-service v0.0.2/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
github.com/linuxsuren/http-downloader v0.0.99 h1:fEu+HkHdYeLM932c7IfmuaDJqWxVU5sIEnS/Aln8h9o=
github.com/linuxsuren/http-downloader v0.0.99/go.mod h1:OngIAkbOJTMbd+IMRbt3TiWSizVJZvPfjdbTpl6uHLo=
github.com/linuxsuren/oauth-hub v0.0.1 h1:5LAdX9ZlWhaM7P10rdxiXPk26eceYHRyfkFXsym6AxY=
Expand Down Expand Up @@ -334,6 +316,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI=
golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
Expand Down
91 changes: 0 additions & 91 deletions pkg/limit/limiter.go

This file was deleted.

54 changes: 0 additions & 54 deletions pkg/limit/limiter_long_test.go

This file was deleted.

29 changes: 0 additions & 29 deletions pkg/limit/limiter_test.go

This file was deleted.

13 changes: 12 additions & 1 deletion pkg/runner/expr_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"net/http"
"os"
"os/exec"
"runtime"
"time"

"github.com/expr-lang/expr"
Expand Down Expand Up @@ -140,8 +141,18 @@ func init() {
{
Name: "command",
Func: func(params ...interface{}) (res any, err error) {
if len(params) < 1 {
err = fmt.Errorf("the command param is required")
return
}

shParams := []string{"sh", "-c"}
if runtime.GOOS == "windows" {
shParams = []string{"cmd", "/c"}
}

var output []byte
output, err = exec.Command("sh", "-c", params[0].(string)).CombinedOutput()
output, err = exec.Command(shParams[0], shParams[1], params[0].(string)).CombinedOutput()
if output != nil {
res = string(output)
}
Expand Down
Loading
Loading