Skip to content

Commit

Permalink
Merge pull request kubernetes#44583 from mikedanese/go1.8
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue

bump bazel build to go1.8.1 and remove invalid unit tests

part of kubernetes#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.
  • Loading branch information
Kubernetes Submit Queue authored Apr 25, 2017
2 parents 896d2af + 6a0c069 commit e1adcc2
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 58 deletions.
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
git_repository(
name = "io_bazel_rules_go",
commit = "cfdcbdc1d17e6dc3c48bbda4fce760949e58e381",
commit = "d57a2abc3b16a3904c159794f0f0a52cf6f061a7",
remote = "https://github.com/bazelbuild/rules_go.git",
)

Expand All @@ -19,7 +19,7 @@ git_repository(
load("@io_bazel_rules_go//go:def.bzl", "go_repositories")

go_repositories(
go_version = "1.7.5",
go_version = "1.8.1",
)

# for building docker base images
Expand Down
2 changes: 1 addition & 1 deletion hack/update-bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set -o pipefail
export KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
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
if [[ -e "${path}/bin/gazel" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion hack/verify-bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set -o pipefail
export KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
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
if [[ -e "${path}/bin/gazel" ]]; then
Expand Down
1 change: 0 additions & 1 deletion pkg/controller/deployment/util/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 9 additions & 16 deletions pkg/controller/deployment/util/deployment_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -668,56 +666,51 @@ func TestResolveFenceposts(t *testing.T) {
desired int32
expectSurge int32
expectUnavailable int32
expectError string
expectError bool
}{
{
maxSurge: "0%",
maxUnavailable: "0%",
desired: 0,
expectSurge: 0,
expectUnavailable: 1,
expectError: "",
expectError: false,
},
{
maxSurge: "39%",
maxUnavailable: "39%",
desired: 10,
expectSurge: 4,
expectUnavailable: 3,
expectError: "",
expectError: false,
},
{
maxSurge: "oops",
maxUnavailable: "39%",
desired: 10,
expectSurge: 0,
expectUnavailable: 0,
expectError: "invalid value for IntOrString: invalid value \"oops\": strconv.ParseInt: parsing \"oops\": invalid syntax",
expectError: true,
},
{
maxSurge: "55%",
maxUnavailable: "urg",
desired: 10,
expectSurge: 0,
expectUnavailable: 0,
expectError: "invalid value for IntOrString: invalid value \"urg\": strconv.ParseInt: parsing \"urg\": invalid syntax",
expectError: true,
},
}

for num, test := range tests {
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)
Expand Down
27 changes: 3 additions & 24 deletions pkg/probe/tcp/tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
}
}
8 changes: 4 additions & 4 deletions pkg/proxy/iptables/proxier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ func Test_getLocalIPs(t *testing.T) {
},
},
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.
Expand All @@ -1322,7 +1322,7 @@ func Test_getLocalIPs(t *testing.T) {
},
},
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.
Expand All @@ -1346,8 +1346,8 @@ func Test_getLocalIPs(t *testing.T) {
},
},
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"),
types.NamespacedName{Namespace: "ns4", Name: "ep4"}: sets.NewString("4.4.4.4", "4.4.4.6"),
{Namespace: "ns2", Name: "ep2"}: sets.NewString("2.2.2.2", "2.2.2.22", "2.2.2.3"),
{Namespace: "ns4", Name: "ep4"}: sets.NewString("4.4.4.4", "4.4.4.6"),
},
}}

Expand Down
4 changes: 3 additions & 1 deletion pkg/util/env/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 5 additions & 3 deletions staging/src/k8s.io/apimachinery/pkg/runtime/embedded_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package runtime_test
import (
"encoding/json"
"reflect"
"strings"
"testing"

"k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions staging/src/k8s.io/apimachinery/pkg/util/json/json_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build go1.8

/*
Copyright 2015 The Kubernetes Authors.
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions staging/src/k8s.io/apimachinery/pkg/util/net/http_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build go1.8

/*
Copyright 2016 The Kubernetes Authors.
Expand Down Expand Up @@ -59,6 +61,15 @@ func TestCloneTLSConfig(t *testing.T) {
"serverInitOnce",
"mutex",
"sessionTicketKeys",

// go1.8
"DynamicRecordSizingDisabled",
"GetClientCertificate",
"GetConfigForClient",
"KeyLogWriter",
"Renegotiation",
"VerifyPeerCertificate",
"originalConfig",
)

// See #33936.
Expand Down
2 changes: 1 addition & 1 deletion vendor/github.com/aws/aws-sdk-go/aws/request/BUILD

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions vendor/golang.org/x/net/http2/BUILD

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e1adcc2

Please sign in to comment.