Commit ca19b4dc authored by Dr. Stefan Schimanski's avatar Dr. Stefan Schimanski

aggregator: add OpenAPI aggregation order test

parent 1cca3f9d
...@@ -25,12 +25,12 @@ import ( ...@@ -25,12 +25,12 @@ import (
"k8s.io/kube-aggregator/pkg/apis/apiregistration" "k8s.io/kube-aggregator/pkg/apis/apiregistration"
) )
func newAPIServiceForTest(name, group string, minGroupPriority, versionPriority int32) apiregistration.APIService { func newAPIServiceForTest(name, group string, minGroupPriority, versionPriority int32, svc *apiregistration.ServiceReference) apiregistration.APIService {
r := apiregistration.APIService{} r := apiregistration.APIService{}
r.Spec.Group = group r.Spec.Group = group
r.Spec.GroupPriorityMinimum = minGroupPriority r.Spec.GroupPriorityMinimum = minGroupPriority
r.Spec.VersionPriority = versionPriority r.Spec.VersionPriority = versionPriority
r.Spec.Service = &apiregistration.ServiceReference{} r.Spec.Service = svc
r.Name = name r.Name = name
return r return r
} }
...@@ -48,22 +48,31 @@ func assertSortedServices(t *testing.T, actual []openAPISpecInfo, expectedNames ...@@ -48,22 +48,31 @@ func assertSortedServices(t *testing.T, actual []openAPISpecInfo, expectedNames
func TestAPIServiceSort(t *testing.T) { func TestAPIServiceSort(t *testing.T) {
list := []openAPISpecInfo{ list := []openAPISpecInfo{
{ {
apiService: newAPIServiceForTest("FirstService", "Group1", 10, 5), apiService: newAPIServiceForTest("FirstService", "Group1", 10, 5, &apiregistration.ServiceReference{}),
spec: &spec.Swagger{}, spec: &spec.Swagger{},
}, },
{ {
apiService: newAPIServiceForTest("SecondService", "Group2", 15, 3), apiService: newAPIServiceForTest("SecondService", "Group2", 15, 3, &apiregistration.ServiceReference{}),
spec: &spec.Swagger{}, spec: &spec.Swagger{},
}, },
{ {
apiService: newAPIServiceForTest("FirstServiceInternal", "Group1", 16, 3), apiService: newAPIServiceForTest("FirstServiceInternal", "Group1", 16, 3, &apiregistration.ServiceReference{}),
spec: &spec.Swagger{}, spec: &spec.Swagger{},
}, },
{ {
apiService: newAPIServiceForTest("ThirdService", "Group3", 15, 3), apiService: newAPIServiceForTest("ThirdService", "Group3", 15, 3, &apiregistration.ServiceReference{}),
spec: &spec.Swagger{}, spec: &spec.Swagger{},
}, },
{
apiService: newAPIServiceForTest("local_service_1", "Group4", 15, 1, nil),
},
{
apiService: newAPIServiceForTest("local_service_3", "Group5", 15, 2, nil),
},
{
apiService: newAPIServiceForTest("local_service_2", "Group6", 15, 3, nil),
},
} }
sortByPriority(list) sortByPriority(list)
assertSortedServices(t, list, []string{"FirstService", "FirstServiceInternal", "SecondService", "ThirdService"}) assertSortedServices(t, list, []string{"local_service_1", "local_service_2", "local_service_3", "FirstService", "FirstServiceInternal", "SecondService", "ThirdService"})
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment