Explorar el Código

Filters v2: Exhaustive, identical AND/OR testing

Michael Dresser hace 4 años
padre
commit
adac75e968
Se han modificado 1 ficheros con 80 adiciones y 5 borrados
  1. 80 5
      pkg/kubecost/allocationfilter_test.go

+ 80 - 5
pkg/kubecost/allocationfilter_test.go

@@ -341,7 +341,7 @@ func Test_AllocationFilterAnd_Matches(t *testing.T) {
 		expected bool
 	}{
 		{
-			name: `label[app]="foo" and namespace="kubecost" -> true`,
+			name: `label[app]="foo" and namespace="kubecost" -> both true`,
 			a: &Allocation{
 				Properties: &AllocationProperties{
 					Namespace: "kubecost",
@@ -366,10 +366,10 @@ func Test_AllocationFilterAnd_Matches(t *testing.T) {
 			expected: true,
 		},
 		{
-			name: `label[app]="foo" and namespace="kubecost" -> false`,
+			name: `label[app]="foo" and namespace="kubecost" -> first true`,
 			a: &Allocation{
 				Properties: &AllocationProperties{
-					Namespace: "kubecost-secondary",
+					Namespace: "kube-system",
 					Labels: map[string]string{
 						"app": "foo",
 					},
@@ -390,6 +390,56 @@ func Test_AllocationFilterAnd_Matches(t *testing.T) {
 			}},
 			expected: false,
 		},
+		{
+			name: `label[app]="foo" and namespace="kubecost" -> second true`,
+			a: &Allocation{
+				Properties: &AllocationProperties{
+					Namespace: "kubecost",
+					Labels: map[string]string{
+						"app": "bar",
+					},
+				},
+			},
+			filter: AllocationFilterAnd{[]AllocationFilter{
+				AllocationFilterCondition{
+					Field: FilterLabel,
+					Op:    FilterEquals,
+					Key:   "app",
+					Value: "foo",
+				},
+				AllocationFilterCondition{
+					Field: FilterNamespace,
+					Op:    FilterEquals,
+					Value: "kubecost",
+				},
+			}},
+			expected: false,
+		},
+		{
+			name: `label[app]="foo" and namespace="kubecost" -> both false`,
+			a: &Allocation{
+				Properties: &AllocationProperties{
+					Namespace: "kube-system",
+					Labels: map[string]string{
+						"app": "bar",
+					},
+				},
+			},
+			filter: AllocationFilterAnd{[]AllocationFilter{
+				AllocationFilterCondition{
+					Field: FilterLabel,
+					Op:    FilterEquals,
+					Key:   "app",
+					Value: "foo",
+				},
+				AllocationFilterCondition{
+					Field: FilterNamespace,
+					Op:    FilterEquals,
+					Value: "kubecost",
+				},
+			}},
+			expected: false,
+		},
 	}
 
 	for _, c := range cases {
@@ -409,6 +459,31 @@ func Test_AllocationFilterOr_Matches(t *testing.T) {
 
 		expected bool
 	}{
+		{
+			name: `label[app]="foo" or namespace="kubecost" -> both true`,
+			a: &Allocation{
+				Properties: &AllocationProperties{
+					Namespace: "kubecost",
+					Labels: map[string]string{
+						"app": "foo",
+					},
+				},
+			},
+			filter: AllocationFilterOr{[]AllocationFilter{
+				AllocationFilterCondition{
+					Field: FilterLabel,
+					Op:    FilterEquals,
+					Key:   "app",
+					Value: "foo",
+				},
+				AllocationFilterCondition{
+					Field: FilterNamespace,
+					Op:    FilterEquals,
+					Value: "kubecost",
+				},
+			}},
+			expected: true,
+		},
 		{
 			name: `label[app]="foo" or namespace="kubecost" -> first true`,
 			a: &Allocation{
@@ -460,10 +535,10 @@ func Test_AllocationFilterOr_Matches(t *testing.T) {
 			expected: true,
 		},
 		{
-			name: `label[app]="foo" or namespace="kubecost" -> false`,
+			name: `label[app]="foo" or namespace="kubecost" -> both false`,
 			a: &Allocation{
 				Properties: &AllocationProperties{
-					Namespace: "kubecost-secondary",
+					Namespace: "kube-system",
 					Labels: map[string]string{
 						"app": "bar",
 					},