Skip to content

Commit e081118

Browse files
authored
feat: add git as the store extension (#165)
* feat: add git as the store extension * fix: the height of center zone of the UI * ui: add query setting for testcase --------- Co-authored-by: rick <[email protected]>
1 parent 18bd198 commit e081118

File tree

24 files changed

+1050
-237
lines changed

24 files changed

+1050
-237
lines changed

.github/workflows/build.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions/[email protected]
1515
- name: Unit Test
1616
run: |
17-
make test-all-backend
17+
make test-all-backend test-operator
1818
- name: Report
1919
if: github.actor == 'linuxsuren'
2020
env:
@@ -24,6 +24,7 @@ jobs:
2424
bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial --force-coverage-parser go -r collector-coverage.out
2525
bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial --force-coverage-parser go -r store-orm-coverage.out
2626
bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial --force-coverage-parser go -r store-s3-coverage.out
27+
bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial --force-coverage-parser go -r store-git-coverage.out
2728
bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial --force-coverage-parser go -r operator/cover.out
2829
bash <(curl -Ls https://coverage.codacy.com/get.sh) final
2930
- name: API Test

.github/workflows/release.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
- uses: actions/[email protected]
5151
- name: Unit Test
5252
run: |
53-
make test-all-backend
53+
make test-all-backend test-operator
5454
- name: Report
5555
if: github.actor == 'linuxsuren'
5656
env:
@@ -60,6 +60,7 @@ jobs:
6060
bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial --force-coverage-parser go -r collector-coverage.out
6161
bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial --force-coverage-parser go -r store-orm-coverage.out
6262
bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial --force-coverage-parser go -r store-s3-coverage.out
63+
bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial --force-coverage-parser go -r store-git-coverage.out
6364
bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial --force-coverage-parser go -r operator/cover.out
6465
bash <(curl -Ls https://coverage.codacy.com/get.sh) final
6566

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ RUN GOPROXY=${GOPROXY} CGO_ENABLED=0 go build -ldflags "-w -s -X github.com/linu
2424
RUN GOPROXY=${GOPROXY} CGO_ENABLED=0 go build -ldflags "-w -s" -o atest-collector extensions/collector/main.go
2525
RUN GOPROXY=${GOPROXY} CGO_ENABLED=0 go build -ldflags "-w -s" -o atest-store-orm extensions/store-orm/main.go
2626
RUN GOPROXY=${GOPROXY} CGO_ENABLED=0 go build -ldflags "-w -s" -o atest-store-s3 extensions/store-s3/main.go
27+
RUN GOPROXY=${GOPROXY} CGO_ENABLED=0 go build -ldflags "-w -s" -o atest-store-git extensions/store-git/main.go
2728

2829
FROM node:20-alpine3.17 AS ui
2930

@@ -49,6 +50,7 @@ COPY --from=builder /workspace/atest /usr/local/bin/atest
4950
COPY --from=builder /workspace/atest-collector /usr/local/bin/atest-collector
5051
COPY --from=builder /workspace/atest-store-orm /usr/local/bin/atest-store-orm
5152
COPY --from=builder /workspace/atest-store-s3 /usr/local/bin/atest-store-s3
53+
COPY --from=builder /workspace/atest-store-git /usr/local/bin/atest-store-git
5254
COPY --from=builder /workspace/LICENSE /LICENSE
5355
COPY --from=builder /workspace/README.md /README.md
5456

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ test-store-orm:
4848
test-store-s3:
4949
go test github.com/linuxsuren/api-testing/extensions/store-s3/./... -cover -v -coverprofile=store-s3-coverage.out
5050
go tool cover -func=store-s3-coverage.out
51+
test-store-git:
52+
go test github.com/linuxsuren/api-testing/extensions/store-git/./... -cover -v -coverprofile=store-git-coverage.out
53+
go tool cover -func=store-git-coverage.out
5154
test-operator:
5255
cd operator && make test # converage file path: operator/cover.out
53-
test-all-backend: test test-collector test-store-orm test-store-s3 test-operator
56+
test-all-backend: test test-collector test-store-orm test-store-s3 test-store-git #test-operator
5457
test-all: test-all-backend test-ui
5558

5659
install-precheck:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This is a API testing tool.
88

99
## Features
1010

11-
* Multiple test report formats: Markdown, HTML, Stdout
11+
* Multiple test report formats: Markdown, HTML, PDF, Stdout
1212
* Response Body fields equation check
1313
* Response Body [eval](https://expr.medv.io/)
1414
* Verify the Kubernetes resources
@@ -17,7 +17,7 @@ This is a API testing tool.
1717
* Output reference between TestCase
1818
* Run in server mode, and provide the [gRPC](pkg/server/server.proto) and HTTP endpoint
1919
* [VS Code extension](https://github.com/LinuxSuRen/vscode-api-testing) support
20-
* Multiple storage backends supported(Local, ORM Database, S3, etc)
20+
* Multiple storage backends supported(Local, ORM Database, S3, Git, etc)
2121
* [HTTP API record](extensions/collector)
2222
* Install in mutiple use cases(CLI, Container, Native-Service, Operator, etc)
2323

console/atest-ui/src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ const viewName = ref('testcase')
198198

199199
<template>
200200
<div class="common-layout" data-title="Welcome!" data-intro="Welcome to use api-testing! 👋">
201-
<el-container>
201+
<el-container style="height: 100%">
202202
<el-header style="height: 30px;justify-content: flex-end;">
203203
<el-button type="primary" :icon="Share" @click="viewName = ''" />
204204
</el-header>

console/atest-ui/src/views/TestCase.vue

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,16 @@ function bodyFiledExpectChange() {
300300
}
301301
}
302302
303+
function queryChange() {
304+
const query = testCaseWithSuite.value.data.request.query
305+
let lastItem = query[query.length - 1]
306+
if (lastItem.key !== '') {
307+
testCaseWithSuite.value.data.request.query.push({
308+
key: '',
309+
value: ''
310+
} as Pair)
311+
}
312+
}
303313
function headerChange() {
304314
const header = testCaseWithSuite.value.data.request.header
305315
let lastItem = header[header.length - 1]
@@ -441,6 +451,27 @@ const queryPupularHeaders = (queryString: string, cb: (arg: any) => void) => {
441451

442452
<el-main>
443453
<el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
454+
<el-tab-pane label="Query" name="query">
455+
<el-table :data="testCaseWithSuite.data.request.query" style="width: 100%">
456+
<el-table-column label="Key" width="180">
457+
<template #default="scope">
458+
<el-autocomplete
459+
v-model="scope.row.key"
460+
placeholder="Key"
461+
@change="queryChange"
462+
/>
463+
</template>
464+
</el-table-column>
465+
<el-table-column label="Value">
466+
<template #default="scope">
467+
<div style="display: flex; align-items: center">
468+
<el-input v-model="scope.row.value" placeholder="Value" />
469+
</div>
470+
</template>
471+
</el-table-column>
472+
</el-table>
473+
</el-tab-pane>
474+
444475
<el-tab-pane label="Headers" name="second">
445476
<el-table :data="testCaseWithSuite.data.request.header" style="width: 100%">
446477
<el-table-column label="Key" width="180">

docs/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ There are multiple storage backends supported. See the status from the list:
5555
| Local Storage | Ready |
5656
| S3 | Ready |
5757
| ORM DataBase | Developing |
58+
| Git Repository | Developing |
5859
| Etcd DataBase | Developing |
5960

6061
### Local Storage
@@ -137,6 +138,29 @@ See also the expected configuration below:
137138
region: cn
138139
```
139140
141+
### Git Storage
142+
You can use a git repository as the storage backend.
143+
144+
```shell
145+
# The default port is 7074
146+
podman run --network host \
147+
ghcr.io/linuxsuren/api-testing:master atest-store-git
148+
```
149+
150+
See also the expected configuration below:
151+
152+
```yaml
153+
- name: git
154+
url: http://172.11.0.13:30999 # address of the git repository
155+
username: linuxsuren
156+
password: linuxsuren
157+
kind:
158+
name: git
159+
url: localhost:7074 # address of the git storage extension
160+
properties:
161+
targetPath: .
162+
```
163+
140164
## Secret Server
141165
You can put the sensitive information into a secret server. For example, [Vault](https://www.github.com/hashicorp/vault).
142166

extensions/store-git/cmd/root.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
MIT License
3+
4+
Copyright (c) 2023 API Testing Authors.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
25+
package cmd
26+
27+
import (
28+
"fmt"
29+
"net"
30+
31+
"github.com/linuxsuren/api-testing/extensions/store-git/pkg"
32+
"github.com/linuxsuren/api-testing/pkg/testing/remote"
33+
"github.com/spf13/cobra"
34+
"google.golang.org/grpc"
35+
)
36+
37+
// NewRootCommand returns the root Command
38+
func NewRootCommand() (c *cobra.Command) {
39+
opt := &options{}
40+
c = &cobra.Command{
41+
Use: "atest-store-git",
42+
Short: "A store extension for git",
43+
RunE: opt.runE,
44+
}
45+
flags := c.Flags()
46+
flags.IntVarP(&opt.port, "port", "p", 7074, "The port to listen on")
47+
return
48+
}
49+
50+
type options struct {
51+
port int
52+
}
53+
54+
func (o *options) runE(c *cobra.Command, args []string) (err error) {
55+
removeServer := pkg.NewRemoteServer()
56+
57+
var lis net.Listener
58+
lis, err = net.Listen("tcp", fmt.Sprintf(":%d", o.port))
59+
if err != nil {
60+
return
61+
}
62+
63+
gRPCServer := grpc.NewServer()
64+
remote.RegisterLoaderServer(gRPCServer, removeServer)
65+
c.Println("Git storage extension is running at port", o.port)
66+
67+
go func() {
68+
<-c.Context().Done()
69+
gRPCServer.Stop()
70+
}()
71+
72+
err = gRPCServer.Serve(lis)
73+
return
74+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
MIT License
3+
4+
Copyright (c) 2023 API Testing Authors.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
25+
package cmd
26+
27+
import (
28+
"context"
29+
"io"
30+
"testing"
31+
"time"
32+
33+
"github.com/spf13/cobra"
34+
"github.com/stretchr/testify/assert"
35+
)
36+
37+
func TestNewRootCmd(t *testing.T) {
38+
t.Run("not run", func(t *testing.T) {
39+
cmd := newRootCmdForTest()
40+
assert.NotNil(t, cmd)
41+
assert.Equal(t, "atest-store-git", cmd.Use)
42+
assert.Equal(t, "7074", cmd.Flags().Lookup("port").Value.String())
43+
})
44+
45+
t.Run("invalid port", func(t *testing.T) {
46+
cmd := newRootCmdForTest()
47+
cmd.SetArgs([]string{"--port", "-1"})
48+
err := cmd.Execute()
49+
assert.Error(t, err)
50+
})
51+
52+
t.Run("stop the command", func(t *testing.T) {
53+
ctx, cancel := context.WithTimeout(context.TODO(), time.Second)
54+
defer cancel()
55+
56+
cmd := newRootCmdForTest()
57+
cmd.SetContext(ctx)
58+
cmd.SetArgs([]string{"--port", "0"})
59+
err := cmd.Execute()
60+
assert.NoError(t, err)
61+
})
62+
}
63+
64+
func newRootCmdForTest() *cobra.Command {
65+
cmd := NewRootCommand()
66+
cmd.SetOut(io.Discard)
67+
return cmd
68+
}

0 commit comments

Comments
 (0)