-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add git as the store extension
- Loading branch information
1 parent
18bd198
commit 6ec20bb
Showing
21 changed files
with
1,017 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => ../../. |
Oops, something went wrong.