Repository: istio/istio
File: pkg/config/analysis/analyzers/analyzers_test.go (Go)

Code before:
		name:       "DestinationRuleSubsetsNotSelectPods",
		inputFiles: []string{"testdata/destinationrule-subsets-not-select-pods.yaml"},
		analyzer:   &destinationrule.PodNotSelectedAnalyzer{},
		expected: []message{
			{msg.DestinationRuleSubsetNotSelectPods, "DestinationRule default/subsets-not-select-pods"},
		},
	},
	{
		name:       "DestinationRuleSubsetsWithTopologyLabels",
		inputFiles: []string{"testdata/destinationrule-subsets-with-topology-labels.yaml"},
		analyzer:   &destinationrule.PodNotSelectedAnalyzer{},
		expected:   []message{
			// Should not report false positives for topology labels
			// All subsets should match because the analyzer augments pod labels with node topology labels:
			// - "region-us-west": matches topology.kubernetes.io/region from node
			// - "zone-us-west-1a": matches topology.kubernetes.io/zone from node
			// - "app-v1": matches version label from pod
			// - "mixed-labels": matches both version from pod AND topology.kubernetes.io/region from node
		},
	},
	{
		name:       "DestinationRuleEmptyTopologyLabels",
		inputFiles: []string{"testdata/destinationrule-empty-topology-labels.yaml"},
		analyzer:   &destinationrule.PodNotSelectedAnalyzer{},
		expected: []message{
			// Should report false positive for empty string topology label since AugmentLabels won't add empty values
			{msg.DestinationRuleSubsetNotSelectPods, "DestinationRule default/empty-topology-labels"},
		},
	},
	{
		name:           "ServiceEntry Addresses Allocated",
		inputFiles:     []string{"testdata/serviceentry-address-allocated.yaml"},
		meshConfigFile: "testdata/serviceentry-address-allocated-mesh-cfg.yaml",
		analyzer:       &serviceentry.ProtocolAddressesAnalyzer{},
		expected:       []message{},
	},
}

// regex patterns for analyzer names that should be explicitly ignored for testing
var ignoreAnalyzers = []string{
	// ValidationAnalyzer doesn't have any of its own logic, it just wraps the schema validation.
	// We assume that detailed testing for schema validation is being done elsewhere.
	// Testing the ValidationAnalyzer as a wrapper is done in a separate unit test.)
	`schema\.ValidationAnalyzer\.*`,
}

// TestAnalyzers allows for table-based testing of Analyzers.
func TestAnalyzers(t *testing.T) {
	requestedInputsByAnalyzer := make(map[string]map[config.GroupVersionKind]struct{})

	// For each test case, verify we get the expected messages as output

Review comment (suggestion):
```suggestion
			// Istio doesn't match on empty node locality labels.
```
Regardless, there is no matching because the topology labels on the node aren't empty

Code after:
		name:       "DestinationRuleSubsetsNotSelectPods",
		inputFiles: []string{"testdata/destinationrule-subsets-not-select-pods.yaml"},
		analyzer:   &destinationrule.PodNotSelectedAnalyzer{},
		expected: []message{
			{msg.DestinationRuleSubsetNotSelectPods, "DestinationRule default/subsets-not-select-pods"},
		},
	},
	{
		name:       "DestinationRuleSubsetsWithTopologyLabels",
		inputFiles: []string{"testdata/destinationrule-subsets-with-topology-labels.yaml"},
		analyzer:   &destinationrule.PodNotSelectedAnalyzer{},
		expected:   []message{
			// Should not report false positives for topology labels
			// All subsets should match because the analyzer augments pod labels with node topology labels:
			// - "region-us-west": matches topology.kubernetes.io/region from node
			// - "zone-us-west-1a": matches topology.kubernetes.io/zone from node
			// - "app-v1": matches version label from pod
			// - "mixed-labels": matches both version from pod AND topology.kubernetes.io/region from node
		},
	},
	{
		name:       "DestinationRuleEmptyTopologyLabels",
		inputFiles: []string{"testdata/destinationrule-empty-topology-labels.yaml"},
		analyzer:   &destinationrule.PodNotSelectedAnalyzer{},
		expected: []message{
			// Istio doesn't match on empty node locality labels.
			{msg.DestinationRuleSubsetNotSelectPods, "DestinationRule default/empty-topology-labels"},
		},
	},
	{
		name:           "ServiceEntry Addresses Allocated",
		inputFiles:     []string{"testdata/serviceentry-address-allocated.yaml"},
		meshConfigFile: "testdata/serviceentry-address-allocated-mesh-cfg.yaml",
		analyzer:       &serviceentry.ProtocolAddressesAnalyzer{},
		expected:       []message{},
	},
}

// regex patterns for analyzer names that should be explicitly ignored for testing
var ignoreAnalyzers = []string{
	// ValidationAnalyzer doesn't have any of its own logic, it just wraps the schema validation.
	// We assume that detailed testing for schema validation is being done elsewhere.
	// Testing the ValidationAnalyzer as a wrapper is done in a separate unit test.)
	`schema\.ValidationAnalyzer\.*`,
}

// TestAnalyzers allows for table-based testing of Analyzers.
func TestAnalyzers(t *testing.T) {
	requestedInputsByAnalyzer := make(map[string]map[config.GroupVersionKind]struct{})

	// For each test case, verify we get the expected messages as output