From 7a2507fc52c1d4e54ef7b57b545ef50b57806fea Mon Sep 17 00:00:00 2001 From: justinsb Date: Wed, 28 Feb 2024 22:25:01 -0500 Subject: [PATCH] mockgcp: serve multiple hosts, including variables --- mockgcp/mock_http_roundtrip.go | 64 +++++++++++++++---- mockgcp/mockaiplatform/service.go | 5 +- mockgcp/mockalloydb/service.go | 4 +- mockgcp/mockapikeys/service.go | 4 +- mockgcp/mockartifactregistry/service.go | 4 +- mockgcp/mockbigquery/service.go | 4 +- mockgcp/mockbigqueryconnection/service.go | 4 +- mockgcp/mockbigtable/service.go | 4 +- mockgcp/mockbilling/service.go | 4 +- mockgcp/mockcertificatemanager/service.go | 4 +- mockgcp/mockcloudbuild/service.go | 4 +- mockgcp/mockcloudfunctions/service.go | 4 +- mockgcp/mockcloudids/service.go | 4 +- mockgcp/mockcompute/service.go | 4 +- mockgcp/mockcontainer/service.go | 4 +- mockgcp/mockcontaineranalysis/service.go | 4 +- mockgcp/mockdataform/service.go | 4 +- mockgcp/mockedgecontainer/service.go | 4 +- mockgcp/mockedgenetwork/service.go | 4 +- mockgcp/mockgkehub/service.go | 4 +- mockgcp/mockgkemulticloud/service.go | 4 +- mockgcp/mockiam/service.go | 4 +- mockgcp/mockkms/service.go | 4 +- mockgcp/mocklogging/service.go | 4 +- mockgcp/mockmonitoring/service.go | 4 +- mockgcp/mocknetworkconnectivity/service.go | 4 +- mockgcp/mocknetworkservices/service.go | 4 +- mockgcp/mockprivateca/service.go | 4 +- .../mockprivilegedaccessmanager/service.go | 4 +- mockgcp/mockpubsub/service.go | 4 +- mockgcp/mockpubsublite/service.go | 5 +- mockgcp/mockredis/service.go | 4 +- mockgcp/mockresourcemanager/service.go | 4 +- mockgcp/mocksecretmanager/service.go | 4 +- mockgcp/mockservicenetworking/service.go | 4 +- mockgcp/mockserviceusage/service.go | 4 +- mockgcp/mockspanner/admin/service.go | 4 +- mockgcp/mocksql/service.go | 4 +- mockgcp/mockstorage/service.go | 4 +- 39 files changed, 128 insertions(+), 90 deletions(-) diff --git a/mockgcp/mock_http_roundtrip.go b/mockgcp/mock_http_roundtrip.go index d26ef9ba97..c5a13e2b61 100644 --- a/mockgcp/mock_http_roundtrip.go +++ b/mockgcp/mock_http_roundtrip.go @@ -23,6 +23,7 @@ import ( "log" "net" "net/http" + "regexp" "strings" "testing" @@ -78,11 +79,24 @@ type mockRoundTripper struct { grpcConnection *grpc.ClientConn grpcListener net.Listener - hosts map[string]http.Handler - iamPolicies *mockIAMPolicies - services []MockService + services []registeredService +} + +type registeredService struct { + hostRegexes []*regexp.Regexp + handler http.Handler + impl MockService +} + +func (h *registeredService) MatchesHost(host string) (http.Handler, bool) { + for _, hostRegex := range h.hostRegexes { + if hostRegex.MatchString(host) { + return h.handler, true + } + } + return nil, false } // MockService is the interface implemented by all services @@ -93,8 +107,9 @@ type MockService interface { // NewHTTPMux creates an HTTP mux for serving http traffic NewHTTPMux(ctx context.Context, conn *grpc.ClientConn) (http.Handler, error) - // ExpectedHost is the hostname we serve on e.g. foo.googleapis.com - ExpectedHost() string + // ExpectedHosts is the hostname(s) we serve on e.g. foo.googleapis.com + // We also support patterns like `{region}-foo.googleapis.com` + ExpectedHosts() []string } type Interface interface { @@ -137,8 +152,6 @@ func NewMockRoundTripper(t *testing.T, k8sClient client.Client, storage storage. var serverOpts []grpc.ServerOption server := grpc.NewServer(serverOpts...) - mockRoundTripper.hosts = make(map[string]http.Handler) - var services []MockService services = append(services, resourcemanagerService) @@ -179,7 +192,6 @@ func NewMockRoundTripper(t *testing.T, k8sClient client.Client, storage storage. services = append(services, mockcontaineranalysis.New(env, storage)) services = append(services, mockdataform.New(env, storage)) services = append(services, mockbigqueryconnection.New(env, storage)) - mockRoundTripper.services = services for _, service := range services { service.Register(server) @@ -216,7 +228,15 @@ func NewMockRoundTripper(t *testing.T, k8sClient client.Client, storage storage. if err != nil { t.Fatalf("error building mux: %v", err) } - mockRoundTripper.hosts[service.ExpectedHost()] = mux + var hostRegexes []*regexp.Regexp + for _, host := range service.ExpectedHosts() { + hostRegexes = append(hostRegexes, toHostRegex(host)) + } + mockRoundTripper.services = append(mockRoundTripper.services, registeredService{ + impl: service, + hostRegexes: hostRegexes, + handler: mux, + }) } mockRoundTripper.iamPolicies = newMockIAMPolicies() @@ -226,11 +246,11 @@ func NewMockRoundTripper(t *testing.T, k8sClient client.Client, storage storage. func (m *mockRoundTripper) RunTestCommand(ctx context.Context, serviceName string, command string) error { for _, service := range m.services { - if service.ExpectedHost() != serviceName { + if _, match := service.MatchesHost(serviceName); !match { continue } - supportsTestCommands, ok := service.(SupportsTestCommands) + supportsTestCommands, ok := service.impl.(SupportsTestCommands) if !ok { return fmt.Errorf("service %T does not support test commands", service) } @@ -251,6 +271,19 @@ func (m *mockRoundTripper) NewGRPCConnection(ctx context.Context) *grpc.ClientCo return conn } +func toHostRegex(host string) *regexp.Regexp { + r := regexp.MustCompile(`{[^}]+}`) + + tokens := strings.Split(host, ".") + for i, token := range tokens { + token = r.ReplaceAllStringFunc(token, func(match string) string { + return "[^.]*" + }) + tokens[i] = token + } + return regexp.MustCompile("^" + strings.Join(tokens, `\.`) + "$") +} + func (m *mockRoundTripper) prefilterRequest(req *http.Request) error { if req.Body != nil { var requestBody bytes.Buffer @@ -389,7 +422,14 @@ func (m *mockRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) return m.roundTripIAMPolicy(req) } - mux := m.hosts[req.Host] + var mux http.Handler + for _, service := range m.services { + m, found := service.MatchesHost(req.Host) + if found { + mux = m + break + } + } if mux != nil { if err := m.prefilterRequest(req); err != nil { return nil, err diff --git a/mockgcp/mockaiplatform/service.go b/mockgcp/mockaiplatform/service.go index 967f39f2f7..c16038d67e 100644 --- a/mockgcp/mockaiplatform/service.go +++ b/mockgcp/mockaiplatform/service.go @@ -46,9 +46,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - // TODO: Support more endpoints - return "us-central1-aiplatform.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"{region}-aiplatform.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockalloydb/service.go b/mockgcp/mockalloydb/service.go index aeddee3543..5ba963e149 100644 --- a/mockgcp/mockalloydb/service.go +++ b/mockgcp/mockalloydb/service.go @@ -46,8 +46,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "alloydb.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"alloydb.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockapikeys/service.go b/mockgcp/mockapikeys/service.go index 3a32dc45a5..cfdb196351 100644 --- a/mockgcp/mockapikeys/service.go +++ b/mockgcp/mockapikeys/service.go @@ -48,8 +48,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "apikeys.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"apikeys.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockartifactregistry/service.go b/mockgcp/mockartifactregistry/service.go index 1ba6b51785..2ee9d35b08 100644 --- a/mockgcp/mockartifactregistry/service.go +++ b/mockgcp/mockartifactregistry/service.go @@ -46,8 +46,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "artifactregistry.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"artifactregistry.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockbigquery/service.go b/mockgcp/mockbigquery/service.go index a4b5706a89..09625a154b 100644 --- a/mockgcp/mockbigquery/service.go +++ b/mockgcp/mockbigquery/service.go @@ -46,8 +46,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "bigquery.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"bigquery.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockbigqueryconnection/service.go b/mockgcp/mockbigqueryconnection/service.go index 2c9cb5e25e..ff5550a03f 100644 --- a/mockgcp/mockbigqueryconnection/service.go +++ b/mockgcp/mockbigqueryconnection/service.go @@ -45,8 +45,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "bigqueryconnection.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"bigqueryconnection.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockbigtable/service.go b/mockgcp/mockbigtable/service.go index 0f53b15632..8ec177ed6f 100644 --- a/mockgcp/mockbigtable/service.go +++ b/mockgcp/mockbigtable/service.go @@ -50,8 +50,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "bigtableadmin.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"bigtableadmin.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockbilling/service.go b/mockgcp/mockbilling/service.go index 2bfefd4cc8..f756a49264 100644 --- a/mockgcp/mockbilling/service.go +++ b/mockgcp/mockbilling/service.go @@ -48,8 +48,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "cloudbilling.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"cloudbilling.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockcertificatemanager/service.go b/mockgcp/mockcertificatemanager/service.go index a26bdaefe8..a082fc9a91 100644 --- a/mockgcp/mockcertificatemanager/service.go +++ b/mockgcp/mockcertificatemanager/service.go @@ -48,8 +48,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "certificatemanager.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"certificatemanager.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockcloudbuild/service.go b/mockgcp/mockcloudbuild/service.go index b185266b57..58933b8934 100644 --- a/mockgcp/mockcloudbuild/service.go +++ b/mockgcp/mockcloudbuild/service.go @@ -47,8 +47,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "cloudbuild.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"cloudbuild.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockcloudfunctions/service.go b/mockgcp/mockcloudfunctions/service.go index b8890bd5d1..3471ac2a32 100644 --- a/mockgcp/mockcloudfunctions/service.go +++ b/mockgcp/mockcloudfunctions/service.go @@ -48,8 +48,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "cloudfunctions.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"cloudfunctions.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockcloudids/service.go b/mockgcp/mockcloudids/service.go index c4ab560430..e5a6495283 100644 --- a/mockgcp/mockcloudids/service.go +++ b/mockgcp/mockcloudids/service.go @@ -47,8 +47,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "ids.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"ids.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockcompute/service.go b/mockgcp/mockcompute/service.go index 9172bfa81c..a85ff9cab5 100644 --- a/mockgcp/mockcompute/service.go +++ b/mockgcp/mockcompute/service.go @@ -45,8 +45,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "compute.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"compute.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockcontainer/service.go b/mockgcp/mockcontainer/service.go index 0904c3cbee..8aed586c04 100644 --- a/mockgcp/mockcontainer/service.go +++ b/mockgcp/mockcontainer/service.go @@ -41,8 +41,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "container.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"container.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockcontaineranalysis/service.go b/mockgcp/mockcontaineranalysis/service.go index 613660595d..33f4ee5007 100644 --- a/mockgcp/mockcontaineranalysis/service.go +++ b/mockgcp/mockcontaineranalysis/service.go @@ -46,8 +46,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "containeranalysis.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"containeranalysis.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockdataform/service.go b/mockgcp/mockdataform/service.go index 2e7fa94947..14947bd12e 100644 --- a/mockgcp/mockdataform/service.go +++ b/mockgcp/mockdataform/service.go @@ -48,8 +48,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "dataform.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"dataform.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockedgecontainer/service.go b/mockgcp/mockedgecontainer/service.go index 30507daade..406e2e7e89 100644 --- a/mockgcp/mockedgecontainer/service.go +++ b/mockgcp/mockedgecontainer/service.go @@ -53,8 +53,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "edgecontainer.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"edgecontainer.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockedgenetwork/service.go b/mockgcp/mockedgenetwork/service.go index be2f2c6750..623e7fecfb 100644 --- a/mockgcp/mockedgenetwork/service.go +++ b/mockgcp/mockedgenetwork/service.go @@ -53,8 +53,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "edgenetwork.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"edgenetwork.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockgkehub/service.go b/mockgcp/mockgkehub/service.go index dd39f165b1..b6749fb029 100644 --- a/mockgcp/mockgkehub/service.go +++ b/mockgcp/mockgkehub/service.go @@ -51,8 +51,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "gkehub.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"gkehub.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockgkemulticloud/service.go b/mockgcp/mockgkemulticloud/service.go index 20cc018756..958bac10fc 100644 --- a/mockgcp/mockgkemulticloud/service.go +++ b/mockgcp/mockgkemulticloud/service.go @@ -48,8 +48,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "us-west1-gkemulticloud.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"{region}-gkemulticloud.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockiam/service.go b/mockgcp/mockiam/service.go index d68b08f683..b30c05b0da 100644 --- a/mockgcp/mockiam/service.go +++ b/mockgcp/mockiam/service.go @@ -49,8 +49,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "iam.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"iam.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockkms/service.go b/mockgcp/mockkms/service.go index 7ff2f3567f..720158f3ca 100644 --- a/mockgcp/mockkms/service.go +++ b/mockgcp/mockkms/service.go @@ -44,8 +44,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "cloudkms.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"cloudkms.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mocklogging/service.go b/mockgcp/mocklogging/service.go index 4567d6937e..2de5b45232 100644 --- a/mockgcp/mocklogging/service.go +++ b/mockgcp/mocklogging/service.go @@ -44,8 +44,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "logging.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"logging.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockmonitoring/service.go b/mockgcp/mockmonitoring/service.go index 1843e46221..037ea7a0d2 100644 --- a/mockgcp/mockmonitoring/service.go +++ b/mockgcp/mockmonitoring/service.go @@ -45,8 +45,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "monitoring.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"monitoring.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mocknetworkconnectivity/service.go b/mockgcp/mocknetworkconnectivity/service.go index 70e72125ec..0440a1e845 100644 --- a/mockgcp/mocknetworkconnectivity/service.go +++ b/mockgcp/mocknetworkconnectivity/service.go @@ -44,8 +44,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "networkconnectivity.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"networkconnectivity.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mocknetworkservices/service.go b/mockgcp/mocknetworkservices/service.go index 826803de94..8d077e9035 100644 --- a/mockgcp/mocknetworkservices/service.go +++ b/mockgcp/mocknetworkservices/service.go @@ -48,8 +48,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "networkservices.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"networkservices.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockprivateca/service.go b/mockgcp/mockprivateca/service.go index e3edb127d0..96a34cea62 100644 --- a/mockgcp/mockprivateca/service.go +++ b/mockgcp/mockprivateca/service.go @@ -45,8 +45,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "privateca.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"privateca.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockprivilegedaccessmanager/service.go b/mockgcp/mockprivilegedaccessmanager/service.go index 1c2743068e..0fabf04f3d 100644 --- a/mockgcp/mockprivilegedaccessmanager/service.go +++ b/mockgcp/mockprivilegedaccessmanager/service.go @@ -48,8 +48,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "privilegedaccessmanger.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"privilegedaccessmanger.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockpubsub/service.go b/mockgcp/mockpubsub/service.go index d64af357ea..e006a0fe97 100644 --- a/mockgcp/mockpubsub/service.go +++ b/mockgcp/mockpubsub/service.go @@ -44,8 +44,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "pubsub.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"pubsub.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockpubsublite/service.go b/mockgcp/mockpubsublite/service.go index f183dbeca8..4172a680c8 100644 --- a/mockgcp/mockpubsublite/service.go +++ b/mockgcp/mockpubsublite/service.go @@ -53,9 +53,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - // TODO: Other regions - return "us-central1-pubsublite.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"{region}-pubsublite.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockredis/service.go b/mockgcp/mockredis/service.go index e3dd4d791e..2d5090f139 100644 --- a/mockgcp/mockredis/service.go +++ b/mockgcp/mockredis/service.go @@ -44,8 +44,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "redis.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"redis.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockresourcemanager/service.go b/mockgcp/mockresourcemanager/service.go index 97b76370a9..3dc641684f 100644 --- a/mockgcp/mockresourcemanager/service.go +++ b/mockgcp/mockresourcemanager/service.go @@ -58,8 +58,8 @@ func (s *MockService) GetProjectStore() projects.ProjectStore { return s.projectsInternal } -func (s *MockService) ExpectedHost() string { - return "cloudresourcemanager.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"cloudresourcemanager.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mocksecretmanager/service.go b/mockgcp/mocksecretmanager/service.go index ac4df7ff1d..22cc586c59 100644 --- a/mockgcp/mocksecretmanager/service.go +++ b/mockgcp/mocksecretmanager/service.go @@ -44,8 +44,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "secretmanager.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"secretmanager.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockservicenetworking/service.go b/mockgcp/mockservicenetworking/service.go index f021478247..d904673eea 100644 --- a/mockgcp/mockservicenetworking/service.go +++ b/mockgcp/mockservicenetworking/service.go @@ -45,8 +45,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "servicenetworking.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"servicenetworking.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockserviceusage/service.go b/mockgcp/mockserviceusage/service.go index 64cd60a3a8..38ced6c9ea 100644 --- a/mockgcp/mockserviceusage/service.go +++ b/mockgcp/mockserviceusage/service.go @@ -51,8 +51,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "serviceusage.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"serviceusage.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockspanner/admin/service.go b/mockgcp/mockspanner/admin/service.go index f5f7ba4e3a..e5f4a1e5b0 100644 --- a/mockgcp/mockspanner/admin/service.go +++ b/mockgcp/mockspanner/admin/service.go @@ -51,8 +51,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "spanner.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"spanner.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mocksql/service.go b/mockgcp/mocksql/service.go index c965b33f39..dd33e71f4b 100644 --- a/mockgcp/mocksql/service.go +++ b/mockgcp/mocksql/service.go @@ -51,8 +51,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "sqladmin.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"sqladmin.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) { diff --git a/mockgcp/mockstorage/service.go b/mockgcp/mockstorage/service.go index 2328437a7d..50fd4295c3 100644 --- a/mockgcp/mockstorage/service.go +++ b/mockgcp/mockstorage/service.go @@ -45,8 +45,8 @@ func New(env *common.MockEnvironment, storage storage.Storage) *MockService { return s } -func (s *MockService) ExpectedHost() string { - return "storage.googleapis.com" +func (s *MockService) ExpectedHosts() []string { + return []string{"storage.googleapis.com"} } func (s *MockService) Register(grpcServer *grpc.Server) {