mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-21 17:48:01 +00:00
Fix tests to pass with changed external types
This commit is contained in:
parent
af7e7f146d
commit
9d19238f6c
@ -430,8 +430,8 @@ func findPort(pod *api.Pod, svcPort *api.ServicePort) (int, int, error) {
|
|||||||
p := portName.IntVal
|
p := portName.IntVal
|
||||||
for _, container := range pod.Spec.Containers {
|
for _, container := range pod.Spec.Containers {
|
||||||
for _, port := range container.Ports {
|
for _, port := range container.Ports {
|
||||||
if port.ContainerPort == p && port.Protocol == svcPort.Protocol {
|
if port.ContainerPort == int(p) && port.Protocol == svcPort.Protocol {
|
||||||
hostPort, err := findMappedPort(pod, port.Protocol, p)
|
hostPort, err := findMappedPort(pod, port.Protocol, int(p))
|
||||||
return hostPort, port.ContainerPort, err
|
return hostPort, port.ContainerPort, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,8 +110,13 @@ func TestSpecificKind(t *testing.T) {
|
|||||||
api.Scheme.Log(t)
|
api.Scheme.Log(t)
|
||||||
defer api.Scheme.Log(nil)
|
defer api.Scheme.Log(nil)
|
||||||
|
|
||||||
kind := "Pod"
|
kind := "JobList"
|
||||||
doRoundTripTest(kind, t)
|
for i := 0; i < *fuzzIters; i++ {
|
||||||
|
doRoundTripTest(kind, t)
|
||||||
|
if t.Failed() {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestList(t *testing.T) {
|
func TestList(t *testing.T) {
|
||||||
@ -142,6 +147,9 @@ func TestRoundTripTypes(t *testing.T) {
|
|||||||
// Try a few times, since runTest uses random values.
|
// Try a few times, since runTest uses random values.
|
||||||
for i := 0; i < *fuzzIters; i++ {
|
for i := 0; i < *fuzzIters; i++ {
|
||||||
doRoundTripTest(kind, t)
|
doRoundTripTest(kind, t)
|
||||||
|
if t.Failed() {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,17 @@ func FuzzerFor(t *testing.T, version string, src rand.Source) *fuzz.Fuzzer {
|
|||||||
f.RandSource(src)
|
f.RandSource(src)
|
||||||
}
|
}
|
||||||
f.Funcs(
|
f.Funcs(
|
||||||
|
func(j *int, c fuzz.Continue) {
|
||||||
|
*j = int(c.Int31())
|
||||||
|
},
|
||||||
|
func(j **int, c fuzz.Continue) {
|
||||||
|
if c.RandBool() {
|
||||||
|
i := int(c.Int31())
|
||||||
|
*j = &i
|
||||||
|
} else {
|
||||||
|
*j = nil
|
||||||
|
}
|
||||||
|
},
|
||||||
func(j *runtime.PluginBase, c fuzz.Continue) {
|
func(j *runtime.PluginBase, c fuzz.Continue) {
|
||||||
// Do nothing; this struct has only a Kind field and it must stay blank in memory.
|
// Do nothing; this struct has only a Kind field and it must stay blank in memory.
|
||||||
},
|
},
|
||||||
@ -140,8 +151,8 @@ func FuzzerFor(t *testing.T, version string, src rand.Source) *fuzz.Fuzzer {
|
|||||||
},
|
},
|
||||||
func(j *extensions.JobSpec, c fuzz.Continue) {
|
func(j *extensions.JobSpec, c fuzz.Continue) {
|
||||||
c.FuzzNoCustom(j) // fuzz self without calling this function again
|
c.FuzzNoCustom(j) // fuzz self without calling this function again
|
||||||
completions := c.Rand.Int()
|
completions := int(c.Rand.Int31())
|
||||||
parallelism := c.Rand.Int()
|
parallelism := int(c.Rand.Int31())
|
||||||
j.Completions = &completions
|
j.Completions = &completions
|
||||||
j.Parallelism = ¶llelism
|
j.Parallelism = ¶llelism
|
||||||
},
|
},
|
||||||
@ -227,24 +238,23 @@ func FuzzerFor(t *testing.T, version string, src rand.Source) *fuzz.Fuzzer {
|
|||||||
policies := []api.RestartPolicy{api.RestartPolicyAlways, api.RestartPolicyNever, api.RestartPolicyOnFailure}
|
policies := []api.RestartPolicy{api.RestartPolicyAlways, api.RestartPolicyNever, api.RestartPolicyOnFailure}
|
||||||
*rp = policies[c.Rand.Intn(len(policies))]
|
*rp = policies[c.Rand.Intn(len(policies))]
|
||||||
},
|
},
|
||||||
|
// Only api.DownwardAPIVolumeFile needs to have a specific func since FieldRef has to be
|
||||||
|
// defaulted to a version otherwise roundtrip will fail
|
||||||
|
// For the remaining volume plugins the default fuzzer is enough.
|
||||||
|
func(m *api.DownwardAPIVolumeFile, c fuzz.Continue) {
|
||||||
|
m.Path = c.RandString()
|
||||||
|
versions := []string{"v1"}
|
||||||
|
m.FieldRef.APIVersion = versions[c.Rand.Intn(len(versions))]
|
||||||
|
m.FieldRef.FieldPath = c.RandString()
|
||||||
|
},
|
||||||
func(vs *api.VolumeSource, c fuzz.Continue) {
|
func(vs *api.VolumeSource, c fuzz.Continue) {
|
||||||
// Exactly one of the fields must be set.
|
// Exactly one of the fields must be set.
|
||||||
v := reflect.ValueOf(vs).Elem()
|
v := reflect.ValueOf(vs).Elem()
|
||||||
i := int(c.RandUint64() % uint64(v.NumField()))
|
i := int(c.RandUint64() % uint64(v.NumField()))
|
||||||
v = v.Field(i).Addr()
|
t := v.Field(i).Addr()
|
||||||
// Use a new fuzzer which cannot populate nil to ensure one field will be set.
|
for v.Field(i).IsNil() {
|
||||||
f := fuzz.New().NilChance(0).NumElements(1, 1)
|
c.Fuzz(t.Interface())
|
||||||
f.Funcs(
|
}
|
||||||
// Only api.DownwardAPIVolumeFile needs to have a specific func since FieldRef has to be
|
|
||||||
// defaulted to a version otherwise roundtrip will fail
|
|
||||||
// For the remaining volume plugins the default fuzzer is enough.
|
|
||||||
func(m *api.DownwardAPIVolumeFile, c fuzz.Continue) {
|
|
||||||
m.Path = c.RandString()
|
|
||||||
versions := []string{"v1"}
|
|
||||||
m.FieldRef.APIVersion = versions[c.Rand.Intn(len(versions))]
|
|
||||||
m.FieldRef.FieldPath = c.RandString()
|
|
||||||
},
|
|
||||||
).Fuzz(v.Interface())
|
|
||||||
},
|
},
|
||||||
func(d *api.DNSPolicy, c fuzz.Continue) {
|
func(d *api.DNSPolicy, c fuzz.Continue) {
|
||||||
policies := []api.DNSPolicy{api.DNSClusterFirst, api.DNSDefault}
|
policies := []api.DNSPolicy{api.DNSClusterFirst, api.DNSDefault}
|
||||||
@ -363,9 +373,9 @@ func FuzzerFor(t *testing.T, version string, src rand.Source) *fuzz.Fuzzer {
|
|||||||
},
|
},
|
||||||
func(s *extensions.HorizontalPodAutoscalerSpec, c fuzz.Continue) {
|
func(s *extensions.HorizontalPodAutoscalerSpec, c fuzz.Continue) {
|
||||||
c.FuzzNoCustom(s) // fuzz self without calling this function again
|
c.FuzzNoCustom(s) // fuzz self without calling this function again
|
||||||
minReplicas := c.Rand.Int()
|
minReplicas := int(c.Rand.Int31())
|
||||||
s.MinReplicas = &minReplicas
|
s.MinReplicas = &minReplicas
|
||||||
s.CPUUtilization = &extensions.CPUTargetUtilization{TargetPercentage: int(c.RandUint64())}
|
s.CPUUtilization = &extensions.CPUTargetUtilization{TargetPercentage: int(c.Int31())}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
return f
|
return f
|
||||||
|
@ -156,8 +156,8 @@ func TestSetDefaultReplicationController(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newInt(val int) *int {
|
func newInt(val int32) *int32 {
|
||||||
p := new(int)
|
p := new(int32)
|
||||||
*p = val
|
*p = val
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
@ -165,7 +165,7 @@ func newInt(val int) *int {
|
|||||||
func TestSetDefaultReplicationControllerReplicas(t *testing.T) {
|
func TestSetDefaultReplicationControllerReplicas(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
rc versioned.ReplicationController
|
rc versioned.ReplicationController
|
||||||
expectReplicas int
|
expectReplicas int32
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
rc: versioned.ReplicationController{
|
rc: versioned.ReplicationController{
|
||||||
@ -345,13 +345,13 @@ func TestSetDefaultServicePort(t *testing.T) {
|
|||||||
if out.Spec.Ports[0].Protocol != versioned.ProtocolTCP {
|
if out.Spec.Ports[0].Protocol != versioned.ProtocolTCP {
|
||||||
t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Spec.Ports[0].Protocol)
|
t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Spec.Ports[0].Protocol)
|
||||||
}
|
}
|
||||||
if out.Spec.Ports[0].TargetPort != intstr.FromInt(in.Spec.Ports[0].Port) {
|
if out.Spec.Ports[0].TargetPort != intstr.FromInt(int(in.Spec.Ports[0].Port)) {
|
||||||
t.Errorf("Expected port %v, got %v", in.Spec.Ports[0].Port, out.Spec.Ports[0].TargetPort)
|
t.Errorf("Expected port %v, got %v", in.Spec.Ports[0].Port, out.Spec.Ports[0].TargetPort)
|
||||||
}
|
}
|
||||||
if out.Spec.Ports[1].Protocol != versioned.ProtocolTCP {
|
if out.Spec.Ports[1].Protocol != versioned.ProtocolTCP {
|
||||||
t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Spec.Ports[1].Protocol)
|
t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Spec.Ports[1].Protocol)
|
||||||
}
|
}
|
||||||
if out.Spec.Ports[1].TargetPort != intstr.FromInt(in.Spec.Ports[1].Port) {
|
if out.Spec.Ports[1].TargetPort != intstr.FromInt(int(in.Spec.Ports[1].Port)) {
|
||||||
t.Errorf("Expected port %v, got %v", in.Spec.Ports[1].Port, out.Spec.Ports[1].TargetPort)
|
t.Errorf("Expected port %v, got %v", in.Spec.Ports[1].Port, out.Spec.Ports[1].TargetPort)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -367,7 +367,7 @@ func TestSetDefaultNamespace(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSetDefaultPodSpecHostNetwork(t *testing.T) {
|
func TestSetDefaultPodSpecHostNetwork(t *testing.T) {
|
||||||
portNum := 8080
|
portNum := int32(8080)
|
||||||
s := versioned.PodSpec{}
|
s := versioned.PodSpec{}
|
||||||
s.HostNetwork = true
|
s.HostNetwork = true
|
||||||
s.Containers = []versioned.Container{
|
s.Containers = []versioned.Container{
|
||||||
|
@ -294,9 +294,9 @@ func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
|
|||||||
return obj3
|
return obj3
|
||||||
}
|
}
|
||||||
|
|
||||||
func newInt(val int) *int {
|
func newInt(val int) *int32 {
|
||||||
p := new(int)
|
p := new(int32)
|
||||||
*p = val
|
*p = int32(val)
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,7 +347,7 @@ func TestTransformResponse(t *testing.T) {
|
|||||||
t.Errorf("%d: response should have been transformable into APIStatus: %v", i, err)
|
t.Errorf("%d: response should have been transformable into APIStatus: %v", i, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if status.Status().Code != test.Response.StatusCode {
|
if int(status.Status().Code) != test.Response.StatusCode {
|
||||||
t.Errorf("%d: status code did not match response: %#v", i, status.Status())
|
t.Errorf("%d: status code did not match response: %#v", i, status.Status())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ func encodeOrDie(obj runtime.Object) []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSortingPrinter(t *testing.T) {
|
func TestSortingPrinter(t *testing.T) {
|
||||||
intPtr := func(val int) *int { return &val }
|
intPtr := func(val int32) *int32 { return &val }
|
||||||
|
|
||||||
a := &api.Pod{
|
a := &api.Pod{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
|
Loading…
Reference in New Issue
Block a user