Skip to content

Commit

Permalink
Grep fix formatting issues (knative#233)
Browse files Browse the repository at this point in the history
* Some fixes to the spoof.go and exporter.go

While reviewing some other CL, I saw some avenues for improving
spoof.go, to log the URL that's being fetched, which would help in test
debugging and to use switch construct, rather than nested if's.

While testing the change, I noticed some shifty loggin from the
exporter, so I fixed that as well while I was there.

* Continuation of the previous cleanups.

* Fix the issues with formatting by executing a grep

* and fix compilation error

* lowercase error

* fix the newly changed unit test
  • Loading branch information
vagababov authored and knative-prow-robot committed Jan 18, 2019
1 parent af675a5 commit a330baa
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 25 deletions.
6 changes: 3 additions & 3 deletions apis/duck/typed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func TestAsStructuredWatcherPassThru(t *testing.T) {
t.Errorf("<-ch = %T, wanted %T", x, &duckv1alpha1.Generational{})
}
case _ = <-time.After(100 * time.Millisecond):
t.Errorf("Didn't see expected message on channel.")
t.Error("Didn't see expected message on channel.")
}
}

Expand Down Expand Up @@ -205,7 +205,7 @@ func TestAsStructuredWatcherPassThruErrors(t *testing.T) {
t.Errorf("<-ch (-want, +got) = %v", diff)
}
case _ = <-time.After(100 * time.Millisecond):
t.Errorf("Didn't see expected message on channel.")
t.Error("Didn't see expected message on channel.")
}
}

Expand Down Expand Up @@ -248,7 +248,7 @@ func TestAsStructuredWatcherErrorConverting(t *testing.T) {
t.Errorf("<-ch = %v, wanted %v", got, want)
}
case _ = <-time.After(100 * time.Millisecond):
t.Errorf("Didn't see expected message on channel.")
t.Error("Didn't see expected message on channel.")
}
}

Expand Down
3 changes: 2 additions & 1 deletion changeset/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package changeset

