mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
fix various bad tests
This commit is contained in:
parent
59fc948a06
commit
e48a4f0af7
@ -58,7 +58,6 @@ go_test(
|
|||||||
"//pkg/apis/extensions/v1beta1:go_default_library",
|
"//pkg/apis/extensions/v1beta1:go_default_library",
|
||||||
"//pkg/client/clientset_generated/clientset/fake:go_default_library",
|
"//pkg/client/clientset_generated/clientset/fake:go_default_library",
|
||||||
"//pkg/controller:go_default_library",
|
"//pkg/controller:go_default_library",
|
||||||
"//vendor/github.com/stretchr/testify/assert:go_default_library",
|
|
||||||
"//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||||
|
@ -25,8 +25,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
|
|
||||||
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
@ -668,7 +666,7 @@ func TestResolveFenceposts(t *testing.T) {
|
|||||||
desired int32
|
desired int32
|
||||||
expectSurge int32
|
expectSurge int32
|
||||||
expectUnavailable int32
|
expectUnavailable int32
|
||||||
expectError string
|
expectError bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
maxSurge: "0%",
|
maxSurge: "0%",
|
||||||
@ -676,7 +674,7 @@ func TestResolveFenceposts(t *testing.T) {
|
|||||||
desired: 0,
|
desired: 0,
|
||||||
expectSurge: 0,
|
expectSurge: 0,
|
||||||
expectUnavailable: 1,
|
expectUnavailable: 1,
|
||||||
expectError: "",
|
expectError: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
maxSurge: "39%",
|
maxSurge: "39%",
|
||||||
@ -684,7 +682,7 @@ func TestResolveFenceposts(t *testing.T) {
|
|||||||
desired: 10,
|
desired: 10,
|
||||||
expectSurge: 4,
|
expectSurge: 4,
|
||||||
expectUnavailable: 3,
|
expectUnavailable: 3,
|
||||||
expectError: "",
|
expectError: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
maxSurge: "oops",
|
maxSurge: "oops",
|
||||||
@ -692,7 +690,7 @@ func TestResolveFenceposts(t *testing.T) {
|
|||||||
desired: 10,
|
desired: 10,
|
||||||
expectSurge: 0,
|
expectSurge: 0,
|
||||||
expectUnavailable: 0,
|
expectUnavailable: 0,
|
||||||
expectError: "invalid value for IntOrString: invalid value \"oops\": strconv.ParseInt: parsing \"oops\": invalid syntax",
|
expectError: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
maxSurge: "55%",
|
maxSurge: "55%",
|
||||||
@ -700,7 +698,7 @@ func TestResolveFenceposts(t *testing.T) {
|
|||||||
desired: 10,
|
desired: 10,
|
||||||
expectSurge: 0,
|
expectSurge: 0,
|
||||||
expectUnavailable: 0,
|
expectUnavailable: 0,
|
||||||
expectError: "invalid value for IntOrString: invalid value \"urg\": strconv.ParseInt: parsing \"urg\": invalid syntax",
|
expectError: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -708,16 +706,11 @@ func TestResolveFenceposts(t *testing.T) {
|
|||||||
maxSurge := intstr.FromString(test.maxSurge)
|
maxSurge := intstr.FromString(test.maxSurge)
|
||||||
maxUnavail := intstr.FromString(test.maxUnavailable)
|
maxUnavail := intstr.FromString(test.maxUnavailable)
|
||||||
surge, unavail, err := ResolveFenceposts(&maxSurge, &maxUnavail, test.desired)
|
surge, unavail, err := ResolveFenceposts(&maxSurge, &maxUnavail, test.desired)
|
||||||
if err != nil {
|
if err != nil && !test.expectError {
|
||||||
if test.expectError == "" {
|
t.Errorf("unexpected error %v", err)
|
||||||
t.Errorf("unexpected error %v", err)
|
|
||||||
} else {
|
|
||||||
assert := assert.New(t)
|
|
||||||
assert.EqualError(err, test.expectError)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if err == nil && test.expectError != "" {
|
if err == nil && test.expectError {
|
||||||
t.Errorf("missing error %v", test.expectError)
|
t.Error("expected error")
|
||||||
}
|
}
|
||||||
if surge != test.expectSurge || unavail != test.expectUnavailable {
|
if surge != test.expectSurge || unavail != test.expectUnavailable {
|
||||||
t.Errorf("#%v got %v:%v, want %v:%v", num, surge, unavail, test.expectSurge, test.expectUnavailable)
|
t.Errorf("#%v got %v:%v, want %v:%v", num, surge, unavail, test.expectSurge, test.expectUnavailable)
|
||||||
|
@ -21,22 +21,12 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/probe"
|
"k8s.io/kubernetes/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
func containsAny(s string, substrs []string) bool {
|
|
||||||
for _, substr := range substrs {
|
|
||||||
if strings.Contains(s, substr) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTcpHealthChecker(t *testing.T) {
|
func TestTcpHealthChecker(t *testing.T) {
|
||||||
// Setup a test server that responds to probing correctly
|
// Setup a test server that responds to probing correctly
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -58,32 +48,21 @@ func TestTcpHealthChecker(t *testing.T) {
|
|||||||
|
|
||||||
expectedStatus probe.Result
|
expectedStatus probe.Result
|
||||||
expectedError error
|
expectedError error
|
||||||
// Some errors are different depending on your system.
|
|
||||||
// The test passes as long as the output matches one of them.
|
|
||||||
expectedOutputs []string
|
|
||||||
}{
|
}{
|
||||||
// A connection is made and probing would succeed
|
// A connection is made and probing would succeed
|
||||||
{tHost, tPort, probe.Success, nil, []string{""}},
|
{tHost, tPort, probe.Success, nil},
|
||||||
// No connection can be made and probing would fail
|
// No connection can be made and probing would fail
|
||||||
{tHost, -1, probe.Failure, nil, []string{
|
{tHost, -1, probe.Failure, nil},
|
||||||
"unknown port",
|
|
||||||
"Servname not supported for ai_socktype",
|
|
||||||
"nodename nor servname provided, or not known",
|
|
||||||
"dial tcp: invalid port",
|
|
||||||
}},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prober := New()
|
prober := New()
|
||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
status, output, err := prober.Probe(tt.host, tt.port, 1*time.Second)
|
status, _, err := prober.Probe(tt.host, tt.port, 1*time.Second)
|
||||||
if status != tt.expectedStatus {
|
if status != tt.expectedStatus {
|
||||||
t.Errorf("#%d: expected status=%v, get=%v", i, tt.expectedStatus, status)
|
t.Errorf("#%d: expected status=%v, get=%v", i, tt.expectedStatus, status)
|
||||||
}
|
}
|
||||||
if err != tt.expectedError {
|
if err != tt.expectedError {
|
||||||
t.Errorf("#%d: expected error=%v, get=%v", i, tt.expectedError, err)
|
t.Errorf("#%d: expected error=%v, get=%v", i, tt.expectedError, err)
|
||||||
}
|
}
|
||||||
if !containsAny(output, tt.expectedOutputs) {
|
|
||||||
t.Errorf("#%d: expected output=one of %#v, get=%s", i, tt.expectedOutputs, output)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
pkg/util/env/env_test.go
vendored
4
pkg/util/env/env_test.go
vendored
@ -55,7 +55,9 @@ func TestGetEnvAsIntOrFallback(t *testing.T) {
|
|||||||
os.Setenv(key, "not-an-int")
|
os.Setenv(key, "not-an-int")
|
||||||
returnVal, err := GetEnvAsIntOrFallback(key, 1)
|
returnVal, err := GetEnvAsIntOrFallback(key, 1)
|
||||||
assert.Equal(expected, returnVal)
|
assert.Equal(expected, returnVal)
|
||||||
assert.EqualError(err, "strconv.ParseInt: parsing \"not-an-int\": invalid syntax")
|
if err == nil {
|
||||||
|
t.Error("expected error")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetEnvAsFloat64OrFallback(t *testing.T) {
|
func TestGetEnvAsFloat64OrFallback(t *testing.T) {
|
||||||
|
@ -19,7 +19,6 @@ package runtime_test
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
@ -240,8 +239,11 @@ func TestNestedObject(t *testing.T) {
|
|||||||
// the external representation
|
// the external representation
|
||||||
var decodedViaJSON EmbeddedTest
|
var decodedViaJSON EmbeddedTest
|
||||||
err = json.Unmarshal(wire, &decodedViaJSON)
|
err = json.Unmarshal(wire, &decodedViaJSON)
|
||||||
if err == nil || !strings.Contains(err.Error(), "unmarshal object into Go value of type runtime.Object") {
|
if err == nil {
|
||||||
t.Fatalf("Unexpected decode error %v", err)
|
t.Fatal("Expeceted decode error")
|
||||||
|
}
|
||||||
|
if _, ok := err.(*json.UnmarshalTypeError); !ok {
|
||||||
|
t.Fatalf("Unexpected decode error: %v", err)
|
||||||
}
|
}
|
||||||
if a := decodedViaJSON; a.Object != nil || a.EmptyObject != nil {
|
if a := decodedViaJSON; a.Object != nil || a.EmptyObject != nil {
|
||||||
t.Errorf("Expected embedded objects to be nil: %#v", a)
|
t.Errorf("Expected embedded objects to be nil: %#v", a)
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// +build go1.8
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright 2015 The Kubernetes Authors.
|
Copyright 2015 The Kubernetes Authors.
|
||||||
|
|
||||||
@ -101,12 +103,12 @@ func TestEvaluateTypes(t *testing.T) {
|
|||||||
{
|
{
|
||||||
In: `9223372036854775808`, // MaxInt64 + 1
|
In: `9223372036854775808`, // MaxInt64 + 1
|
||||||
Data: float64(9223372036854775808),
|
Data: float64(9223372036854775808),
|
||||||
Out: strconv.FormatFloat(9223372036854775808, 'g', -1, 64),
|
Out: `9223372036854776000`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
In: `-9223372036854775809`, // MinInt64 - 1
|
In: `-9223372036854775809`, // MinInt64 - 1
|
||||||
Data: float64(math.MinInt64),
|
Data: float64(math.MinInt64),
|
||||||
Out: strconv.FormatFloat(-9223372036854775809, 'g', -1, 64),
|
Out: `-9223372036854776000`,
|
||||||
},
|
},
|
||||||
|
|
||||||
// Floats
|
// Floats
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// +build go1.8
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright 2016 The Kubernetes Authors.
|
Copyright 2016 The Kubernetes Authors.
|
||||||
|
|
||||||
@ -59,6 +61,15 @@ func TestCloneTLSConfig(t *testing.T) {
|
|||||||
"serverInitOnce",
|
"serverInitOnce",
|
||||||
"mutex",
|
"mutex",
|
||||||
"sessionTicketKeys",
|
"sessionTicketKeys",
|
||||||
|
|
||||||
|
// go1.8
|
||||||
|
"DynamicRecordSizingDisabled",
|
||||||
|
"GetClientCertificate",
|
||||||
|
"GetConfigForClient",
|
||||||
|
"KeyLogWriter",
|
||||||
|
"Renegotiation",
|
||||||
|
"VerifyPeerCertificate",
|
||||||
|
"originalConfig",
|
||||||
)
|
)
|
||||||
|
|
||||||
// See #33936.
|
// See #33936.
|
||||||
|
Loading…
Reference in New Issue
Block a user