Skip to content
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

pubsub/pstest: add support to register other servers into the grpc.Server #9198

Open
tpokki opened this issue Dec 26, 2023 · 1 comment · May be fixed by #9722
Open

pubsub/pstest: add support to register other servers into the grpc.Server #9198

tpokki opened this issue Dec 26, 2023 · 1 comment · May be fixed by #9722
Assignees
Labels
api: pubsub Issues related to the Pub/Sub API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@tpokki
Copy link

tpokki commented Dec 26, 2023

Is your feature request related to a problem? Please describe.

I'd like to use GetPolicy() and SetPolicy() in the tests that rely on the pstest.Server. For this, I would need to register my FakeIAMPolicyServer into the grpc.Server instance. Currently the instance is hidden behind unexposed variables.

Describe the solution you'd like

I would like to add new method with callback function to initialise the pstest.Server:

func NewServerWithFakes(port int, registerFakes func(*grpc.Server), opts ...ServerReactorOption) *Server

The existing NewServer and NewServerWithPort would use internally empty callback for backwards compatiblity.

The server registration process would change like this:

	pb.RegisterPublisherServer(srv.Gsrv, &s.GServer)
	pb.RegisterSubscriberServer(srv.Gsrv, &s.GServer)
	pb.RegisterSchemaServiceServer(srv.Gsrv, &s.GServer)

	// register user provided fake servers, such as IAMPolicyServer
	registerFakes(srv.Gsrv)
	srv.Start()

The new method would be used for example like this:

	srv := pstest.NewServerWithFakes(
		0,
		func (gsrv *grpc.Server) {
			// register one or more additional fake server
			iampb.RegisterIAMPolicyServer(gsrv, &FakeIAMPolicyServer{})
		},
	)

Describe alternatives you've considered
The srv in the pstest.Server could be exposed. But then we would need new method that creates new server without calling the srv.Start(). Registering additional fakes is only possible before the Gsrv.Serve() is called.

@tpokki tpokki added the triage me I really want to be triaged. label Dec 26, 2023
@codyoss codyoss added the api: pubsub Issues related to the Pub/Sub API. label Dec 26, 2023
@codyoss codyoss changed the title pstest: add support to register other servers into the grpc.Server pubsub/pstest: add support to register other servers into the grpc.Server Dec 26, 2023
@noahdietz noahdietz added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed triage me I really want to be triaged. labels Jan 8, 2024
@hongalex
Copy link
Member

Sorry this got lost in the triage. I'm amenable to this idea. If you want to send a PR to this, I'd be happy to review this, otherwise I'll get to this when I have cycles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the Pub/Sub API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants