Repository: istio/istio
File: pilot/pkg/xds/waypoint_test.go (Go)

Code before:
func TestWaypointPeerMetadataFilters(t *testing.T) {
	testCases := []struct {
		name                                string
		enableAmbientMultiNetwork           bool
		enableAmbientMultiNetworkBaggage    bool
		expectedDownstreamDiscoveryMethods  []string
		expectedDownstreamPropagationMethod string
	}{
		{
			name:                                "single network ambient uses workload_discovery",
			enableAmbientMultiNetwork:           false,
			enableAmbientMultiNetworkBaggage:    false,
			expectedDownstreamDiscoveryMethods:  []string{"workload_discovery"},
			expectedDownstreamPropagationMethod: "",
		},
		{
			name:                                "ENABLE_AMBIENT_MULTI_NETWORK=true, ENABLE_AMBIENT_MULTI_NETWORK_BAGGAGE=false",
			enableAmbientMultiNetwork:           true,
			enableAmbientMultiNetworkBaggage:    false,
			expectedDownstreamDiscoveryMethods:  []string{"workload_discovery"},
			expectedDownstreamPropagationMethod: "",
		},
		{
			name:                                "single network ambient uses baggage",
			enableAmbientMultiNetwork:           false,
			enableAmbientMultiNetworkBaggage:    false,
			expectedDownstreamDiscoveryMethods:  []string{"baggage", "workload_discovery"},
			expectedDownstreamPropagationMethod: "baggage",
		},
		{
			name:                                "multi-network ambient uses baggage",
			enableAmbientMultiNetwork:           true,
			enableAmbientMultiNetworkBaggage:    true,
			expectedDownstreamDiscoveryMethods:  []string{"baggage", "workload_discovery"},
			expectedDownstreamPropagationMethod: "baggage",
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			g := NewWithT(t)
			test.SetForTest(t, &features.EnableAmbientMultiNetwork, tc.enableAmbientMultiNetwork)
			test.SetForTest(t, &features.EnableAmbientBaggage, tc.enableAmbientMultiNetworkBaggage)

			d, proxy := setupWaypointTest(t,
				waypointGateway,
				waypointSvc,
				waypointInstance,
				appServiceEntry)

			connectTerminateListener := xdstest.ExtractListener("connect_terminate", d.Listeners(proxy))

Review comment (bug):
This is why the test is failing; we disable baggage but expect the baggage propagation method to exist. We should rename the field to make it clearer that this is just baggage now (not dependent on multinetwork)

Code after:
func TestWaypointPeerMetadataFilters(t *testing.T) {
	testCases := []struct {
		name                                string
		enableAmbientMultiNetwork           bool
		enableAmbientBaggage                bool
		expectedDownstreamDiscoveryMethods  []string
		expectedDownstreamPropagationMethod string
	}{
		{
			name:                                "single network ambient uses workload_discovery",
			enableAmbientMultiNetwork:           false,
			enableAmbientBaggage:                false,
			expectedDownstreamDiscoveryMethods:  []string{"workload_discovery"},
			expectedDownstreamPropagationMethod: "",
		},
		{
			name:                                "ENABLE_AMBIENT_MULTI_NETWORK=true, ENABLE_AMBIENT_BAGGAGE=false",
			enableAmbientMultiNetwork:           true,
			enableAmbientBaggage:                false,
			expectedDownstreamDiscoveryMethods:  []string{"workload_discovery"},
			expectedDownstreamPropagationMethod: "",
		},
		{
			name:                                "single network ambient uses baggage",
			enableAmbientMultiNetwork:           false,
			enableAmbientBaggage:                true,
			expectedDownstreamDiscoveryMethods:  []string{"baggage", "workload_discovery"},
			expectedDownstreamPropagationMethod: "baggage",
		},
		{
			name:                                "multi-network ambient uses baggage",
			enableAmbientMultiNetwork:           true,
			enableAmbientBaggage:                true,
			expectedDownstreamDiscoveryMethods:  []string{"baggage", "workload_discovery"},
			expectedDownstreamPropagationMethod: "baggage",
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			g := NewWithT(t)
			test.SetForTest(t, &features.EnableAmbientMultiNetwork, tc.enableAmbientMultiNetwork)
			test.SetForTest(t, &features.EnableAmbientBaggage, tc.enableAmbientBaggage)

			d, proxy := setupWaypointTest(t,
				waypointGateway,
				waypointSvc,
				waypointInstance,
				appServiceEntry)

			connectTerminateListener := xdstest.ExtractListener("connect_terminate", d.Listeners(proxy))