import (
"errors"
"fmt"
"os"
"testing"
Expand Down Expand Up @@ -59,7 +60,7 @@ func TestReadFile(t *testing.T) {
name: "HEAD file does not exist",
koDataPath: "testdata/nonexisting",
wantErr: true,
err: fmt.Errorf("open testdata/nonexisting/HEAD: no such file or directory"),
err: errors.New("open testdata/nonexisting/HEAD: no such file or directory"),
}}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion cloudevents/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cloudevents
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -114,7 +115,7 @@ func validateOutParamSignature(fnType reflect.Type) error {
// of allowed types. If successful, returns the expected in-param type, otherwise panics.
func validateFunction(fnType reflect.Type) errAndHandler {
if fnType.Kind() != reflect.Func {
return &failedHandler{err: fmt.Errorf("Must pass a function to handle events")}
return &failedHandler{err: errors.New("must pass a function to handle events")}
}
err := anyError(
validateInParamSignature(fnType),
Expand Down
2 changes: 1 addition & 1 deletion cloudevents/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestHandlerTypeErrors(t *testing.T) {
{
name: "non-func",
param: 5,
err: "Must pass a function to handle events",
err: "must pass a function to handle events",
},
{
name: "wrong param count",
Expand Down
4 changes: 2 additions & 2 deletions kmp/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ func TestRecovery(t *testing.T) {

want := recoveryErrorMessageFor("SafeDiff")
if _, err := SafeDiff(a, b); err == nil {
t.Errorf("expected err, got nil")
t.Error("expected err, got nil")
} else if diff := cmp.Diff(want, err.Error()); diff != "" {
t.Errorf("SafeDiff (-want, +got): %v", diff)
}

want = recoveryErrorMessageFor("SafeEqual")
if _, err := SafeEqual(a, b); err == nil {
t.Errorf("expected err, got nil")
t.Error("expected err, got nil")
} else if diff := cmp.Diff(want, err.Error()); diff != "" {
t.Errorf("SafeEqual (-want, +got): %v", diff)
}
Expand Down
5 changes: 2 additions & 3 deletions test/spoof/spoof.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,10 @@ func (sc *SpoofingClient) LogZipkinTrace(traceID string) error {
}

var prettyJSON bytes.Buffer
error := json.Indent(&prettyJSON, trace, "", "\t")
if error != nil {
if error := json.Indent(&prettyJSON, trace, "", "\t"); error != nil {
return fmt.Errorf("JSON Parser Error while trying for Pretty-Format: %v, Original Response: %s", error, string(trace))
}
sc.logger.Infof(prettyJSON.String())
sc.logger.Info(prettyJSON.String())

return nil
}
15 changes: 8 additions & 7 deletions test/zipkin/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ const (

var zipkinPortForwardPID int

// SetupZipkinTracing sets up zipkin tracing which involves a) Setting up port-forwarding from localhost to zipkin pod on the cluster (pid of the process doing Port-Forward is stored in a global variable).
// b) enable AlwaysSample config for tracing.
// SetupZipkinTracing sets up zipkin tracing which involves:
// 1. Setting up port-forwarding from localhost to zipkin pod on the cluster
// (pid of the process doing Port-Forward is stored in a global variable).
// 2. Enable AlwaysSample config for tracing.
func SetupZipkinTracing(kubeClientset *kubernetes.Clientset) error {
logger := logging.GetContextLogger("SpoofUtil")

Expand All @@ -61,7 +63,7 @@ func SetupZipkinTracing(kubeClientset *kubernetes.Clientset) error {

zipkinPods, err := kubeClientset.CoreV1().Pods(ZipkinNamespace).List(metav1.ListOptions{LabelSelector: "app=zipkin"})
if err != nil {
return fmt.Errorf("Error retrieving Zipkin pod details : %v", err)
return fmt.Errorf("Error retrieving Zipkin pod details: %v", err)
}

if len(zipkinPods.Items) == 0 {
Expand All @@ -70,16 +72,15 @@ func SetupZipkinTracing(kubeClientset *kubernetes.Clientset) error {

portForwardCmd := exec.Command("kubectl", "port-forward", "--namespace="+ZipkinNamespace, zipkinPods.Items[0].Name, fmt.Sprintf("%d:%d", ZipkinPort, ZipkinPort))
if err = portForwardCmd.Start(); err != nil {
return fmt.Errorf("Error starting kubectl port-forward command : %v", err)

return fmt.Errorf("Error starting kubectl port-forward command: %v", err)
}
zipkinPortForwardPID = portForwardCmd.Process.Pid
logger.Infof("Zipkin port-forward process started with PID: %d", zipkinPortForwardPID)

// Applying AlwaysSample config to ensure we propagate zipkin header for every request made by this client.
trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()})

logger.Infof("Successfully setup SpoofingClient for Zipkin Tracing")
logger.Info("Successfully setup SpoofingClient for Zipkin Tracing")

return nil
}
Expand All @@ -93,7 +94,7 @@ func CleanupZipkinTracingSetup() error {
return fmt.Errorf("Encoutered error killing port-forward process in CleanupZipkingTracingSetup() : %v", err)
}

logger.Infof("Successfully killed Zipkin port-forward process")
logger.Info("Successfully killed Zipkin port-forward process")
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion tracker/enqueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestHappyPaths(t *testing.T) {
t.Errorf("OnChanged() = %v, wanted %v", got, want)
}
if _, stillThere := trk.(*impl).mapping[objRef]; stillThere {
t.Errorf("Timeout passed, but mapping for objectReference is still there")
t.Error("Timeout passed, but mapping for objectReference is still there")
}
})

Expand Down
6 changes: 3 additions & 3 deletions webhook/webhook_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestEmptyRequestBody(t *testing.T) {
}

if !strings.Contains(string(responseBody), "could not decode body") {
t.Errorf("Response body to contain 'decode failure information' , got = '%s'", string(responseBody))
t.Errorf("Response body to contain 'decode failure information' , got = %q", string(responseBody))
}
}

Expand Down Expand Up @@ -402,10 +402,10 @@ func TestSetupWebhookHTTPServerError(t *testing.T) {

select {
case <-time.After(6 * time.Second):
t.Errorf("Timeout in testing bootstrap webhook http server failed\n")
t.Error("Timeout in testing bootstrap webhook http server failed")
case errItem := <-errCh:
if !strings.Contains(errItem.Error(), "bootstrap failed") {
t.Errorf("Expected bootstrap webhook http server failed\n")
t.Error("Expected bootstrap webhook http server failed")
}
}
}
6 changes: 3 additions & 3 deletions webhook/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,11 @@ func expectAllowed(t *testing.T, resp *admissionv1beta1.AdmissionResponse) {
func expectFailsWith(t *testing.T, resp *admissionv1beta1.AdmissionResponse, contains string) {
t.Helper()
if resp.Allowed {
t.Errorf("expected denial, got allowed")
t.Error("Expected denial, got allowed")
return
}
if !strings.Contains(resp.Result.Message, contains) {
t.Errorf("expected failure containing %q got %q", contains, resp.Result.Message)
t.Errorf("Expected failure containing %q got %q", contains, resp.Result.Message)
}
}

Expand All @@ -484,7 +484,7 @@ func expectPatches(t *testing.T, a []byte, e []jsonpatch.JsonPatchOperation) {

err := json.Unmarshal(a, &got)
if err != nil {
t.Errorf("failed to unmarshal patches: %s", err)
t.Errorf("Failed to unmarshal patches: %s", err)
return
}

Expand Down

0 comments on commit a330baa

Please sign in to comment.