Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support to generate sample YAML via grpc #76

Merged
merged 1 commit into from
May 30, 2023
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ run-image:
docker run ghcr.io/linuxsuren/api-testing:dev
copy: build
sudo cp bin/atest /usr/local/bin/
copy-restart:
copy-restart: build
atest service stop
make copy
atest service restart
Expand Down
9 changes: 9 additions & 0 deletions pkg/server/fake_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ func (s *fakeServer) GetVersion(ctx context.Context, in *Empty) (reply *HelloRep
return
}

// Sample returns a sample of the test task
func (s *fakeServer) Sample(ctx context.Context, in *Empty) (reply *HelloReply, err error) {
reply = &HelloReply{
Message: "",
}
err = s.err
return
}

// NewFakeClient creates a fake client
func NewFakeClient(ctx context.Context, version string, err error) (RunnerClient, func()) {
buffer := 101024 * 1024
Expand Down
7 changes: 7 additions & 0 deletions pkg/server/remote_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/linuxsuren/api-testing/pkg/runner"
"github.com/linuxsuren/api-testing/pkg/testing"
"github.com/linuxsuren/api-testing/pkg/version"
"github.com/linuxsuren/api-testing/sample"
)

type server struct {
Expand Down Expand Up @@ -140,6 +141,12 @@ func (s *server) GetVersion(ctx context.Context, in *Empty) (reply *HelloReply,
return
}

// Sample returns a sample of the test task
func (s *server) Sample(ctx context.Context, in *Empty) (reply *HelloReply, err error) {
reply = &HelloReply{Message: sample.TestSuiteGitLab}
return
}

func findParentTestCases(testcase *testing.TestCase, suite *testing.TestSuite) (testcases []testing.TestCase) {
reg, matchErr := regexp.Compile(`(.*?\{\{.*\.\w*.*?\}\})`)
targetReg, targetErr := regexp.Compile(`\.\w*`)
Expand Down
5 changes: 5 additions & 0 deletions pkg/server/remote_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/h2non/gock"
atesting "github.com/linuxsuren/api-testing/pkg/testing"
"github.com/linuxsuren/api-testing/sample"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -61,6 +62,10 @@ func TestRemoteServer(t *testing.T) {
ver, err = server.GetVersion(context.TODO(), &Empty{})
assert.Empty(t, ver.Message)
assert.Nil(t, err)

ver, err = server.Sample(context.TODO(), &Empty{})
assert.Nil(t, err)
assert.Equal(t, sample.TestSuiteGitLab, ver.Message)
}

func TestFindParentTestCases(t *testing.T) {
Expand Down
Loading