fix various bad tests
This commit is contained in:
		 Mike Danese
					Mike Danese
				
			
				
					committed by
					
						 Jeff Grafton
						Jeff Grafton
					
				
			
			
				
	
			
			
			 Jeff Grafton
						Jeff Grafton
					
				
			
						parent
						
							59fc948a06
						
					
				
				
					commit
					e48a4f0af7
				
			| @@ -58,7 +58,6 @@ go_test( | ||||
|         "//pkg/apis/extensions/v1beta1:go_default_library", | ||||
|         "//pkg/client/clientset_generated/clientset/fake: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/apis/meta/v1:go_default_library", | ||||
|         "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", | ||||
|   | ||||
| @@ -25,8 +25,6 @@ import ( | ||||
| 	"testing" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/stretchr/testify/assert" | ||||
|  | ||||
| 	apiequality "k8s.io/apimachinery/pkg/api/equality" | ||||
| 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||
| 	"k8s.io/apimachinery/pkg/runtime" | ||||
| @@ -668,7 +666,7 @@ func TestResolveFenceposts(t *testing.T) { | ||||
| 		desired           int32 | ||||
| 		expectSurge       int32 | ||||
| 		expectUnavailable int32 | ||||
| 		expectError       string | ||||
| 		expectError       bool | ||||
| 	}{ | ||||
| 		{ | ||||
| 			maxSurge:          "0%", | ||||
| @@ -676,7 +674,7 @@ func TestResolveFenceposts(t *testing.T) { | ||||
| 			desired:           0, | ||||
| 			expectSurge:       0, | ||||
| 			expectUnavailable: 1, | ||||
| 			expectError:       "", | ||||
| 			expectError:       false, | ||||
| 		}, | ||||
| 		{ | ||||
| 			maxSurge:          "39%", | ||||
| @@ -684,7 +682,7 @@ func TestResolveFenceposts(t *testing.T) { | ||||
| 			desired:           10, | ||||
| 			expectSurge:       4, | ||||
| 			expectUnavailable: 3, | ||||
| 			expectError:       "", | ||||
| 			expectError:       false, | ||||
| 		}, | ||||
| 		{ | ||||
| 			maxSurge:          "oops", | ||||
| @@ -692,7 +690,7 @@ func TestResolveFenceposts(t *testing.T) { | ||||
| 			desired:           10, | ||||
| 			expectSurge:       0, | ||||
| 			expectUnavailable: 0, | ||||
| 			expectError:       "invalid value for IntOrString: invalid value \"oops\": strconv.ParseInt: parsing \"oops\": invalid syntax", | ||||
| 			expectError:       true, | ||||
| 		}, | ||||
| 		{ | ||||
| 			maxSurge:          "55%", | ||||
| @@ -700,7 +698,7 @@ func TestResolveFenceposts(t *testing.T) { | ||||
| 			desired:           10, | ||||
| 			expectSurge:       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) | ||||
| 		maxUnavail := intstr.FromString(test.maxUnavailable) | ||||
| 		surge, unavail, err := ResolveFenceposts(&maxSurge, &maxUnavail, test.desired) | ||||
| 		if err != nil { | ||||
| 			if test.expectError == "" { | ||||
| 				t.Errorf("unexpected error %v", err) | ||||
| 			} else { | ||||
| 				assert := assert.New(t) | ||||
| 				assert.EqualError(err, test.expectError) | ||||
| 			} | ||||
| 		if err != nil && !test.expectError { | ||||
| 			t.Errorf("unexpected error %v", err) | ||||
| 		} | ||||
| 		if err == nil && test.expectError != "" { | ||||
| 			t.Errorf("missing error %v", test.expectError) | ||||
| 		if err == nil && test.expectError { | ||||
| 			t.Error("expected error") | ||||
| 		} | ||||
| 		if surge != test.expectSurge || unavail != 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/httptest" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| 	"testing" | ||||
| 	"time" | ||||
|  | ||||
| 	"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) { | ||||
| 	// Setup a test server that responds to probing correctly | ||||
| 	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||||
| @@ -58,32 +48,21 @@ func TestTcpHealthChecker(t *testing.T) { | ||||
|  | ||||
| 		expectedStatus probe.Result | ||||
| 		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 | ||||
| 		{tHost, tPort, probe.Success, nil, []string{""}}, | ||||
| 		{tHost, tPort, probe.Success, nil}, | ||||
| 		// No connection can be made and probing would fail | ||||
| 		{tHost, -1, probe.Failure, nil, []string{ | ||||
| 			"unknown port", | ||||
| 			"Servname not supported for ai_socktype", | ||||
| 			"nodename nor servname provided, or not known", | ||||
| 			"dial tcp: invalid port", | ||||
| 		}}, | ||||
| 		{tHost, -1, probe.Failure, nil}, | ||||
| 	} | ||||
|  | ||||
| 	prober := New() | ||||
| 	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 { | ||||
| 			t.Errorf("#%d: expected status=%v, get=%v", i, tt.expectedStatus, status) | ||||
| 		} | ||||
| 		if err != tt.expectedError { | ||||
| 			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") | ||||
| 	returnVal, err := GetEnvAsIntOrFallback(key, 1) | ||||
| 	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) { | ||||
|   | ||||
| @@ -19,7 +19,6 @@ package runtime_test | ||||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"reflect" | ||||
| 	"strings" | ||||
| 	"testing" | ||||
|  | ||||
| 	"k8s.io/apimachinery/pkg/api/meta" | ||||
| @@ -240,8 +239,11 @@ func TestNestedObject(t *testing.T) { | ||||
| 	// the external representation | ||||
| 	var decodedViaJSON EmbeddedTest | ||||
| 	err = json.Unmarshal(wire, &decodedViaJSON) | ||||
| 	if err == nil || !strings.Contains(err.Error(), "unmarshal object into Go value of type runtime.Object") { | ||||
| 		t.Fatalf("Unexpected decode error %v", err) | ||||
| 	if err == nil { | ||||
| 		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 { | ||||
| 		t.Errorf("Expected embedded objects to be nil: %#v", a) | ||||
|   | ||||
| @@ -1,3 +1,5 @@ | ||||
| // +build go1.8 | ||||
|  | ||||
| /* | ||||
| Copyright 2015 The Kubernetes Authors. | ||||
|  | ||||
| @@ -101,12 +103,12 @@ func TestEvaluateTypes(t *testing.T) { | ||||
| 		{ | ||||
| 			In:   `9223372036854775808`, // MaxInt64 + 1 | ||||
| 			Data: float64(9223372036854775808), | ||||
| 			Out:  strconv.FormatFloat(9223372036854775808, 'g', -1, 64), | ||||
| 			Out:  `9223372036854776000`, | ||||
| 		}, | ||||
| 		{ | ||||
| 			In:   `-9223372036854775809`, // MinInt64 - 1 | ||||
| 			Data: float64(math.MinInt64), | ||||
| 			Out:  strconv.FormatFloat(-9223372036854775809, 'g', -1, 64), | ||||
| 			Out:  `-9223372036854776000`, | ||||
| 		}, | ||||
|  | ||||
| 		// Floats | ||||
|   | ||||
| @@ -1,3 +1,5 @@ | ||||
| // +build go1.8 | ||||
|  | ||||
| /* | ||||
| Copyright 2016 The Kubernetes Authors. | ||||
|  | ||||
| @@ -59,6 +61,15 @@ func TestCloneTLSConfig(t *testing.T) { | ||||
| 		"serverInitOnce", | ||||
| 		"mutex", | ||||
| 		"sessionTicketKeys", | ||||
|  | ||||
| 		// go1.8 | ||||
| 		"DynamicRecordSizingDisabled", | ||||
| 		"GetClientCertificate", | ||||
| 		"GetConfigForClient", | ||||
| 		"KeyLogWriter", | ||||
| 		"Renegotiation", | ||||
| 		"VerifyPeerCertificate", | ||||
| 		"originalConfig", | ||||
| 	) | ||||
|  | ||||
| 	// See #33936. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user