-
Notifications
You must be signed in to change notification settings - Fork 1
[gRPCServerTest] gRPS server implemented #24
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
base: master
Are you sure you want to change the base?
Changes from all commits
c067a48
19d0169
e10cfaf
b162be1
6650048
540ca0c
0a8017d
1b800fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Certificates service | ||
| === | ||
|
|
||
| ### Запуск сервиса: | ||
| *"cmd/rpc/main.go"* | ||
|
|
||
| ### Перед запуском необходимо: | ||
| Задать переменные окружения - **"TEMPLATES_DIR"**, **"CERTIFICATES_DIR"**, с путями хранения файлов шаблонов и сертификатов. | ||
| В системе должна быть установлена **"wkhtmltopdf"**, программа конвертации **HTML** файлов в **PDF**: https://wkhtmltopdf.org/downloads.html | ||
| Исполняемый файл **"wkhtmltopdf"** должен находиться в каталоге запуска сервиса, или быть доступным по путям из переменной окружения **"PATH"**. | ||
| Сгенерировать из **".proto"** вспомогательные файлы **gRPC**: *"protoc @protoc_options_generate.txt"* | ||
|
|
||
| ### Требования к шаблонам: | ||
| В шаблоне могут содержаться следующие теги замены: | ||
| ``` | ||
| {{.CourseName}} | ||
| {{.CourseType}} | ||
| {{.CourseHours}} | ||
| {{.CourseDate}} | ||
| {{.CourseMentors}} | ||
| {{.StudentFirstname}} | ||
| {{.StudentLastname}} | ||
| {{.QrCodeLink}} | ||
| ``` | ||
| Шаблоны с любыми другими тегами замены будут отклонены валидатором. | ||
| Вместо тега замены `{{.QrCodeLink}}` будет вставлен **QR** код в формате **PNG**: ссылка на сертификат. | ||
| Например: `"<img src={{.QrCodeLink}} width="128" height="128">"` | ||
|
|
||
| ### Пример простого HTML шаблона: | ||
| ``` | ||
| <html><body><h1 style="color:red;">Test html color<h1><p>{{.CourseName}}</p><p>{{.CourseType}}</p><p>{{.CourseHours}}</p><p>{{.CourseDate}}</p><p>{{.CourseMentors}}</p><p>{{.StudentFirstname}}</p><p>{{.StudentLastname}}</p><p><img src={{.QrCodeLink}} width="128" height="128"></p></body></html> | ||
| ``` |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package certificate; | ||
|
|
||
| option go_package = "gus_certificates/protobuf/transport/certificate;certificate"; | ||
|
|
||
| import "google/protobuf/empty.proto"; | ||
|
|
||
| service Certificate { | ||
| rpc IssueCertificate(IssueCertificateReq) returns (IssueCertificateResp); | ||
| rpc GetCertificateFileByID(GetCertificateFileByIDReq) returns (GetCertificateFileByIDResp); | ||
| rpc GetCertificateLinkByID(GetCertificateLinkByIDReq) returns (GetCertificateLinkByIDResp); | ||
| rpc AddTemplate(AddTemplateReq) returns (AddTemplateResp); | ||
| rpc DelTemplate(DelTemplateReq) returns (DelTemplateResp); | ||
| } | ||
|
|
||
| message IssueCertificateReq { | ||
| StudentMessage student = 1; | ||
| string template_name = 2; | ||
| CourseMessage course = 3; | ||
| } | ||
|
|
||
| message IssueCertificateResp { | ||
| string id = 1; | ||
| } | ||
|
|
||
| message GetCertificateFileByIDReq { | ||
| string id = 1; | ||
| } | ||
|
|
||
| message GetCertificateLinkByIDReq { | ||
| string id = 1; | ||
| } | ||
|
|
||
| message GetCertificateFileByIDResp { | ||
| bytes certificate = 1; | ||
| } | ||
|
|
||
| message GetCertificateLinkByIDResp { | ||
| string link = 1; | ||
| } | ||
|
|
||
| message AddTemplateReq { | ||
| string template_name = 1; | ||
| bytes template = 2; | ||
| } | ||
|
|
||
| message DelTemplateReq { | ||
| string template_name = 1; | ||
| } | ||
|
|
||
| message AddTemplateResp { | ||
| Status status = 1; | ||
| } | ||
|
|
||
| message DelTemplateResp { | ||
| Status status = 1; | ||
| } | ||
|
|
||
| message StudentMessage { | ||
| string firstname = 1; | ||
| string lastname = 2; | ||
| } | ||
|
|
||
| message CourseMessage { | ||
| string course_name = 1; | ||
| string course_type = 2; | ||
| string hours = 3; | ||
| string date = 4; | ||
| repeated string mentors = 5; | ||
| } | ||
|
|
||
| message Status { | ||
| int32 code = 1; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,22 +7,24 @@ import ( | |
| ) | ||
|
|
||
| var testData = struct { | ||
| certGenerator CertGenerator | ||
| certGenerator *CertGenerator | ||
| goodTemplate []byte | ||
| failTemplate []byte | ||
| expected []byte | ||
| expectedCert []byte | ||
| expectedId string | ||
| }{ | ||
| certGenerator: CertGenerator{}, | ||
| certGenerator: &CertGenerator{}, | ||
| goodTemplate: []byte(`<html><body><h1 style="color:red;">Test html color<h1> | ||
| <p>{{.CourseName}}</p><p>{{.CourseType}}</p><p>{{.CourseHours}}</p><p>{{.CourseDate}}</p> | ||
| <p>{{.CourseMentors}}</p><p>{{.StudentFirstname}}</p><p>{{.StudentLastname}}</p> | ||
| </body></html>`), | ||
| failTemplate: []byte(`<html><body><h1 style="color:red;">Test html color<h1> | ||
| <p>{{.CourseName_Fail}}</p></body></html>`), | ||
| expected: []byte(`<html><body><h1 style="color:red;">Test html color<h1> | ||
| expectedCert: []byte(`<html><body><h1 style="color:red;">Test html color<h1> | ||
| <p>Golang</p><p>Theory</p><p>35</p><p>25.01.2023</p> | ||
| <p>Pavel Gordiyanov, Mikita Viarbovikau, Sergey Shtripling</p><p>Ivan</p><p>Ivanov</p> | ||
| </body></html>`), | ||
| expectedId: "612364afe471b3b1cc80083183fd381d", | ||
| } | ||
|
|
||
| func TestMain(m *testing.M) { | ||
|
|
@@ -52,7 +54,32 @@ func TestGenerateCertificate(t *testing.T) { | |
| t.Error(err) | ||
| } | ||
|
|
||
| if !reflect.DeepEqual(gotCertif, testData.expected) { | ||
| if !reflect.DeepEqual(gotCertif, testData.expectedCert) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Опять же - лучше использовать какой-либо testify. Но это нужно было сделать раньше, сейчас можно отдельную таску.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. переделать все тесты под testify? |
||
| t.Errorf("%q and %q should be equal", "gotSertif", "expectedCert") | ||
| } | ||
| } | ||
|
|
||
| func TestGenerateID(t *testing.T) { | ||
| generator := testData.certGenerator | ||
|
|
||
| actualId := generator.GenerateID() | ||
| if actualId != testData.expectedId { | ||
| t.Errorf("expected:%q, actual:%q", testData.expectedId, actualId) | ||
| } | ||
| } | ||
|
|
||
| func TestCheckTemplateHTML_fail(t *testing.T) { | ||
| generator := testData.certGenerator | ||
| err := generator.CheckTemplateHTML(testData.failTemplate) | ||
| if err == nil { | ||
| t.Error("err must not be nil") | ||
| } | ||
| } | ||
|
|
||
| func TestCheckTemplateHTML(t *testing.T) { | ||
| generator := testData.certGenerator | ||
| err := generator.CheckTemplateHTML(testData.goodTemplate) | ||
| if err != nil { | ||
| t.Error(err) | ||
| } | ||
| } | ||
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Что-то не обратил внимания раньше. Тут по-хорошему должен быть failObject
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тут не понял. Почему должен failObject? Наоборот expectedCert это образец сертификата который должен сгенерироваться.