Skip to content

Commit

Permalink
feat: support getting version from extension (#513)
Browse files Browse the repository at this point in the history
Co-authored-by: rick <linuxsuren@users.noreply.github.com>
  • Loading branch information
LinuxSuRen and LinuxSuRen authored Jul 12, 2024
1 parent 33c89be commit 6ce9363
Show file tree
Hide file tree
Showing 14 changed files with 624 additions and 343 deletions.
2 changes: 1 addition & 1 deletion pkg/runner/monitor/monitor.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/runner/monitor/monitor_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/server/fake_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func (s *fakeServer) Run(ctx context.Context, in *TestTask) (*TestResult, error)
}

// GetVersion returns the version
func (s *fakeServer) GetVersion(ctx context.Context, in *Empty) (reply *HelloReply, err error) {
reply = &HelloReply{
Message: s.version,
func (s *fakeServer) GetVersion(ctx context.Context, in *Empty) (reply *Version, err error) {
reply = &Version{
Version: s.version,
}
err = s.err
return
Expand Down
13 changes: 9 additions & 4 deletions pkg/server/remote_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ import (
"context"
"errors"
"fmt"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"io"
"net/http"
"os"
reflect "reflect"
"regexp"
"strings"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"

"github.com/linuxsuren/api-testing/pkg/util/home"

"github.com/linuxsuren/api-testing/pkg/mock"
Expand Down Expand Up @@ -317,8 +318,12 @@ func (s *server) RunTestSuite(srv Runner_RunTestSuiteServer) (err error) {
}

// GetVersion returns the version
func (s *server) GetVersion(ctx context.Context, in *Empty) (reply *HelloReply, err error) {
reply = &HelloReply{Message: version.GetVersion()}
func (s *server) GetVersion(ctx context.Context, in *Empty) (reply *Version, err error) {
reply = &Version{
Version: version.GetVersion(),
Date: version.GetDate(),
Commit: version.GetCommit(),
}
return
}

Expand Down
9 changes: 5 additions & 4 deletions pkg/server/remote_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,15 @@ func TestRemoteServer(t *testing.T) {
})
assert.NotNil(t, err)

var ver *HelloReply
var ver *Version
ver, err = server.GetVersion(ctx, &Empty{})
assert.Equal(t, "unknown", ver.Message)
assert.Equal(t, "unknown", ver.Version)
assert.Nil(t, err)

ver, err = server.Sample(ctx, &Empty{})
var sampleData *HelloReply
sampleData, err = server.Sample(ctx, &Empty{})
assert.Nil(t, err)
assert.Equal(t, sample.TestSuiteGitLab, ver.Message)
assert.Equal(t, sample.TestSuiteGitLab, sampleData.Message)

var suites *Suites
suites, err = server.GetSuites(ctx, &Empty{})
Expand Down
563 changes: 322 additions & 241 deletions pkg/server/server.pb.go

Large diffs are not rendered by default.

222 changes: 179 additions & 43 deletions pkg/server/server.pb.gw.go

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion pkg/server/server.proto
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ service Runner {
get: "/api/v1/functionsQuery"
};
}
rpc GetVersion(Empty) returns (HelloReply) {
rpc GetVersion(Empty) returns (Version) {
option (google.api.http) = {
get: "/api/v1/version"
};
Expand Down Expand Up @@ -497,3 +497,9 @@ message MockConfig {
string Prefix = 1;
string Config = 2;
}

message Version {
string version = 1;
string commit = 2;
string date = 3;
}
12 changes: 6 additions & 6 deletions pkg/server/server_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions pkg/server/server_grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,25 @@ func TestUnimplement(t *testing.T) {

func TestServer(t *testing.T) {
client, _ := server.NewFakeClient(context.Background(), "version", nil)
reply, err := client.GetVersion(context.Background(), &server.Empty{})
assert.NotNil(t, reply)
assert.Equal(t, "version", reply.GetMessage())
assert.Empty(t, reply.GetError())
ver, err := client.GetVersion(context.Background(), &server.Empty{})
assert.NotNil(t, ver)
assert.Equal(t, "version", ver.GetVersion())
assert.Nil(t, err)

var testResult *server.TestResult
testResult, err = client.Run(context.Background(), &server.TestTask{})
assert.NotNil(t, testResult)
assert.Nil(t, err)

var reply *server.HelloReply
reply, err = client.Sample(context.Background(), &server.Empty{})
assert.Nil(t, err)
assert.Empty(t, reply.GetMessage())

clientWithErr, _ := server.NewFakeClient(context.Background(), "version", errors.New("fake"))
reply, err = clientWithErr.GetVersion(context.Background(), &server.Empty{})
ver, err = clientWithErr.GetVersion(context.Background(), &server.Empty{})
assert.NotNil(t, err)
assert.Nil(t, reply)
assert.Nil(t, ver)

testResult, err = clientWithErr.Run(context.Background(), &server.TestTask{})
assert.NotNil(t, err)
Expand Down
70 changes: 38 additions & 32 deletions pkg/testing/remote/loader.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/testing/remote/loader.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ service Loader {
rpc UpdateTestCase(server.TestCase) returns (server.TestCase) {}
rpc DeleteTestCase(server.TestCase) returns (server.Empty) {}

rpc GetVersion(server.Empty) returns (server.Version) {}
rpc Verify(server.Empty) returns (server.ExtensionStatus) {}
rpc PProf(server.PProfRequest) returns (server.PProfData) {}
}
Expand Down
38 changes: 37 additions & 1 deletion pkg/testing/remote/loader_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6ce9363

Please sign in to comment.