Svc REST: Remove old rest_test

All the tests have been ported to storage_test.go
This commit is contained in:
Tim Hockin 2021-08-21 20:13:51 -07:00
parent b6da6c9c0f
commit 4ac7c73b2e
2 changed files with 24 additions and 138 deletions

View File

@ -1,138 +0,0 @@
/*
Copyright 2014 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package storage
import (
"net"
"testing"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
utilnet "k8s.io/apimachinery/pkg/util/net"
"k8s.io/apiserver/pkg/registry/generic"
etcd3testing "k8s.io/apiserver/pkg/storage/etcd3/testing"
api "k8s.io/kubernetes/pkg/apis/core"
endpointstore "k8s.io/kubernetes/pkg/registry/core/endpoint/storage"
"k8s.io/kubernetes/pkg/registry/core/service/ipallocator"
"k8s.io/kubernetes/pkg/registry/core/service/portallocator"
"k8s.io/kubernetes/pkg/registry/registrytest"
netutils "k8s.io/utils/net"
)
func NewTestREST(t *testing.T, ipFamilies []api.IPFamily) (*GenericREST, *etcd3testing.EtcdTestServer) {
etcdStorage, server := registrytest.NewEtcdStorage(t, "")
var rPrimary ipallocator.Interface
var rSecondary ipallocator.Interface
if len(ipFamilies) < 1 || len(ipFamilies) > 2 {
t.Fatalf("unexpected ipfamilies passed: %v", ipFamilies)
}
for i, family := range ipFamilies {
var r ipallocator.Interface
var err error
switch family {
case api.IPv4Protocol:
r, err = ipallocator.NewInMemory(makeIPNet(t))
if err != nil {
t.Fatalf("cannot create CIDR Range %v", err)
}
case api.IPv6Protocol:
r, err = ipallocator.NewInMemory(makeIPNet6(t))
if err != nil {
t.Fatalf("cannot create CIDR Range %v", err)
}
}
switch i {
case 0:
rPrimary = r
case 1:
rSecondary = r
}
}
portRange := utilnet.PortRange{Base: 30000, Size: 1000}
portAllocator, err := portallocator.NewInMemory(portRange)
if err != nil {
t.Fatalf("cannot create port allocator %v", err)
}
ipAllocators := map[api.IPFamily]ipallocator.Interface{
rPrimary.IPFamily(): rPrimary,
}
if rSecondary != nil {
ipAllocators[rSecondary.IPFamily()] = rSecondary
}
restOptions := generic.RESTOptions{
StorageConfig: etcdStorage.ForResource(schema.GroupResource{Resource: "services"}),
Decorator: generic.UndecoratedStorage,
DeleteCollectionWorkers: 1,
ResourcePrefix: "services",
}
endpoints, err := endpointstore.NewREST(generic.RESTOptions{
StorageConfig: etcdStorage,
Decorator: generic.UndecoratedStorage,
ResourcePrefix: "endpoints",
})
rest, _, _, err := NewREST(restOptions, api.IPv4Protocol, ipAllocators, portAllocator, endpoints, nil, nil)
if err != nil {
t.Fatalf("unexpected error from REST storage: %v", err)
}
return rest, server
}
func makeIPNet(t *testing.T) *net.IPNet {
_, net, err := netutils.ParseCIDRSloppy("1.2.3.0/24")
if err != nil {
t.Error(err)
}
return net
}
func makeIPNet6(t *testing.T) *net.IPNet {
_, net, err := netutils.ParseCIDRSloppy("2000::/108")
if err != nil {
t.Error(err)
}
return net
}
// this is local because it's not fully fleshed out enough for general use.
func makePod(name string, ips ...string) api.Pod {
p := api.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: metav1.NamespaceDefault,
},
Spec: api.PodSpec{
RestartPolicy: api.RestartPolicyAlways,
DNSPolicy: api.DNSDefault,
Containers: []api.Container{{Name: "ctr", Image: "img", ImagePullPolicy: api.PullIfNotPresent, TerminationMessagePolicy: api.TerminationMessageReadFile}},
},
Status: api.PodStatus{
PodIPs: []api.PodIP{},
},
}
for _, ip := range ips {
p.Status.PodIPs = append(p.Status.PodIPs, api.PodIP{IP: ip})
}
return p
}

View File

@ -11525,6 +11525,30 @@ func TestFeatureInternalTrafficPolicy(t *testing.T) {
// ipfamilypolicy and list,
// AllocateLoadBalancerNodePorts, LoadBalancerClass, status
// this is local because it's not fully fleshed out enough for general use.
func makePod(name string, ips ...string) api.Pod {
p := api.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: metav1.NamespaceDefault,
},
Spec: api.PodSpec{
RestartPolicy: api.RestartPolicyAlways,
DNSPolicy: api.DNSDefault,
Containers: []api.Container{{Name: "ctr", Image: "img", ImagePullPolicy: api.PullIfNotPresent, TerminationMessagePolicy: api.TerminationMessageReadFile}},
},
Status: api.PodStatus{
PodIPs: []api.PodIP{},
},
}
for _, ip := range ips {
p.Status.PodIPs = append(p.Status.PodIPs, api.PodIP{IP: ip})
}
return p
}
func TestServiceRegistryResourceLocation(t *testing.T) {
pods := []api.Pod{
makePod("unnamed", "1.2.3.4", "1.2.3.5"),