Repository: grpc/grpc-go
File: internal/xds/resolver/xds_resolver_test.go (Go)

Code before:
			envconfig:           false,
			serverfeature:       serverFeature.ServerFeatureTrustedXDSServer,
			wantAutoHostRewrite: false,
		},
		{
			name:                "Disable_UntrustedServer",
			autoHostRewrite:     true,
			envconfig:           true,
			wantAutoHostRewrite: false,
		},
		{
			name:                "Disable_Routeconfig",
			autoHostRewrite:     false,
			envconfig:           true,
			serverfeature:       serverFeature.ServerFeatureTrustedXDSServer,
			wantAutoHostRewrite: false,
		},
	} {
		t.Run(tt.name, func(t *testing.T) {
			testutils.SetEnvConfig(t, &envconfig.XDSAuthorityRewrite, tt.envconfig)

			// Spin up an xDS management server for the test.
			ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
			defer cancel()
			nodeID := uuid.New().String()
			mgmtServer, _, _, _ := setupManagementServerForTest(t, nodeID)

			// Configure the management server with a good listener resource and a
			// route configuration resource, as specified by the test case.
			listeners := []*v3listenerpb.Listener{e2e.DefaultClientListener(defaultTestServiceName, defaultTestRouteConfigName)}
			clusters := []*v3clusterpb.Cluster{e2e.DefaultCluster(defaultTestClusterName, defaultTestEndpointName, e2e.SecurityLevelNone)}
			endpoints := []*v3endpointpb.ClusterLoadAssignment{e2e.DefaultEndpoint(defaultTestEndpointName, defaultTestHostname, defaultTestPort)}
			routes := []*v3routepb.RouteConfiguration{{
				Name: defaultTestRouteConfigName,
				VirtualHosts: []*v3routepb.VirtualHost{{
					Domains: []string{defaultTestServiceName},
					Routes: []*v3routepb.Route{{
						Match: &v3routepb.RouteMatch{PathSpecifier: &v3routepb.RouteMatch_Prefix{Prefix: "/"}},
						Action: &v3routepb.Route_Route{Route: &v3routepb.RouteAction{
							ClusterSpecifier: &v3routepb.RouteAction_WeightedClusters{WeightedClusters: &v3routepb.WeightedCluster{
								Clusters: []*v3routepb.WeightedCluster_ClusterWeight{
									{
										Name:   defaultTestClusterName,
										Weight: &wrapperspb.UInt32Value{Value: 100},
									},
								},
							}},
							HostRewriteSpecifier: &v3routepb.RouteAction_AutoHostRewrite{
								AutoHostRewrite: &wrapperspb.BoolValue{Value: tt.autoHostRewrite},
							},
						}},

Review comment (refactor):
You probably don't need this helper function here, since you don't use any of the returned channels from that helper function. You could instead manually start the management server here with `e2e.StartManagementServer`. 

Code after:
		},
		{
			name:                "EnvVarDisabled_TrustedServer_AutoHostRewriteOff",
			autoHostRewrite:     false,
			envconfig:           false,
			serverfeature:       serverFeature.ServerFeatureTrustedXDSServer,
			wantAutoHostRewrite: false,
		},
		{
			name:                "EnvVarDisabled_TrustedServer_AutoHostRewriteOn",
			autoHostRewrite:     true,
			envconfig:           false,
			serverfeature:       serverFeature.ServerFeatureTrustedXDSServer,
			wantAutoHostRewrite: false,
		},
		{
			name:                "EnvVarEnabled_NonTrustedServer_AutoHostRewriteOff",
			autoHostRewrite:     false,
			envconfig:           true,
			wantAutoHostRewrite: false,
		},
		{
			name:                "EnvVarEnabled_NonTrustedServer_AutoHostRewriteOn",
			autoHostRewrite:     true,
			envconfig:           true,
			wantAutoHostRewrite: false,
		},
		{
			name:                "EnvVarEnabled_TrustedServer_AutoHostRewriteOff",
			autoHostRewrite:     false,
			envconfig:           true,
			serverfeature:       serverFeature.ServerFeatureTrustedXDSServer,
			wantAutoHostRewrite: false,
		},
		{
			name:                "EnvVarEnabled_TrustedServer_AutoHostRewriteOn",
			autoHostRewrite:     true,
			envconfig:           true,
			serverfeature:       serverFeature.ServerFeatureTrustedXDSServer,
			wantAutoHostRewrite: true,
		},
	} {
		t.Run(tt.name, func(t *testing.T) {
			testutils.SetEnvConfig(t, &envconfig.XDSAuthorityRewrite, tt.envconfig)

			// Spin up an xDS management server for the test.
			ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
			defer cancel()
			nodeID := uuid.New().String()
			mgmtServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{AllowResourceSubset: true})
			defer mgmtServer.Stop()