Skip to content
Snippets Groups Projects
Commit 2a0c0154 authored by Pavel Antonov's avatar Pavel Antonov :asterisk:
Browse files

feat: Внесены правки в Spaces после изменений в perxis-proto,...

feat: Внесены правки в Spaces после изменений в perxis-proto, перегенерированны grpc-клиенты для Spaces

Close #PRXS-1835
parents c11dae6a 9f81b2ad
No related branches found
No related tags found
No related merge requests found
Subproject commit 78539871cf2d9f6b187865c4855450143dec4e79 Subproject commit 59b21fcd765d2a6208f65dccdd04a63e55a0016e
...@@ -57,7 +57,7 @@ func IsSpaceAvailable(ctx context.Context, spcs Spaces, spaceId string) error { ...@@ -57,7 +57,7 @@ func IsSpaceAvailable(ctx context.Context, spcs Spaces, spaceId string) error {
return errors.Wrap(err, "space not available") return errors.Wrap(err, "space not available")
} }
if spc.State != StateReady { if spc.StateInfo != nil && spc.StateInfo.State != StateReady {
return errors.New("space not available") return errors.New("space not available")
} }
......
package spaces
import (
"context"
"testing"
)
// dummySpaces используется для имитации поведения Spaces
// Моки использовать не можем, так как получается циклический импорт
type dummySpaces struct {
Spaces
space *Space
}
func (t *dummySpaces) Get(_ context.Context, _ string) (*Space, error) { return t.space, nil }
func TestIsSpaceAvailable(t *testing.T) {
tests := []struct {
name string
space *Space
wantErr bool
}{
{
"Space has nil StateInfo: available",
&Space{ID: "space", OrgID: "org", Name: "test-space"},
false,
},
{
"Space state is StateReady: available",
&Space{ID: "space", OrgID: "org", Name: "test-space", StateInfo: &StateInfo{State: StateReady}},
false,
},
{
"Space state is StatePreparing: not available",
&Space{ID: "space", OrgID: "org", Name: "test-space", StateInfo: &StateInfo{State: StatePreparing}},
true,
},
{
"Space state is StateMigration: not available",
&Space{ID: "space", OrgID: "org", Name: "test-space", StateInfo: &StateInfo{State: StateMigration}},
true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
spaces := &dummySpaces{space: tt.space}
if err := IsSpaceAvailable(context.Background(), spaces, "space"); (err != nil) != tt.wantErr {
t.Errorf("IsSpaceAvailable() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
package spaces package spaces
import "time"
type State int type State int
const ( const (
...@@ -24,13 +26,18 @@ type Space struct { ...@@ -24,13 +26,18 @@ type Space struct {
OrgID string `json:"org_id,omitempty" bson:"org_id"` OrgID string `json:"org_id,omitempty" bson:"org_id"`
Name string `json:"name,omitempty" bson:"name"` Name string `json:"name,omitempty" bson:"name"`
Description string `json:"desc,omitempty" bson:"desc"` Description string `json:"desc,omitempty" bson:"desc"`
State State `json:"state" bson:"state"`
StateInfo string `json:"stateInfo,omitempty" bson:"stateInfo,omitempty"`
// TransferToOrg - идентификатор организации, в которую был запрошен перенос пространства // TransferToOrg - идентификатор организации, в которую был запрошен перенос пространства
TransferToOrg string `json:"transfer_to_org" bson:"transfer_to_org"` TransferToOrg string `json:"transfer_to_org" bson:"transfer_to_org"`
Config *Config `json:"config" bson:"config"` Config *Config `json:"config" bson:"config"`
StateInfo *StateInfo `json:"state_info,omitempty" bson:"state_info,omitempty"`
}
type StateInfo struct {
State State `json:"state" bson:"state"`
Info string `json:"info" bson:"info"`
Time time.Time `json:"time,omitempty" bson:"time,omitempty"`
DBVersion uint32 `json:"db_version" bson:"db_version"`
} }
func (s Space) Clone() *Space { func (s Space) Clone() *Space {
...@@ -48,10 +55,10 @@ func (s Space) Fetch(i interface{}) interface{} { ...@@ -48,10 +55,10 @@ func (s Space) Fetch(i interface{}) interface{} {
return s.Name return s.Name
case "Description": case "Description":
return s.Description return s.Description
case "State":
return s.State
case "Config": case "Config":
return s.Config return s.Config
case "StateInfo":
return s.StateInfo
default: default:
panic("unknown parameter") panic("unknown parameter")
} }
......
...@@ -7,6 +7,7 @@ package transportgrpc ...@@ -7,6 +7,7 @@ package transportgrpc
import ( import (
service "git.perx.ru/perxis/perxis-go/pkg/spaces" service "git.perx.ru/perxis/perxis-go/pkg/spaces"
pb "git.perx.ru/perxis/perxis-go/proto/spaces" pb "git.perx.ru/perxis/perxis-go/proto/spaces"
"google.golang.org/protobuf/types/known/timestamppb"
) )
func PtrConfigToProto(config *service.Config) (*pb.Config, error) { func PtrConfigToProto(config *service.Config) (*pb.Config, error) {
...@@ -18,6 +19,18 @@ func PtrConfigToProto(config *service.Config) (*pb.Config, error) { ...@@ -18,6 +19,18 @@ func PtrConfigToProto(config *service.Config) (*pb.Config, error) {
}, nil }, nil
} }
func PtrStateInfoToProto(stateInfo *service.StateInfo) (*pb.StateInfo, error) {
if stateInfo == nil {
return nil, nil
}
return &pb.StateInfo{
State: pb.State(stateInfo.State),
Info: stateInfo.Info,
DbVersion: int32(stateInfo.DBVersion),
Time: timestamppb.New(stateInfo.Time),
}, nil
}
func ProtoToPtrConfig(protoConfig *pb.Config) (*service.Config, error) { func ProtoToPtrConfig(protoConfig *pb.Config) (*service.Config, error) {
if protoConfig == nil { if protoConfig == nil {
return nil, nil return nil, nil
...@@ -27,17 +40,35 @@ func ProtoToPtrConfig(protoConfig *pb.Config) (*service.Config, error) { ...@@ -27,17 +40,35 @@ func ProtoToPtrConfig(protoConfig *pb.Config) (*service.Config, error) {
}, nil }, nil
} }
func ProtoToPtrStateInfo(protoStateInfo *pb.StateInfo) (*service.StateInfo, error) {
if protoStateInfo == nil {
return nil, nil
}
return &service.StateInfo{
State: service.State(protoStateInfo.State),
Info: protoStateInfo.Info,
Time: protoStateInfo.Time.AsTime(),
DBVersion: uint32(protoStateInfo.DbVersion),
}, nil
}
func PtrSpaceToProto(space *service.Space) (*pb.Space, error) { func PtrSpaceToProto(space *service.Space) (*pb.Space, error) {
if space == nil { if space == nil {
return nil, nil return nil, nil
} }
cfg, _ := PtrConfigToProto(space.Config) cfg, _ := PtrConfigToProto(space.Config)
var state pb.State
if space.StateInfo != nil {
state = pb.State(space.StateInfo.State)
}
stateInfo, _ := PtrStateInfoToProto(space.StateInfo)
return &pb.Space{ return &pb.Space{
Id: space.ID, Id: space.ID,
OrgId: space.OrgID, OrgId: space.OrgID,
Name: space.Name, Name: space.Name,
Description: space.Description, Description: space.Description,
State: pb.State(space.State), State: state,
StateInfo: stateInfo,
Config: cfg, Config: cfg,
TransferToOrg: space.TransferToOrg, TransferToOrg: space.TransferToOrg,
}, nil }, nil
...@@ -48,12 +79,13 @@ func ProtoToPtrSpace(protoSpace *pb.Space) (*service.Space, error) { ...@@ -48,12 +79,13 @@ func ProtoToPtrSpace(protoSpace *pb.Space) (*service.Space, error) {
return nil, nil return nil, nil
} }
cfg, _ := ProtoToPtrConfig(protoSpace.Config) cfg, _ := ProtoToPtrConfig(protoSpace.Config)
state, _ := ProtoToPtrStateInfo(protoSpace.StateInfo)
return &service.Space{ return &service.Space{
ID: protoSpace.Id, ID: protoSpace.Id,
OrgID: protoSpace.OrgId, OrgID: protoSpace.OrgId,
Name: protoSpace.Name, Name: protoSpace.Name,
Description: protoSpace.Description, Description: protoSpace.Description,
State: service.State(protoSpace.State), StateInfo: state,
Config: cfg, Config: cfg,
TransferToOrg: protoSpace.TransferToOrg, TransferToOrg: protoSpace.TransferToOrg,
}, nil }, nil
......
This diff is collapsed.
// Code generated by protoc-gen-go-grpc. DO NOT EDIT. // Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions: // versions:
// - protoc-gen-go-grpc v1.3.0 // - protoc-gen-go-grpc v1.3.0
// - protoc v4.24.3 // - protoc v4.25.1
// source: spaces/spaces.proto // source: spaces/spaces.proto
package spaces package spaces
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment