mirror of https://github.com/k3s-io/k3s
Merge pull request #44583 from mikedanese/go1.8
Automatic merge from submit-queue bump bazel build to go1.8.1 and remove invalid unit tests part of https://github.com/kubernetes/kubernetes/issues/38228 I firmly believe that unit tests that check error strings are incorrect unit tests. If we care about what type of error is returned, we need to use public error types. Anywhere we are using generic errors, we don't care other then that we saw an error.pull/6/head
commit
e1adcc2367
|
@ -1,6 +1,6 @@
|
||||||
git_repository(
|
git_repository(
|
||||||
name = "io_bazel_rules_go",
|
name = "io_bazel_rules_go",
|
||||||
commit = "cfdcbdc1d17e6dc3c48bbda4fce760949e58e381",
|
commit = "d57a2abc3b16a3904c159794f0f0a52cf6f061a7",
|
||||||
remote = "https://github.com/bazelbuild/rules_go.git",
|
remote = "https://github.com/bazelbuild/rules_go.git",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ git_repository(
|
||||||
load("@io_bazel_rules_go//go:def.bzl", "go_repositories")
|
load("@io_bazel_rules_go//go:def.bzl", "go_repositories")
|
||||||
|
|
||||||
go_repositories(
|
go_repositories(
|
||||||
go_version = "1.7.5",
|
go_version = "1.8.1",
|
||||||
)
|
)
|
||||||
|
|
||||||
# for building docker base images
|
# for building docker base images
|
||||||
|
|
|
@ -20,7 +20,7 @@ set -o pipefail
|
||||||
export KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
|
export KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
|
||||||
source "${KUBE_ROOT}/hack/lib/init.sh"
|
source "${KUBE_ROOT}/hack/lib/init.sh"
|
||||||
|
|
||||||
go get gopkg.in/mikedanese/gazel.v14/gazel
|
go get gopkg.in/mikedanese/gazel.v16/gazel
|
||||||
|
|
||||||
for path in ${GOPATH//:/ }; do
|
for path in ${GOPATH//:/ }; do
|
||||||
if [[ -e "${path}/bin/gazel" ]]; then
|
if [[ -e "${path}/bin/gazel" ]]; then
|
||||||
|
|
|
@ -20,7 +20,7 @@ set -o pipefail
|
||||||
export KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
|
export KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
|
||||||
source "${KUBE_ROOT}/hack/lib/init.sh"
|
source "${KUBE_ROOT}/hack/lib/init.sh"
|
||||||
|
|
||||||
go get gopkg.in/mikedanese/gazel.v14/gazel
|
go get gopkg.in/mikedanese/gazel.v16/gazel
|
||||||
|
|
||||||
for path in ${GOPATH//:/ }; do
|
for path in ${GOPATH//:/ }; do
|
||||||
if [[ -e "${path}/bin/gazel" ]]; then
|
if [[ -e "${path}/bin/gazel" ]]; then
|
||||||
|
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1307,7 +1307,7 @@ func Test_getLocalIPs(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: map[types.NamespacedName]sets.String{
|
expected: map[types.NamespacedName]sets.String{
|
||||||
types.NamespacedName{Namespace: "ns1", Name: "ep1"}: sets.NewString("1.1.1.1"),
|
{Namespace: "ns1", Name: "ep1"}: sets.NewString("1.1.1.1"),
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
// Case[3]: named local and non-local ports for the same IP.
|
// Case[3]: named local and non-local ports for the same IP.
|
||||||
|
@ -1322,7 +1322,7 @@ func Test_getLocalIPs(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: map[types.NamespacedName]sets.String{
|
expected: map[types.NamespacedName]sets.String{
|
||||||
types.NamespacedName{Namespace: "ns1", Name: "ep1"}: sets.NewString("1.1.1.2"),
|
{Namespace: "ns1", Name: "ep1"}: sets.NewString("1.1.1.2"),
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
// Case[4]: named local and non-local ports for different IPs.
|
// Case[4]: named local and non-local ports for different IPs.
|
||||||
|
@ -1346,8 +1346,8 @@ func Test_getLocalIPs(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: map[types.NamespacedName]sets.String{
|
expected: map[types.NamespacedName]sets.String{
|
||||||
types.NamespacedName{Namespace: "ns2", Name: "ep2"}: sets.NewString("2.2.2.2", "2.2.2.22", "2.2.2.3"),
|
{Namespace: "ns2", Name: "ep2"}: sets.NewString("2.2.2.2", "2.2.2.22", "2.2.2.3"),
|
||||||
types.NamespacedName{Namespace: "ns4", Name: "ep4"}: sets.NewString("4.4.4.4", "4.4.4.6"),
|
{Namespace: "ns4", Name: "ep4"}: sets.NewString("4.4.4.4", "4.4.4.6"),
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -14,7 +14,7 @@ go_library(
|
||||||
"http_request.go",
|
"http_request.go",
|
||||||
"offset_reader.go",
|
"offset_reader.go",
|
||||||
"request.go",
|
"request.go",
|
||||||
"request_1_7.go",
|
"request_1_8.go",
|
||||||
"request_pagination.go",
|
"request_pagination.go",
|
||||||
"retryer.go",
|
"retryer.go",
|
||||||
"validation.go",
|
"validation.go",
|
||||||
|
|
|
@ -18,11 +18,10 @@ go_library(
|
||||||
"frame.go",
|
"frame.go",
|
||||||
"go16.go",
|
"go16.go",
|
||||||
"go17.go",
|
"go17.go",
|
||||||
"go17_not18.go",
|
"go18.go",
|
||||||
"gotrack.go",
|
"gotrack.go",
|
||||||
"headermap.go",
|
"headermap.go",
|
||||||
"http2.go",
|
"http2.go",
|
||||||
"not_go18.go",
|
|
||||||
"pipe.go",
|
"pipe.go",
|
||||||
"server.go",
|
"server.go",
|
||||||
"transport.go",
|
"transport.go",
|
||||||
|
|
Loading…
Reference in New Issue