diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
index f9ed161..8fa1209 100644
--- a/.github/workflows/build.yaml
+++ b/.github/workflows/build.yaml
@@ -5,6 +5,10 @@ on:
env:
IMG_TOOL: docker
+concurrency:
+ group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
+ cancel-in-progress: true
+
jobs:
Test:
runs-on: ubuntu-22.04
diff --git a/.github/workflows/qodana_code_quality.yml b/.github/workflows/qodana_code_quality.yml
index 33f5b95..aed96ed 100644
--- a/.github/workflows/qodana_code_quality.yml
+++ b/.github/workflows/qodana_code_quality.yml
@@ -5,11 +5,11 @@ on:
push:
branches:
- master
- - feat/mock-timer
jobs:
qodana:
runs-on: ubuntu-latest
+ if: github.actor == 'linuxsuren'
steps:
- uses: actions/checkout@v3
with:
diff --git a/console/atest-ui/src/views/TestCase.vue b/console/atest-ui/src/views/TestCase.vue
index 034ccbd..e78bed1 100644
--- a/console/atest-ui/src/views/TestCase.vue
+++ b/console/atest-ui/src/views/TestCase.vue
@@ -57,10 +57,7 @@ const sendRequest = async () => {
type: 'success'
})
}
- if (e.body !== '') {
- testResult.value.bodyObject = JSON.parse(e.body)
- testResult.value.originBodyObject = JSON.parse(e.body)
- }
+ parseResponseBody(e.body)
Cache.SetTestCaseResponseCache(suite + '-' + name, {
body: testResult.value.bodyObject,
@@ -74,11 +71,24 @@ const sendRequest = async () => {
requestLoading.value = false
UIAPI.ErrorTip(e)
- testResult.value.bodyObject = JSON.parse(e.body)
- testResult.value.originBodyObject = JSON.parse(e.body)
+
+ parseResponseBody(e.body)
})
}
+const parseResponseBody = (body) => {
+ if (body === '') {
+ return
+ }
+
+ try {
+ testResult.value.bodyObject = JSON.parse(body)
+ testResult.value.originBodyObject = JSON.parse(body)
+ } catch {
+ testResult.value.bodyText = body
+ }
+}
+
const responseBodyFilterText = ref('')
function responseBodyFilter() {
if (responseBodyFilterText.value === '') {
@@ -803,9 +813,14 @@ const queryHeaderValues = (queryString: string, cb: (arg: any) => void) => {
-
-
+
+
+
+
+
+
+
diff --git a/console/atest-ui/src/views/types.ts b/console/atest-ui/src/views/types.ts
index 9a0898c..fe686bb 100644
--- a/console/atest-ui/src/views/types.ts
+++ b/console/atest-ui/src/views/types.ts
@@ -1,5 +1,5 @@
/*
-Copyright 2023 API Testing Authors.
+Copyright 2023-2024 API Testing Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -30,12 +30,13 @@ export interface Suite {
export interface TestResult {
body: string
bodyObject: {}
+ bodyText: string
output: string
error: string
statusCode: number
header: Pair[]
- // inner fileds
+ // inner fields
originBodyObject:{}
}
diff --git a/pkg/server/remote_server.go b/pkg/server/remote_server.go
index 56c3d9f..1226955 100644
--- a/pkg/server/remote_server.go
+++ b/pkg/server/remote_server.go
@@ -431,14 +431,13 @@ func (s *server) GetTestCase(ctx context.Context, in *TestCaseIdentity) (reply *
func (s *server) RunTestCase(ctx context.Context, in *TestCaseIdentity) (result *TestCaseResult, err error) {
var targetTestSuite testing.TestSuite
+ result = &TestCaseResult{}
loader := s.getLoader(ctx)
defer loader.Close()
targetTestSuite, err = loader.GetTestSuite(in.Suite, true)
- if err != nil {
+ if err != nil || targetTestSuite.Name == "" {
err = nil
- result = &TestCaseResult{
- Error: fmt.Sprintf("not found suite: %s", in.Suite),
- }
+ result.Error = fmt.Sprintf("not found suite: %s", in.Suite)
return
}
@@ -453,9 +452,10 @@ func (s *server) RunTestCase(ctx context.Context, in *TestCaseIdentity) (result
}
var reply *TestResult
+ var lastItem *TestCaseResult
if reply, err = s.Run(ctx, task); err == nil && len(reply.TestCaseResult) > 0 {
lastIndex := len(reply.TestCaseResult) - 1
- lastItem := reply.TestCaseResult[lastIndex]
+ lastItem = reply.TestCaseResult[lastIndex]
if len(lastItem.Body) > GrpcMaxRecvMsgSize {
e := "the HTTP response body exceeded the maximum message size limit received by the gRPC client"
@@ -468,23 +468,18 @@ func (s *server) RunTestCase(ctx context.Context, in *TestCaseIdentity) (result
}
return
}
-
- result = &TestCaseResult{
- Output: reply.Message,
- Error: reply.Error,
- Body: lastItem.Body,
- Header: lastItem.Header,
- StatusCode: lastItem.StatusCode,
- }
} else if err != nil {
- result = &TestCaseResult{
- Error: err.Error(),
- }
- } else {
- result = &TestCaseResult{
- Output: reply.Message,
- Error: reply.Error,
- }
+ result.Error = err.Error()
+ }
+
+ if reply != nil {
+ result.Output = reply.Message
+ result.Error = reply.Error
+ }
+ if lastItem != nil {
+ result.Body = lastItem.Body
+ result.Header = lastItem.Header
+ result.StatusCode = lastItem.StatusCode
}
}
return
diff --git a/pkg/server/remote_server_test.go b/pkg/server/remote_server_test.go
index 961057e..512bb4c 100644
--- a/pkg/server/remote_server_test.go
+++ b/pkg/server/remote_server_test.go
@@ -31,6 +31,7 @@ import (
"github.com/h2non/gock"
atest "github.com/linuxsuren/api-testing/pkg/testing"
+ "github.com/linuxsuren/api-testing/pkg/util"
"github.com/linuxsuren/api-testing/sample"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/metadata"
@@ -127,22 +128,49 @@ func TestRemoteServer(t *testing.T) {
assert.Error(t, err)
}
+const sampleBody = `{"message": "hello"}`
+
func TestRunTestCase(t *testing.T) {
loader := atest.NewFileWriter("")
loader.Put("testdata/simple.yaml")
server := NewRemoteServer(loader, nil, nil, nil, "", 1024*1024*4)
- defer gock.Clean()
- gock.New(urlFoo).Get("/").MatchHeader("key", "value").
- Reply(http.StatusOK).
- BodyString(`{"message": "hello"}`)
+ t.Run("json response", func(t *testing.T) {
+ defer gock.Clean()
+ gock.New(urlFoo).Get("/").MatchHeader("key", "value").
+ Reply(http.StatusOK).SetHeader(util.ContentType, util.JSON).
+ BodyString(sampleBody)
- result, err := server.RunTestCase(context.TODO(), &TestCaseIdentity{
- Suite: "simple",
- Testcase: "get",
+ result, err := server.RunTestCase(context.TODO(), &TestCaseIdentity{
+ Suite: "simple",
+ Testcase: "get",
+ })
+ assert.NoError(t, err)
+ assert.Equal(t, sampleBody, result.Body)
+ assert.Contains(t, result.Output, "start to run: 'get'\nstart to send request to http://foo\ntest case \"get\", status code: 200\n")
+ })
+
+ t.Run("text response", func(t *testing.T) {
+ defer gock.Clean()
+ gock.New(urlFoo).Get("/").MatchHeader("key", "value").
+ Reply(http.StatusOK).SetHeader(util.ContentType, util.Plain).
+ BodyString(sampleBody)
+
+ result, err := server.RunTestCase(context.TODO(), &TestCaseIdentity{
+ Suite: "simple",
+ Testcase: "get",
+ })
+ assert.NoError(t, err)
+ assert.Equal(t, sampleBody, result.Body)
+ })
+
+ t.Run("not suite found", func(t *testing.T) {
+ result, err := server.RunTestCase(context.TODO(), &TestCaseIdentity{
+ Suite: "not-found",
+ })
+ assert.NoError(t, err)
+ assert.NotEmpty(t, result.Error)
})
- assert.NoError(t, err)
- assert.Contains(t, result.Output, "start to run: 'get'\nstart to send request to http://foo\ntest case \"get\", status code: 200\n")
}
func TestFindParentTestCases(t *testing.T) {