Repository: grpc/grpc-go
File: internal/xds/balancer/clusterimpl/tests/balancer_test.go (Go)

Code before:
	if _, err := client.EmptyCall(ctx, &testpb.Empty{}); err == nil || !strings.Contains(err.Error(), parseConfigError) {
		t.Fatal("EmptyCall RPC succeeded when expected to fail")
	}
}

// setupManagementServerAndResolver sets up an xDS management server and returns
// the management server, resolver builder and Node ID.
func setupManagementServerAndResolver(t *testing.T) (*e2e.ManagementServer, resolver.Builder, string) {
	t.Helper()

	nodeID := uuid.New().String()
	mgmtServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{})
	contents := e2e.DefaultBootstrapContents(t, nodeID, mgmtServer.Address)

	// Create an xDS resolver with the above bootstrap configuration.
	resolverBuilder, err := internal.NewXDSResolverWithConfigForTesting.(func([]byte) (resolver.Builder, error))(contents)
	if err != nil {
		t.Fatalf("Failed to create xDS resolver for testing: %v", err)
	}

	return mgmtServer, resolverBuilder, nodeID
}

// configureXDSResources configures the management server with a route that
// enables auto_host_rewrite and an endpoint with the specified hostname.
func configureXDSResources(ctx context.Context, t *testing.T, mgmtServer *e2e.ManagementServer, nodeID string, serverAddr string, endpointHostname string, secLevel e2e.SecurityLevel, clusterType e2e.ClusterType) {
	t.Helper()

	const (
		serviceName  = "my-test-xds-service"
		routeName    = "route-my-test-xds-service"
		clusterName  = "cluster-my-test-xds-service"
		endpointName = "endpoints-my-test-xds-service"
	)

	port := testutils.ParsePort(t, serverAddr)

	resources := e2e.DefaultClientResources(e2e.ResourceParams{
		DialTarget: serviceName,
		NodeID:     nodeID,
		Host:       "localhost",
		Port:       port,
		SecLevel:   secLevel,
	})

	if clusterType == e2e.ClusterTypeLogicalDNS {
		resources.Clusters = []*v3clusterpb.Cluster{
			e2e.ClusterResourceWithOptions(e2e.ClusterOptions{
				ClusterName: clusterName,
				Type:        e2e.ClusterTypeLogicalDNS,
				DNSHostName: endpointHostname,

Review comment (security):
Nit: While you are here, could you please shorten the parameter list a bit by doing this:

```golang
func configureXDSResources(ctx context.Context, t *testing.T, mgmtServer *e2e.ManagementServer, nodeID, serverAddr, endpointHostname string, secLevel e2e.SecurityLevel, clusterType e2e.ClusterType) { ... }
```

Thanks

Code after:
	if _, err := client.EmptyCall(ctx, &testpb.Empty{}); err == nil || !strings.Contains(err.Error(), parseConfigError) {
		t.Fatal("EmptyCall RPC succeeded when expected to fail")
	}
}

// setupManagementServerAndResolver sets up an xDS management server and returns
// the management server, resolver builder and Node ID.
func setupManagementServerAndResolver(t *testing.T) (*e2e.ManagementServer, resolver.Builder, string) {
	t.Helper()

	nodeID := uuid.New().String()
	mgmtServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{})
	contents := e2e.DefaultBootstrapContents(t, nodeID, mgmtServer.Address)

	// Create an xDS resolver with the above bootstrap configuration.
	resolverBuilder, err := internal.NewXDSResolverWithConfigForTesting.(func([]byte) (resolver.Builder, error))(contents)
	if err != nil {
		t.Fatalf("Failed to create xDS resolver for testing: %v", err)
	}

	return mgmtServer, resolverBuilder, nodeID
}

// configureXDSResources configures the management server with a route that
// enables auto_host_rewrite and an endpoint with the specified hostname.
func configureXDSResources(ctx context.Context, t *testing.T, mgmtServer *e2e.ManagementServer, nodeID, serverAddr, endpointHostname string, secLevel e2e.SecurityLevel, clusterType e2e.ClusterType) {
	t.Helper()

	const (
		serviceName  = "my-test-xds-service"
		routeName    = "route-my-test-xds-service"
		clusterName  = "cluster-my-test-xds-service"
		endpointName = "endpoints-my-test-xds-service"
	)

	port := testutils.ParsePort(t, serverAddr)

	resources := e2e.DefaultClientResources(e2e.ResourceParams{
		DialTarget: serviceName,
		NodeID:     nodeID,
		Host:       "localhost",
		Port:       port,
		SecLevel:   secLevel,
	})

	if clusterType == e2e.ClusterTypeLogicalDNS {
		resources.Clusters = []*v3clusterpb.Cluster{
			e2e.ClusterResourceWithOptions(e2e.ClusterOptions{
				ClusterName: clusterName,
				Type:        e2e.ClusterTypeLogicalDNS,
				DNSHostName: endpointHostname,