diff --git a/bin/templates/internal/app/grpc/server_grpc/server_grpc_test.go_ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_test.go_ index b936877..dd48a37 100644 --- a/bin/templates/internal/app/grpc/server_grpc/server_grpc_test.go_ +++ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_test.go_ @@ -3,8 +3,8 @@ package server_grpc import ( "context" "github.com/ManyakRus/starter/config_main" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/api/grpc_proto" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/crud_starter" - "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_proto" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" "testing" ) @@ -41,14 +41,61 @@ func Test_server_LawsuitStatusType_Delete(t *testing.T) { Request.VersionModel = lawsuit_status_types.LawsuitStatusType{}.GetStructVersion() server1 := &ServerGRPC{} - Otvet, err := server1.LawsuitStatusType_Delete(ctx, &Request) + + //прочитаем + Response, err := server1.LawsuitStatusType_Read(ctx, &Request) if err != nil { t.Error("Test_server_LawsuitStatusType_Delete() error: ", err) } - if Otvet.ModelString == "" { + if Response.ModelString == "" { t.Error("Test_server_LawsuitStatusType_Delete() error: ModelString=''") } - Otvet, err = server1.LawsuitStatusType_Restore(ctx, &Request) + + Otvet := &lawsuit_status_types.LawsuitStatusType{} + sModel := Response.ModelString + err = json.Unmarshal([]byte(sModel), Otvet) + if err != nil { + t.Error("Test_server_LawsuitStatusType_Delete() Unmarshal() error: ", err) + } + + if Otvet.IsDeleted == false { + //пометим на удаление + _, err = server1.LawsuitStatusType_Delete(ctx, &Request) + if err != nil { + t.Error("Test_server_LawsuitStatusType_Delete() error: ", err) + } + if Otvet.ID == 0 { + t.Error("Test_server_LawsuitStatusType_Delete() error: ID =0") + } + + //снимем пометку на удаление + _, err = server1.LawsuitStatusType_Restore(ctx, &Request) + if err != nil { + t.Error("Test_server_LawsuitStatusType_Delete() error: ", err) + } + if Otvet.ID == 0 { + t.Error("Test_server_LawsuitStatusType_Delete() error: ID =0") + } + } else { + //снимем пометку на удаление + _, err = server1.LawsuitStatusType_Restore(ctx, &Request) + if err != nil { + t.Error("Test_server_LawsuitStatusType_Delete() error: ", err) + } + if Otvet.ID == 0 { + t.Error("Test_server_LawsuitStatusType_Delete() error: ID =0") + } + + //пометим на удаление + _, err = server1.LawsuitStatusType_Delete(ctx, &Request) + if err != nil { + t.Error("Test_server_LawsuitStatusType_Delete() error: ", err) + } + if Otvet.ID == 0 { + t.Error("Test_server_LawsuitStatusType_Delete() error: ID =0") + } + } + } func Test_server_LawsuitStatusType_Create(t *testing.T) { @@ -148,45 +195,3 @@ func Test_server_LawsuitStatusType_Save(t *testing.T) { } } - -func Test_server_LawsuitStatusType_FindByExtID(t *testing.T) { - config_main.LoadEnv() - crud_starter.InitCrudTransport_DB() - - ctx := context.Background() - Request := grpc_proto.RequestId{} - Request.ID = LawsuitStatusType_ID_Test - Request.VersionModel = lawsuit_status_types.LawsuitStatusType{}.GetStructVersion() - - server1 := &ServerGRPC{} - Otvet1, err := server1.LawsuitStatusType_Read(ctx, &Request) - if err != nil { - t.Error("Test_server_LawsuitStatusType_FindByExtID() error: ", err) - } - - // получим модель из строки JSON - Model := lawsuit_status_types.LawsuitStatusType{} - err = Model.GetModelFromJSON(Otvet1.ModelString) - if err != nil { - t.Error("Test_server_LawsuitStatusType_FindByExtID() GetModelFromJSON() error: ", err) - } - - if Model.ExtID == 0 { - return - } - - - ctx = context.Background() - RequestExtID:= grpc_proto.RequestExtID{} - RequestExtID.ExtID = Model.ExtID - RequestExtID.ConnectionId = Model.ConnectionID - RequestExtID.VersionModel = lawsuit_status_types.LawsuitStatusType{}.GetStructVersion() - - Otvet, err := server1.LawsuitStatusType_FindByExtID(ctx, &RequestExtID) - if err != nil { - t.Error("Test_server_LawsuitStatusType_FindByExtID() error: ", err) - } - if Otvet.ModelString == "" { - t.Error("Test_server_LawsuitStatusType_FindByExtID() error: ModelString=''") - } -} diff --git a/internal/create_files/create_files.go b/internal/create_files/create_files.go index 98ff0a2..b18cd8a 100644 --- a/internal/create_files/create_files.go +++ b/internal/create_files/create_files.go @@ -555,6 +555,22 @@ func AddImport(Text, URL string) string { return Otvet } +// CheckAndAddImport - добавляет URL в секцию Import, если его там нет, если он нужен +func CheckAndAddImport(Text, URL string) string { + Otvet := Text + + //проверим используется или нет + ModuleName := micro.LastWord(URL) + pos1 := strings.Index(Otvet, ModuleName+".") + if pos1 < 0 { + return Otvet + } + + Otvet = AddImport(Text, URL) + + return Otvet +} + // AddImportTime - добавляет покет в секцию Import, если его там нет func AddImportTime(TextModel string) string { Otvet := TextModel diff --git a/internal/create_files/grpc_server_tables/grpc_server_tables.go b/internal/create_files/grpc_server_tables/grpc_server_tables.go index 1959d80..147784f 100644 --- a/internal/create_files/grpc_server_tables/grpc_server_tables.go +++ b/internal/create_files/grpc_server_tables/grpc_server_tables.go @@ -169,6 +169,12 @@ func CreateTestFiles(Table1 *types.Table) error { //заменим импорты if config.Settings.USE_DEFAULT_TEMPLATE == true { + //удалим лишние функции + TextGRPCServer = DeleteFuncTestDelete(TextGRPCServer, Table1) + TextGRPCServer = DeleteFuncTestRestore(TextGRPCServer, Table1) + TextGRPCServer = DeleteFuncTestFind_byExtID(TextGRPCServer, Table1) + + //добавим импорты TextGRPCServer = create_files.DeleteTemplateRepositoryImports(TextGRPCServer) ModelTableURL := create_files.FindModelTableURL(TableName) @@ -180,10 +186,7 @@ func CreateTestFiles(Table1 *types.Table) error { CrudStarterURL := create_files.FindCrudStarterURL() TextGRPCServer = create_files.AddImport(TextGRPCServer, CrudStarterURL) - //удалим лишние функции - TextGRPCServer = DeleteFuncTestDelete(TextGRPCServer, Table1) - TextGRPCServer = DeleteFuncTestRestore(TextGRPCServer, Table1) - TextGRPCServer = DeleteFuncTestFind_byExtID(TextGRPCServer, Table1) + TextGRPCServer = create_files.CheckAndAddImport(TextGRPCServer, "encoding/json") } //создание текста