Skip to content

Commit

Permalink
feat: add git as the store extension
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxSuRen committed Aug 14, 2023
1 parent 18bd198 commit 6ec20bb
Show file tree
Hide file tree
Showing 21 changed files with 1,017 additions and 236 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v3.0.0
- name: Unit Test
run: |
make test-all-backend
make test-all-backend test-operator
- name: Report
if: github.actor == 'linuxsuren'
env:
Expand All @@ -24,6 +24,7 @@ jobs:
bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial --force-coverage-parser go -r collector-coverage.out
bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial --force-coverage-parser go -r store-orm-coverage.out
bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial --force-coverage-parser go -r store-s3-coverage.out
bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial --force-coverage-parser go -r store-git-coverage.out
bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial --force-coverage-parser go -r operator/cover.out
bash <(curl -Ls https://coverage.codacy.com/get.sh) final
- name: API Test
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- uses: actions/checkout@v3.0.0
- name: Unit Test
run: |
make test-all-backend
make test-all-backend test-operator
- name: Report
if: github.actor == 'linuxsuren'
env:
Expand All @@ -60,6 +60,7 @@ jobs:
bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial --force-coverage-parser go -r collector-coverage.out
bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial --force-coverage-parser go -r store-orm-coverage.out
bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial --force-coverage-parser go -r store-s3-coverage.out
bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial --force-coverage-parser go -r store-git-coverage.out
bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial --force-coverage-parser go -r operator/cover.out
bash <(curl -Ls https://coverage.codacy.com/get.sh) final
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ RUN GOPROXY=${GOPROXY} CGO_ENABLED=0 go build -ldflags "-w -s -X github.com/linu
RUN GOPROXY=${GOPROXY} CGO_ENABLED=0 go build -ldflags "-w -s" -o atest-collector extensions/collector/main.go
RUN GOPROXY=${GOPROXY} CGO_ENABLED=0 go build -ldflags "-w -s" -o atest-store-orm extensions/store-orm/main.go
RUN GOPROXY=${GOPROXY} CGO_ENABLED=0 go build -ldflags "-w -s" -o atest-store-s3 extensions/store-s3/main.go
RUN GOPROXY=${GOPROXY} CGO_ENABLED=0 go build -ldflags "-w -s" -o atest-store-git extensions/store-git/main.go

FROM node:20-alpine3.17 AS ui

Expand All @@ -49,6 +50,7 @@ COPY --from=builder /workspace/atest /usr/local/bin/atest
COPY --from=builder /workspace/atest-collector /usr/local/bin/atest-collector
COPY --from=builder /workspace/atest-store-orm /usr/local/bin/atest-store-orm
COPY --from=builder /workspace/atest-store-s3 /usr/local/bin/atest-store-s3
COPY --from=builder /workspace/atest-store-git /usr/local/bin/atest-store-git
COPY --from=builder /workspace/LICENSE /LICENSE
COPY --from=builder /workspace/README.md /README.md

Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ test-store-orm:
test-store-s3:
go test github.com/linuxsuren/api-testing/extensions/store-s3/./... -cover -v -coverprofile=store-s3-coverage.out
go tool cover -func=store-s3-coverage.out
test-store-git:
go test github.com/linuxsuren/api-testing/extensions/store-git/./... -cover -v -coverprofile=store-git-coverage.out
go tool cover -func=store-git-coverage.out
test-operator:
cd operator && make test # converage file path: operator/cover.out
test-all-backend: test test-collector test-store-orm test-store-s3 test-operator
test-all-backend: test test-collector test-store-orm test-store-s3 test-store-git #test-operator
test-all: test-all-backend test-ui

install-precheck:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This is a API testing tool.

## Features

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

Expand Down
24 changes: 24 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ There are multiple storage backends supported. See the status from the list:
| Local Storage | Ready |
| S3 | Ready |
| ORM DataBase | Developing |
| Git Repository | Developing |
| Etcd DataBase | Developing |

### Local Storage
Expand Down Expand Up @@ -137,6 +138,29 @@ See also the expected configuration below:
region: cn
```
### Git Storage
You can use a git repository as the storage backend.
```shell
# The default port is 7074
podman run --network host \
ghcr.io/linuxsuren/api-testing:master atest-store-git
```

See also the expected configuration below:

```yaml
- name: git
url: http://172.11.0.13:30999 # address of the git repository
username: linuxsuren
password: linuxsuren
kind:
name: git
url: localhost:7074 # address of the git storage extension
properties:
targetPath: .
```
## Secret Server
You can put the sensitive information into a secret server. For example, [Vault](https://github.com/hashicorp/vault).
Expand Down
74 changes: 74 additions & 0 deletions extensions/store-git/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
MIT License
Copyright (c) 2023 API Testing Authors.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package cmd

import (
"fmt"
"net"

"github.com/linuxsuren/api-testing/extensions/store-git/pkg"
"github.com/linuxsuren/api-testing/pkg/testing/remote"
"github.com/spf13/cobra"
"google.golang.org/grpc"
)

// NewRootCommand returns the root Command
func NewRootCommand() (c *cobra.Command) {
opt := &options{}
c = &cobra.Command{
Use: "atest-store-git",
Short: "A store extension for git",
RunE: opt.runE,
}
flags := c.Flags()
flags.IntVarP(&opt.port, "port", "p", 7074, "The port to listen on")
return
}

type options struct {
port int
}

func (o *options) runE(c *cobra.Command, args []string) (err error) {
removeServer := pkg.NewRemoteServer()

var lis net.Listener
lis, err = net.Listen("tcp", fmt.Sprintf(":%d", o.port))
if err != nil {
return
}

gRPCServer := grpc.NewServer()
remote.RegisterLoaderServer(gRPCServer, removeServer)
c.Println("Git storage extension is running at port", o.port)

go func() {
<-c.Context().Done()
gRPCServer.Stop()
}()

err = gRPCServer.Serve(lis)
return
}
68 changes: 68 additions & 0 deletions extensions/store-git/cmd/root_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
MIT License
Copyright (c) 2023 API Testing Authors.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package cmd

import (
"context"
"io"
"testing"
"time"

"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)

func TestNewRootCmd(t *testing.T) {
t.Run("not run", func(t *testing.T) {
cmd := newRootCmdForTest()
assert.NotNil(t, cmd)
assert.Equal(t, "atest-store-git", cmd.Use)
assert.Equal(t, "7074", cmd.Flags().Lookup("port").Value.String())
})

t.Run("invalid port", func(t *testing.T) {
cmd := newRootCmdForTest()
cmd.SetArgs([]string{"--port", "-1"})
err := cmd.Execute()
assert.Error(t, err)
})

t.Run("stop the command", func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.TODO(), time.Second)
defer cancel()

cmd := newRootCmdForTest()
cmd.SetContext(ctx)
cmd.SetArgs([]string{"--port", "0"})
err := cmd.Execute()
assert.NoError(t, err)
})
}

func newRootCmdForTest() *cobra.Command {
cmd := NewRootCommand()
cmd.SetOut(io.Discard)
return cmd
}
78 changes: 78 additions & 0 deletions extensions/store-git/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
module github.com/linuxsuren/api-testing/extensions/store-git

go 1.20

require (
github.com/go-git/go-git v4.7.0+incompatible
github.com/go-git/go-git/v5 v5.8.1
github.com/linuxsuren/api-testing v0.0.0-00010101000000-000000000000
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.8.4
google.golang.org/grpc v1.57.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 // indirect
github.com/antonmedv/expr v1.12.1 // indirect
github.com/bufbuild/protocompile v0.6.0 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/flopp/go-findfont v0.1.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.4.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/linuxsuren/go-fake-runtime v0.0.1 // indirect
github.com/linuxsuren/unstructured v0.0.1 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.0 // indirect
github.com/phpdave11/gofpdi v1.0.14-0.20211212211723-1f10f9844311 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/signintech/gopdf v0.18.0 // indirect
github.com/skeema/knownhosts v1.2.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tidwall/gjson v1.14.4 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/tools v0.6.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/src-d/go-git.v4 v4.13.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/linuxsuren/api-testing => ../../.
Loading

0 comments on commit 6ec20bb

Please sign in to comment.