Skip to content

Commit

Permalink
Merge pull request #6252 from krousey/string_format_cleanup
Browse files Browse the repository at this point in the history
Fixing a lot of string formatting issues
  • Loading branch information
vmarmol committed Mar 31, 2015
2 parents 7094bad + 6904c4d commit 2de3762
Show file tree
Hide file tree
Showing 26 changed files with 66 additions and 66 deletions.
2 changes: 1 addition & 1 deletion pkg/api/helpers_test.go
Expand Up @@ -63,7 +63,7 @@ func TestSemantic(t *testing.T) {

for index, item := range table {
if e, a := item.shouldEqual, Semantic.DeepEqual(item.a, item.b); e != a {
t.Errorf("expected %v, got %v.", index, e, a)
t.Errorf("case[%d], expected %v, got %v.", index, e, a)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/apiserver_test.go
Expand Up @@ -653,7 +653,7 @@ func TestList(t *testing.T) {
if resp.StatusCode != http.StatusOK {
t.Errorf("%d: unexpected status: %d, Expected: %d, %#v", i, resp.StatusCode, http.StatusOK, resp)
body, _ := ioutil.ReadAll(resp.Body)
t.Logf("%d: body: %s", string(body))
t.Logf("%d: body: %s", i, string(body))
continue
}
// TODO: future, restore get links
Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/authorizer/abac/abac_test.go
Expand Up @@ -340,7 +340,7 @@ func TestPolicy(t *testing.T) {
for _, test := range tests {
matches := test.policy.matches(test.attr)
if test.matches != matches {
t.Errorf("unexpected value for %s, expected: %s, saw: %s", test.name, test.matches, matches)
t.Errorf("unexpected value for %s, expected: %t, saw: %t", test.name, test.matches, matches)
}
}
}
2 changes: 1 addition & 1 deletion pkg/client/helper_test.go
Expand Up @@ -307,7 +307,7 @@ func TestSetKubernetesDefaults(t *testing.T) {
func TestSetKubernetesDefaultsUserAgent(t *testing.T) {
config := &Config{}
if err := SetKubernetesDefaults(config); err != nil {
t.Errorf("unexpected error: %v")
t.Errorf("unexpected error: %v", err)
}
if !strings.Contains(config.UserAgent, "kubernetes/") {
t.Errorf("no user agent set: %#v", config)
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/portforward/portforward_test.go
Expand Up @@ -299,11 +299,11 @@ func TestForwardPorts(t *testing.T) {
// wait for r.ForwardPorts to actually return
err = <-doneChan
if err != nil {
t.Fatalf("%d: unexpected error: %s", err)
t.Fatalf("%d: unexpected error: %s", i, err)
}

if e, a := len(testCase.Send), len(conn.streams); e != a {
t.Fatalf("%d: expected %d streams to be created, got %d", e, a)
t.Fatalf("%d: expected %d streams to be created, got %d", i, e, a)
}

if !conn.closeCalled {
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/remotecommand/remotecommand_test.go
Expand Up @@ -282,7 +282,7 @@ func TestRequestExecuteRemoteCommand(t *testing.T) {
}

if !conn.closeCalled {
t.Fatalf("%d: expected upgraded connection to get closed")
t.Fatalf("%d: expected upgraded connection to get closed", i)
}
}
}
4 changes: 2 additions & 2 deletions pkg/client/request_test.go
Expand Up @@ -644,11 +644,11 @@ func TestRequestUpgrade(t *testing.T) {
}

if testCase.AuthBasicHeader && !strings.Contains(rt.req.Header.Get("Authorization"), "Basic") {
t.Errorf("%d: expected basic auth header, got: %s", rt.req.Header.Get("Authorization"))
t.Errorf("%d: expected basic auth header, got: %s", i, rt.req.Header.Get("Authorization"))
}

if testCase.AuthBearerHeader && !strings.Contains(rt.req.Header.Get("Authorization"), "Bearer") {
t.Errorf("%d: expected bearer auth header, got: %s", rt.req.Header.Get("Authorization"))
t.Errorf("%d: expected bearer auth header, got: %s", i, rt.req.Header.Get("Authorization"))
}

if e, a := expectedConn, conn; e != a {
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/label.go
Expand Up @@ -110,7 +110,7 @@ func parseLabels(spec []string) (map[string]string, []string, error) {
} else if strings.HasSuffix(labelSpec, "-") {
remove = append(remove, labelSpec[:len(labelSpec)-1])
} else {
return nil, nil, fmt.Errorf("unknown label spec: %v")
return nil, nil, fmt.Errorf("unknown label spec: %v", labelSpec)
}
}
for _, removeLabel := range remove {
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/resize_test.go
Expand Up @@ -79,7 +79,7 @@ func TestReplicationControllerResize(t *testing.T) {
t.Errorf("unexpected action: %v, expected get-controller %s", fake.Actions[0], name)
}
if fake.Actions[1].Action != "update-controller" || fake.Actions[1].Value.(*api.ReplicationController).Spec.Replicas != int(count) {
t.Errorf("unexpected action %v, expected update-controller with replicas = %d", count)
t.Errorf("unexpected action %v, expected update-controller with replicas = %d", fake.Actions[1], count)
}
}

Expand Down
30 changes: 15 additions & 15 deletions pkg/kubectl/resource/builder_test.go
Expand Up @@ -173,7 +173,7 @@ func TestPathBuilder(t *testing.T) {

err := b.Do().IntoSingular(&singular).Visit(test.Handle)
if err != nil || !singular || len(test.Infos) != 1 {
t.Fatalf("unexpected response: %v %f %#v", err, singular, test.Infos)
t.Fatalf("unexpected response: %v %t %#v", err, singular, test.Infos)
}

info := test.Infos[0]
Expand Down Expand Up @@ -225,7 +225,7 @@ func TestPathBuilderWithMultiple(t *testing.T) {

err := b.Do().IntoSingular(&singular).Visit(test.Handle)
if err != nil || singular || len(test.Infos) != 2 {
t.Fatalf("unexpected response: %v %f %#v", err, singular, test.Infos)
t.Fatalf("unexpected response: %v %t %#v", err, singular, test.Infos)
}

info := test.Infos[1]
Expand All @@ -244,7 +244,7 @@ func TestDirectoryBuilder(t *testing.T) {

err := b.Do().IntoSingular(&singular).Visit(test.Handle)
if err != nil || singular || len(test.Infos) < 4 {
t.Fatalf("unexpected response: %v %f %#v", err, singular, test.Infos)
t.Fatalf("unexpected response: %v %t %#v", err, singular, test.Infos)
}

found := false
Expand Down Expand Up @@ -274,7 +274,7 @@ func TestURLBuilder(t *testing.T) {

err := b.Do().IntoSingular(&singular).Visit(test.Handle)
if err != nil || !singular || len(test.Infos) != 1 {
t.Fatalf("unexpected response: %v %f %#v", err, singular, test.Infos)
t.Fatalf("unexpected response: %v %t %#v", err, singular, test.Infos)
}
info := test.Infos[0]
if info.Name != "test" || info.Namespace != "foo" || info.Object == nil {
Expand All @@ -298,7 +298,7 @@ func TestURLBuilderRequireNamespace(t *testing.T) {

err := b.Do().IntoSingular(&singular).Visit(test.Handle)
if err == nil || !singular || len(test.Infos) != 0 {
t.Fatalf("unexpected response: %v %f %#v", err, singular, test.Infos)
t.Fatalf("unexpected response: %v %t %#v", err, singular, test.Infos)
}
}

Expand All @@ -320,7 +320,7 @@ func TestResourceByName(t *testing.T) {

err := b.Do().IntoSingular(&singular).Visit(test.Handle)
if err != nil || !singular || len(test.Infos) != 1 {
t.Fatalf("unexpected response: %v %f %#v", err, singular, test.Infos)
t.Fatalf("unexpected response: %v %t %#v", err, singular, test.Infos)
}
if !reflect.DeepEqual(&pods.Items[0], test.Objects()[0]) {
t.Errorf("unexpected object: %#v", test.Objects())
Expand All @@ -347,7 +347,7 @@ func TestResourceByNameAndEmptySelector(t *testing.T) {
singular := false
infos, err := b.Do().IntoSingular(&singular).Infos()
if err != nil || !singular || len(infos) != 1 {
t.Fatalf("unexpected response: %v %f %#v", err, singular, infos)
t.Fatalf("unexpected response: %v %t %#v", err, singular, infos)
}
if !reflect.DeepEqual(&pods.Items[0], infos[0].Object) {
t.Errorf("unexpected object: %#v", infos[0])
Expand Down Expand Up @@ -383,7 +383,7 @@ func TestSelector(t *testing.T) {

err := b.Do().IntoSingular(&singular).Visit(test.Handle)
if err != nil || singular || len(test.Infos) != 3 {
t.Fatalf("unexpected response: %v %f %#v", err, singular, test.Infos)
t.Fatalf("unexpected response: %v %t %#v", err, singular, test.Infos)
}
if !api.Semantic.DeepDerivative([]runtime.Object{&pods.Items[0], &pods.Items[1], &svc.Items[0]}, test.Objects()) {
t.Errorf("unexpected visited objects: %#v", test.Objects())
Expand Down Expand Up @@ -493,7 +493,7 @@ func TestResourceTuple(t *testing.T) {
continue
}
if len(info) != len(testCase.args) {
t.Errorf("%s: unexpected number of infos returned: %#v", info)
t.Errorf("%s: unexpected number of infos returned: %#v", k, info)
}
}
}
Expand All @@ -508,7 +508,7 @@ func TestStream(t *testing.T) {

err := b.Do().IntoSingular(&singular).Visit(test.Handle)
if err != nil || singular || len(test.Infos) != 3 {
t.Fatalf("unexpected response: %v %f %#v", err, singular, test.Infos)
t.Fatalf("unexpected response: %v %t %#v", err, singular, test.Infos)
}
if !api.Semantic.DeepDerivative([]runtime.Object{&pods.Items[0], &pods.Items[1], &rc.Items[0]}, test.Objects()) {
t.Errorf("unexpected visited objects: %#v", test.Objects())
Expand All @@ -525,7 +525,7 @@ func TestYAMLStream(t *testing.T) {

err := b.Do().IntoSingular(&singular).Visit(test.Handle)
if err != nil || singular || len(test.Infos) != 3 {
t.Fatalf("unexpected response: %v %f %#v", err, singular, test.Infos)
t.Fatalf("unexpected response: %v %t %#v", err, singular, test.Infos)
}
if !api.Semantic.DeepDerivative([]runtime.Object{&pods.Items[0], &pods.Items[1], &rc.Items[0]}, test.Objects()) {
t.Errorf("unexpected visited objects: %#v", test.Objects())
Expand Down Expand Up @@ -653,7 +653,7 @@ func TestWatch(t *testing.T) {
select {
case obj := <-ch:
if obj.Type != watch.Added {
t.Fatalf("unexpected watch event", obj)
t.Fatalf("unexpected watch event %#v", obj)
}
service, ok := obj.Object.(*api.Service)
if !ok {
Expand Down Expand Up @@ -734,7 +734,7 @@ func TestIgnoreStreamErrors(t *testing.T) {

err := b.Do().IntoSingular(&singular).Visit(test.Handle)
if err != nil || singular || len(test.Infos) != 2 {
t.Fatalf("unexpected response: %v %f %#v", err, singular, test.Infos)
t.Fatalf("unexpected response: %v %t %#v", err, singular, test.Infos)
}

if !api.Semantic.DeepDerivative([]runtime.Object{&pods.Items[0], &svc.Items[0]}, test.Objects()) {
Expand Down Expand Up @@ -768,14 +768,14 @@ func TestReceiveMultipleErrors(t *testing.T) {

err := b.Do().IntoSingular(&singular).Visit(test.Handle)
if err == nil || singular || len(test.Infos) != 0 {
t.Fatalf("unexpected response: %v %f %#v", err, singular, test.Infos)
t.Fatalf("unexpected response: %v %t %#v", err, singular, test.Infos)
}

errs, ok := err.(errors.Aggregate)
if !ok {
t.Fatalf("unexpected error: %v", reflect.TypeOf(err))
}
if len(errs.Errors()) != 2 {
t.Errorf("unexpected errors", errs)
t.Errorf("unexpected errors %v", errs)
}
}
6 changes: 3 additions & 3 deletions pkg/kubelet/kubelet.go
Expand Up @@ -1562,7 +1562,7 @@ func checkHostPortConflicts(pods []api.Pod) (fitting []api.Pod, notFitting []api
func (kl *Kubelet) checkCapacityExceeded(pods []api.Pod) (fitting []api.Pod, notFitting []api.Pod) {
info, err := kl.GetCachedMachineInfo()
if err != nil {
glog.Error("error getting machine info: %v", err)
glog.Errorf("error getting machine info: %v", err)
return pods, []api.Pod{}
}

Expand Down Expand Up @@ -1780,7 +1780,7 @@ func (kl *Kubelet) tryUpdateNodeStatus() error {
// cAdvisor locally, e.g. for test-cmd.sh, and in integration test.
info, err := kl.GetCachedMachineInfo()
if err != nil {
glog.Error("error getting machine info: %v", err)
glog.Errorf("error getting machine info: %v", err)
} else {
node.Status.NodeInfo.MachineID = info.MachineID
node.Status.NodeInfo.SystemUUID = info.SystemUUID
Expand All @@ -1797,7 +1797,7 @@ func (kl *Kubelet) tryUpdateNodeStatus() error {

verinfo, err := kl.cadvisor.VersionInfo()
if err != nil {
glog.Error("error getting version info: %v", err)
glog.Errorf("error getting version info: %v", err)
} else {
node.Status.NodeInfo.KernelVersion = verinfo.KernelVersion
node.Status.NodeInfo.OsImage = verinfo.ContainerOsVersion
Expand Down
8 changes: 4 additions & 4 deletions pkg/kubelet/kubelet_test.go
Expand Up @@ -2858,7 +2858,7 @@ func TestHandlePortConflicts(t *testing.T) {
// Check pod status stored in the status map.
status, err := kl.GetPodStatus(conflictedPodName)
if err != nil {
t.Fatalf("status of pod %q is not found in the status map: ", conflictedPodName, err)
t.Fatalf("status of pod %q is not found in the status map: %#v", conflictedPodName, err)
}
if status.Phase != api.PodFailed {
t.Fatalf("expected pod status %q. Got %q.", api.PodFailed, status.Phase)
Expand Down Expand Up @@ -2964,7 +2964,7 @@ func TestHandleMemExceeded(t *testing.T) {
// Check pod status stored in the status map.
status, err := kl.GetPodStatus(notfittingPodName)
if err != nil {
t.Fatalf("status of pod %q is not found in the status map: ", notfittingPodName, err)
t.Fatalf("status of pod %q is not found in the status map: %#v", notfittingPodName, err)
}
if status.Phase != api.PodFailed {
t.Fatalf("expected pod status %q. Got %q.", api.PodFailed, status.Phase)
Expand All @@ -2974,7 +2974,7 @@ func TestHandleMemExceeded(t *testing.T) {
kl.podManager.SetPods(pods)
status, err = kl.GetPodStatus(notfittingPodName)
if err != nil {
t.Fatalf("unable to retrieve pod status for pod %q: #v.", notfittingPodName, err)
t.Fatalf("unable to retrieve pod status for pod %q: %#v.", notfittingPodName, err)
}
if status.Phase != api.PodFailed {
t.Fatalf("expected pod status %q. Got %q.", api.PodFailed, status.Phase)
Expand Down Expand Up @@ -3269,7 +3269,7 @@ func TestUpdateNodeStatusError(t *testing.T) {
kubeClient.MinionsList = api.NodeList{Items: []api.Node{}}

if err := kubelet.updateNodeStatus(); err == nil {
t.Errorf("unexpected non error: %v")
t.Errorf("unexpected non error: %v", err)
}
if len(kubeClient.Actions) != nodeStatusUpdateRetry {
t.Errorf("unexpected actions: %v", kubeClient.Actions)
Expand Down
10 changes: 5 additions & 5 deletions pkg/kubelet/server_test.go
Expand Up @@ -448,7 +448,7 @@ func TestPodsInfo(t *testing.T) {
}
result := string(body)
if !strings.Contains(result, "pod level status currently unimplemented") {
t.Errorf("expected body contains %s, got %d", "pod level status currently unimplemented", result)
t.Errorf("expected body contains pod level status currently unimplemented, got %s", result)
}
}

Expand Down Expand Up @@ -477,7 +477,7 @@ func TestHealthCheck(t *testing.T) {
}
result := string(body)
if !strings.Contains(result, "ok") {
t.Errorf("expected body contains %s, got %d", "ok", result)
t.Errorf("expected body contains ok, got %s", result)
}

//Test with incorrect hostname
Expand Down Expand Up @@ -822,7 +822,7 @@ func TestServeExecInContainer(t *testing.T) {
}

if e, a := test.responseStatusCode, resp.StatusCode; e != a {
t.Fatalf("%d: response status: expected %v, got %v", e, a)
t.Fatalf("%d: response status: expected %v, got %v", i, e, a)
}

if test.responseStatusCode != http.StatusSwitchingProtocols {
Expand Down Expand Up @@ -987,7 +987,7 @@ func TestServePortForward(t *testing.T) {

p, err := strconv.ParseUint(test.port, 10, 16)
if err != nil {
t.Fatalf("%d: error parsing port string '%s': %v", i, port, err)
t.Fatalf("%d: error parsing port string '%s': %v", i, test.port, err)
}
if e, a := uint16(p), port; e != a {
t.Fatalf("%d: port: expected '%v', got '%v'", i, e, a)
Expand Down Expand Up @@ -1035,7 +1035,7 @@ func TestServePortForward(t *testing.T) {
t.Fatalf("Unexpected error creating streaming connection: %s", err)
}
if conn == nil {
t.Fatal("%d: Unexpected nil connection", i)
t.Fatalf("%d: Unexpected nil connection", i)
}
defer conn.Close()

Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/status_manager_test.go
Expand Up @@ -78,7 +78,7 @@ func verifyUpdates(t *testing.T, manager *statusManager, expectedUpdates int) {
}

if numUpdates != expectedUpdates {
t.Errorf("unexpected number of updates %d, expected %s", numUpdates, expectedUpdates)
t.Errorf("unexpected number of updates %d, expected %d", numUpdates, expectedUpdates)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/labels/selector.go
Expand Up @@ -445,7 +445,7 @@ func (p *Parser) parse() ([]Requirement, error) {
case IdentifierToken:
r, err := p.parseRequirement()
if err != nil {
return nil, fmt.Errorf("unable to parse requiremnt: ", err)
return nil, fmt.Errorf("unable to parse requiremnt: %v", err)
}
requirements = append(requirements, *r)
t, l := p.consume(Values)
Expand Down
2 changes: 1 addition & 1 deletion pkg/labels/selector_test.go
Expand Up @@ -322,7 +322,7 @@ func TestToString(t *testing.T) {
}
for _, ts := range toStringTests {
if out := ts.In.String(); out == "" && ts.Valid {
t.Errorf("%+v.String() => '%v' expected no error", ts.In)
t.Errorf("%+v.String() => '%v' expected no error", ts.In, out)
} else if out != ts.Out {
t.Errorf("%+v.String() => '%v' want '%v'", ts.In, out, ts.Out)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/registry/service/ip_allocator_test.go
Expand Up @@ -267,11 +267,11 @@ func TestGetIndexedIPSubnetTooSmall(t *testing.T) {
_, subnet, _ := net.ParseCIDR(testCase.subnet)
secondIP, err := GetIndexedIP(subnet, 2)
if err == nil {
t.Errorf("Expected error but no error occured for subnet: ", testCase.subnet)
t.Errorf("Expected error but no error occured for subnet: %s", testCase.subnet)
}
thirdIP, err := GetIndexedIP(subnet, 3)
if err == nil {
t.Errorf("Expected error but no error occured for subnet: ", testCase.subnet)
t.Errorf("Expected error but no error occured for subnet: %s", testCase.subnet)
}
if secondIP != nil {
t.Errorf("Unexpected second IP: Expected nil Actual <%q>", thirdIP.String())
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/service/rest_test.go
Expand Up @@ -708,7 +708,7 @@ func TestServiceRegistryIPUpdate(t *testing.T) {

_, _, err := rest.Update(ctx, update)
if err == nil || !errors.IsInvalid(err) {
t.Error("Unexpected error type: %v", err)
t.Errorf("Unexpected error type: %v", err)
}
}

Expand Down

0 comments on commit 2de3762

Please sign in to comment.