diff --git a/pkg/server/remote_server.go b/pkg/server/remote_server.go index c759e87c..592c28f0 100644 --- a/pkg/server/remote_server.go +++ b/pkg/server/remote_server.go @@ -5,6 +5,7 @@ import ( "bytes" context "context" "fmt" + "os" "strings" "github.com/linuxsuren/api-testing/pkg/render" @@ -25,6 +26,22 @@ func NewRemoteServer() RunnerServer { // Run start to run the test task func (s *server) Run(ctx context.Context, task *TestTask) (reply *HelloReply, err error) { var suite *testing.TestSuite + if task.Env == nil { + task.Env = map[string]string{} + } + + // TODO may not safe in multiple threads + oldEnv := map[string]string{} + for key, val := range task.Env { + oldEnv[key] = os.Getenv(key) + os.Setenv(key, val) + } + + defer func() { + for key, val := range oldEnv { + os.Setenv(key, val) + } + }() switch task.Kind { case "suite": @@ -69,6 +86,7 @@ func (s *server) Run(ctx context.Context, task *TestTask) (reply *HelloReply, er return } + fmt.Println("prepare to run:", suite.Name) dataContext := map[string]interface{}{} var result string diff --git a/pkg/server/remote_server_test.go b/pkg/server/remote_server_test.go index 5b1f3ac3..8e46ef20 100644 --- a/pkg/server/remote_server_test.go +++ b/pkg/server/remote_server_test.go @@ -46,6 +46,9 @@ func TestRemoteServer(t *testing.T) { Kind: "testcaseInSuite", Data: simpleSuite, CaseName: "fake", + Env: map[string]string{ + "SERVER": "http://localhost:9090", + }, }) assert.NotNil(t, err) diff --git a/pkg/server/server.pb.go b/pkg/server/server.pb.go index 2cb0b9dd..dd728648 100644 --- a/pkg/server/server.pb.go +++ b/pkg/server/server.pb.go @@ -1,288 +1,188 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.28.1 -// protoc v4.22.2 // source: pkg/server/server.proto package server import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" ) -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf -type TestTask struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package - Data string `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` - Kind string `protobuf:"bytes,2,opt,name=kind,proto3" json:"kind,omitempty"` - CaseName string `protobuf:"bytes,3,opt,name=caseName,proto3" json:"caseName,omitempty"` +type TestTask struct { + Data string `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` + Kind string `protobuf:"bytes,2,opt,name=kind,proto3" json:"kind,omitempty"` + CaseName string `protobuf:"bytes,3,opt,name=caseName,proto3" json:"caseName,omitempty"` + Env map[string]string `protobuf:"bytes,4,rep,name=env,proto3" json:"env,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *TestTask) Reset() { *m = TestTask{} } +func (m *TestTask) String() string { return proto.CompactTextString(m) } +func (*TestTask) ProtoMessage() {} +func (*TestTask) Descriptor() ([]byte, []int) { + return fileDescriptor_36fb7b77b8f76c98, []int{0} } -func (x *TestTask) Reset() { - *x = TestTask{} - if protoimpl.UnsafeEnabled { - mi := &file_pkg_server_server_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } +func (m *TestTask) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_TestTask.Unmarshal(m, b) } - -func (x *TestTask) String() string { - return protoimpl.X.MessageStringOf(x) +func (m *TestTask) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_TestTask.Marshal(b, m, deterministic) +} +func (m *TestTask) XXX_Merge(src proto.Message) { + xxx_messageInfo_TestTask.Merge(m, src) +} +func (m *TestTask) XXX_Size() int { + return xxx_messageInfo_TestTask.Size(m) +} +func (m *TestTask) XXX_DiscardUnknown() { + xxx_messageInfo_TestTask.DiscardUnknown(m) } -func (*TestTask) ProtoMessage() {} +var xxx_messageInfo_TestTask proto.InternalMessageInfo -func (x *TestTask) ProtoReflect() protoreflect.Message { - mi := &file_pkg_server_server_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms +func (m *TestTask) GetData() string { + if m != nil { + return m.Data } - return mi.MessageOf(x) -} - -// Deprecated: Use TestTask.ProtoReflect.Descriptor instead. -func (*TestTask) Descriptor() ([]byte, []int) { - return file_pkg_server_server_proto_rawDescGZIP(), []int{0} + return "" } -func (x *TestTask) GetData() string { - if x != nil { - return x.Data +func (m *TestTask) GetKind() string { + if m != nil { + return m.Kind } return "" } -func (x *TestTask) GetKind() string { - if x != nil { - return x.Kind +func (m *TestTask) GetCaseName() string { + if m != nil { + return m.CaseName } return "" } -func (x *TestTask) GetCaseName() string { - if x != nil { - return x.CaseName +func (m *TestTask) GetEnv() map[string]string { + if m != nil { + return m.Env } - return "" + return nil } type HelloReply struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } -func (x *HelloReply) Reset() { - *x = HelloReply{} - if protoimpl.UnsafeEnabled { - mi := &file_pkg_server_server_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } +func (m *HelloReply) Reset() { *m = HelloReply{} } +func (m *HelloReply) String() string { return proto.CompactTextString(m) } +func (*HelloReply) ProtoMessage() {} +func (*HelloReply) Descriptor() ([]byte, []int) { + return fileDescriptor_36fb7b77b8f76c98, []int{1} } -func (x *HelloReply) String() string { - return protoimpl.X.MessageStringOf(x) +func (m *HelloReply) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_HelloReply.Unmarshal(m, b) } - -func (*HelloReply) ProtoMessage() {} - -func (x *HelloReply) ProtoReflect() protoreflect.Message { - mi := &file_pkg_server_server_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) +func (m *HelloReply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_HelloReply.Marshal(b, m, deterministic) } - -// Deprecated: Use HelloReply.ProtoReflect.Descriptor instead. -func (*HelloReply) Descriptor() ([]byte, []int) { - return file_pkg_server_server_proto_rawDescGZIP(), []int{1} +func (m *HelloReply) XXX_Merge(src proto.Message) { + xxx_messageInfo_HelloReply.Merge(m, src) +} +func (m *HelloReply) XXX_Size() int { + return xxx_messageInfo_HelloReply.Size(m) } +func (m *HelloReply) XXX_DiscardUnknown() { + xxx_messageInfo_HelloReply.DiscardUnknown(m) +} + +var xxx_messageInfo_HelloReply proto.InternalMessageInfo -func (x *HelloReply) GetMessage() string { - if x != nil { - return x.Message +func (m *HelloReply) GetMessage() string { + if m != nil { + return m.Message } return "" } type Empty struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } -func (x *Empty) Reset() { - *x = Empty{} - if protoimpl.UnsafeEnabled { - mi := &file_pkg_server_server_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } +func (m *Empty) Reset() { *m = Empty{} } +func (m *Empty) String() string { return proto.CompactTextString(m) } +func (*Empty) ProtoMessage() {} +func (*Empty) Descriptor() ([]byte, []int) { + return fileDescriptor_36fb7b77b8f76c98, []int{2} } -func (x *Empty) String() string { - return protoimpl.X.MessageStringOf(x) +func (m *Empty) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Empty.Unmarshal(m, b) } - -func (*Empty) ProtoMessage() {} - -func (x *Empty) ProtoReflect() protoreflect.Message { - mi := &file_pkg_server_server_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) +func (m *Empty) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Empty.Marshal(b, m, deterministic) } - -// Deprecated: Use Empty.ProtoReflect.Descriptor instead. -func (*Empty) Descriptor() ([]byte, []int) { - return file_pkg_server_server_proto_rawDescGZIP(), []int{2} +func (m *Empty) XXX_Merge(src proto.Message) { + xxx_messageInfo_Empty.Merge(m, src) } - -var File_pkg_server_server_proto protoreflect.FileDescriptor - -var file_pkg_server_server_proto_rawDesc = []byte{ - 0x0a, 0x17, 0x70, 0x6b, 0x67, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x73, 0x65, 0x72, - 0x76, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, - 0x72, 0x22, 0x4e, 0x0a, 0x08, 0x54, 0x65, 0x73, 0x74, 0x54, 0x61, 0x73, 0x6b, 0x12, 0x12, 0x0a, - 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, 0x74, - 0x61, 0x12, 0x12, 0x0a, 0x04, 0x6b, 0x69, 0x6e, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x04, 0x6b, 0x69, 0x6e, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x61, 0x73, 0x65, 0x4e, 0x61, 0x6d, - 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x61, 0x73, 0x65, 0x4e, 0x61, 0x6d, - 0x65, 0x22, 0x26, 0x0a, 0x0a, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, - 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x07, 0x0a, 0x05, 0x45, 0x6d, 0x70, - 0x74, 0x79, 0x32, 0x6a, 0x0a, 0x06, 0x52, 0x75, 0x6e, 0x6e, 0x65, 0x72, 0x12, 0x2d, 0x0a, 0x03, - 0x52, 0x75, 0x6e, 0x12, 0x10, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x54, 0x65, 0x73, - 0x74, 0x54, 0x61, 0x73, 0x6b, 0x1a, 0x12, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x48, - 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x31, 0x0a, 0x0a, 0x47, - 0x65, 0x74, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x0d, 0x2e, 0x73, 0x65, 0x72, 0x76, - 0x65, 0x72, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x12, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, - 0x72, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x2e, - 0x5a, 0x2c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6c, 0x69, 0x6e, - 0x75, 0x78, 0x73, 0x75, 0x72, 0x65, 0x6e, 0x2f, 0x61, 0x70, 0x69, 0x2d, 0x74, 0x65, 0x73, 0x74, - 0x69, 0x6e, 0x67, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +func (m *Empty) XXX_Size() int { + return xxx_messageInfo_Empty.Size(m) +} +func (m *Empty) XXX_DiscardUnknown() { + xxx_messageInfo_Empty.DiscardUnknown(m) } -var ( - file_pkg_server_server_proto_rawDescOnce sync.Once - file_pkg_server_server_proto_rawDescData = file_pkg_server_server_proto_rawDesc -) +var xxx_messageInfo_Empty proto.InternalMessageInfo -func file_pkg_server_server_proto_rawDescGZIP() []byte { - file_pkg_server_server_proto_rawDescOnce.Do(func() { - file_pkg_server_server_proto_rawDescData = protoimpl.X.CompressGZIP(file_pkg_server_server_proto_rawDescData) - }) - return file_pkg_server_server_proto_rawDescData +func init() { + proto.RegisterType((*TestTask)(nil), "server.TestTask") + proto.RegisterMapType((map[string]string)(nil), "server.TestTask.EnvEntry") + proto.RegisterType((*HelloReply)(nil), "server.HelloReply") + proto.RegisterType((*Empty)(nil), "server.Empty") } -var file_pkg_server_server_proto_msgTypes = make([]protoimpl.MessageInfo, 3) -var file_pkg_server_server_proto_goTypes = []interface{}{ - (*TestTask)(nil), // 0: server.TestTask - (*HelloReply)(nil), // 1: server.HelloReply - (*Empty)(nil), // 2: server.Empty -} -var file_pkg_server_server_proto_depIdxs = []int32{ - 0, // 0: server.Runner.Run:input_type -> server.TestTask - 2, // 1: server.Runner.GetVersion:input_type -> server.Empty - 1, // 2: server.Runner.Run:output_type -> server.HelloReply - 1, // 3: server.Runner.GetVersion:output_type -> server.HelloReply - 2, // [2:4] is the sub-list for method output_type - 0, // [0:2] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name +func init() { + proto.RegisterFile("pkg/server/server.proto", fileDescriptor_36fb7b77b8f76c98) } -func init() { file_pkg_server_server_proto_init() } -func file_pkg_server_server_proto_init() { - if File_pkg_server_server_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_pkg_server_server_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*TestTask); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_pkg_server_server_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*HelloReply); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_pkg_server_server_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Empty); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_pkg_server_server_proto_rawDesc, - NumEnums: 0, - NumMessages: 3, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_pkg_server_server_proto_goTypes, - DependencyIndexes: file_pkg_server_server_proto_depIdxs, - MessageInfos: file_pkg_server_server_proto_msgTypes, - }.Build() - File_pkg_server_server_proto = out.File - file_pkg_server_server_proto_rawDesc = nil - file_pkg_server_server_proto_goTypes = nil - file_pkg_server_server_proto_depIdxs = nil +var fileDescriptor_36fb7b77b8f76c98 = []byte{ + // 291 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0x4d, 0x4b, 0xf3, 0x40, + 0x14, 0x85, 0xdf, 0x34, 0x6d, 0x9a, 0xf7, 0x8a, 0x50, 0x2e, 0x82, 0x31, 0xab, 0x92, 0x85, 0x14, + 0xb4, 0x09, 0x56, 0x10, 0x71, 0x29, 0x04, 0x5d, 0xb9, 0x08, 0xc5, 0x85, 0xbb, 0x69, 0x7b, 0x89, + 0x63, 0x92, 0x49, 0x98, 0x8f, 0x60, 0x7e, 0x97, 0x7f, 0x50, 0xf2, 0x65, 0x41, 0x5c, 0xcd, 0x39, + 0x0f, 0xf7, 0xde, 0x33, 0x70, 0xe0, 0xbc, 0xca, 0xd2, 0x48, 0x91, 0xac, 0x49, 0x0e, 0x4f, 0x58, + 0xc9, 0x52, 0x97, 0xe8, 0xf4, 0x2e, 0xf8, 0xb2, 0xc0, 0xdd, 0x92, 0xd2, 0x5b, 0xa6, 0x32, 0x44, + 0x98, 0x1e, 0x98, 0x66, 0x9e, 0xb5, 0xb4, 0x56, 0xff, 0x93, 0x4e, 0xb7, 0x2c, 0xe3, 0xe2, 0xe0, + 0x4d, 0x7a, 0xd6, 0x6a, 0xf4, 0xc1, 0xdd, 0x33, 0x45, 0x2f, 0xac, 0x20, 0xcf, 0xee, 0xf8, 0x8f, + 0xc7, 0x2b, 0xb0, 0x49, 0xd4, 0xde, 0x74, 0x69, 0xaf, 0x4e, 0x36, 0x17, 0xe1, 0x10, 0x3a, 0x46, + 0x84, 0xb1, 0xa8, 0x63, 0xa1, 0x65, 0x93, 0xb4, 0x53, 0xfe, 0x1d, 0xb8, 0x23, 0xc0, 0x05, 0xd8, + 0x19, 0x35, 0x43, 0x76, 0x2b, 0xf1, 0x0c, 0x66, 0x35, 0xcb, 0x0d, 0x0d, 0xd9, 0xbd, 0x79, 0x98, + 0xdc, 0x5b, 0xc1, 0x25, 0xc0, 0x33, 0xe5, 0x79, 0x99, 0x50, 0x95, 0x37, 0xe8, 0xc1, 0xbc, 0x20, + 0xa5, 0x58, 0x4a, 0xc3, 0xf6, 0x68, 0x83, 0x39, 0xcc, 0xe2, 0xa2, 0xd2, 0xcd, 0xe6, 0x03, 0x9c, + 0xc4, 0x08, 0x41, 0x12, 0xd7, 0x60, 0x27, 0x46, 0xe0, 0xe2, 0xf7, 0xcf, 0x7c, 0x1c, 0xc9, 0xf1, + 0x72, 0xf0, 0x0f, 0x6f, 0x00, 0x9e, 0x48, 0xbf, 0x92, 0x54, 0xbc, 0x14, 0x78, 0x3a, 0xce, 0x74, + 0x57, 0xff, 0x5e, 0x79, 0x0c, 0xdf, 0xae, 0x53, 0xae, 0xdf, 0xcd, 0x2e, 0xdc, 0x97, 0x45, 0x94, + 0x73, 0x61, 0x3e, 0x95, 0x91, 0x24, 0x22, 0x56, 0xf1, 0xb5, 0x26, 0xa5, 0xb9, 0x48, 0xa3, 0x63, + 0x2f, 0x3b, 0xa7, 0x6b, 0xe4, 0xf6, 0x3b, 0x00, 0x00, 0xff, 0xff, 0xf9, 0x82, 0x4d, 0xe3, 0xac, + 0x01, 0x00, 0x00, } diff --git a/pkg/server/server.proto b/pkg/server/server.proto index e3a99ee9..a4b66bea 100644 --- a/pkg/server/server.proto +++ b/pkg/server/server.proto @@ -13,6 +13,7 @@ message TestTask { string data = 1; string kind = 2; string caseName = 3; + map env = 4; } message HelloReply {