Skip to content
Snippets Groups Projects
Commit 1e7713ef authored by OZGCloud's avatar OZGCloud
Browse files

OZG-6676 proxy adaption

parent a05c6a3d
Branches
Tags
No related merge requests found
......@@ -30,14 +30,6 @@ package de.ozgcloud.fachstellenproxy;
option go_package = "de.ozgcloud.fachstellenproxy";
message GrpcFachstelleRegistrationRequest {
GrpcFachstelle fachstelle = 1;
}
message GrpcFachstelleRegistrationResponse {
}
message GrpcFachstelle {
string mukId = 1;
string firmenName = 2;
string rechtsform = 3;
......@@ -47,3 +39,7 @@ message GrpcFachstelle {
string emailAdresse = 7;
string anschrift = 8;
}
message GrpcFachstelleRegistrationResponse {
}
\ No newline at end of file
......@@ -49,16 +49,16 @@ type registrationServer struct {
}
func (s *registrationServer) Register(_ context.Context, in *pb.GrpcFachstelleRegistrationRequest) (*pb.GrpcFachstelleRegistrationResponse, error) {
if in.Fachstelle == nil {
return nil, status.Error(codes.InvalidArgument, "fachstelle is missing")
if in.MukId == "" {
return nil, status.Error(codes.InvalidArgument, "mukId is missing")
}
if in.Fachstelle.MukId == "conflictMukId" {
return nil, status.Error(codes.AlreadyExists, "conflict MukId")
} else if in.Fachstelle.MukId == "unavailableMukId" {
return nil, status.Error(codes.Unavailable, "unavailable MukId")
} else if in.Fachstelle.MukId == "erroneousMukId" {
return nil, status.Error(codes.Internal, "erroneous MukId")
if in.MukId == "conflictMukId" {
return nil, status.Error(codes.AlreadyExists, "conflict mukId")
} else if in.MukId == "unavailableMukId" {
return nil, status.Error(codes.Unavailable, "unavailable mukId")
} else if in.MukId == "erroneousMukId" {
return nil, status.Error(codes.Internal, "erroneous mukId")
}
return &pb.GrpcFachstelleRegistrationResponse{}, nil
......
......@@ -67,7 +67,7 @@ func TestStartGrpcServer(t *testing.T) {
client, cleanUp := setUpGrpcEnv()
defer cleanUp()
resp, err := client.Register(context.Background(), &pb.GrpcFachstelleRegistrationRequest{Fachstelle: &pb.GrpcFachstelle{MukId: "testMukId"}})
resp, err := client.Register(context.Background(), &pb.GrpcFachstelleRegistrationRequest{MukId: "testMukId"})
assert.NoError(t, err)
assert.NotNil(t, resp)
......
......@@ -46,7 +46,7 @@ func TestRegisterFachstelleRegistrationEndpoints(t *testing.T) {
mock.SetUpGrpcServer()
SetUpHttpGateway()
jsonData := []byte(`{"fachstelle": {"mukId": "testMukId"}}`)
jsonData := []byte(`{"mukId": "testMukId"}`)
resp, err := http.Post("http://localhost:8080/api/fachstellen", "application/json", bytes.NewBuffer(jsonData))
assert.NoError(t, err)
......@@ -102,19 +102,19 @@ func TestErrorHandler(t *testing.T) {
})
t.Run("should have conflict error", func(t *testing.T) {
jsonData := []byte(`{"fachstelle": {"mukId": "conflictMukId"}}`)
jsonData := []byte(`{"mukId": "conflictMukId"}`)
assertErroneousRequest(jsonData, http.StatusConflict)
})
t.Run("should have unavailable error", func(t *testing.T) {
jsonData := []byte(`{"fachstelle": {"mukId": "unavailableMukId"}}`)
jsonData := []byte(`{"mukId": "unavailableMukId"}`)
assertErroneousRequest(jsonData, http.StatusServiceUnavailable)
})
t.Run("should have internal server error", func(t *testing.T) {
jsonData := []byte(`{"fachstelle": {"mukId": "erroneousMukId"}}`)
jsonData := []byte(`{"mukId": "erroneousMukId"}`)
assertErroneousRequest(jsonData, http.StatusInternalServerError)
})
......
......@@ -47,12 +47,12 @@ func TestRequestLoggingMiddleware(t *testing.T) {
logger.BaseLogger.SetFlags(originalFlags)
}()
jsonData := []byte(`{"fachstelle": {"mukId": "testMukId"}}`)
jsonData := []byte(`{"mukId": "testMukId"}`)
http.Post("http://localhost:8080/api/fachstellen", "application/json", bytes.NewBuffer(jsonData))
logOutput := buf.String()
assert.Contains(t, logOutput, "received POST request for /api/fachstellen with body: {\"fachstelle\": {\"mukId\": \"testMukId\"}}")
assert.Contains(t, logOutput, "successfully handled POST request for /api/fachstellen with body: {\"fachstelle\": {\"mukId\": \"testMukId\"}}")
assert.Contains(t, logOutput, "received POST request for /api/fachstellen with body: {\"mukId\": \"testMukId\"}")
assert.Contains(t, logOutput, "successfully handled POST request for /api/fachstellen with body: {\"mukId\": \"testMukId\"}")
})
t.Run("should not log request", func(t *testing.T) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment