Add a Failf utility function for 'Fail(fmt.Sprintf())' and convert one file

This commit is contained in:
Zach Loafman 2015-02-09 17:02:11 -08:00
parent 251bb585bd
commit 6b3746896f
2 changed files with 13 additions and 10 deletions

View File

@ -120,9 +120,8 @@ func ServeImageOrFail(c *client.Client, test string, image string) {
break break
} }
if time.Since(t) > listTimeout { if time.Since(t) > listTimeout {
Fail(fmt.Sprintf( Failf("Controller %s: Gave up waiting for %d pods to come up after seeing only %d pods after %v seconds",
"Controller %s: Gave up waiting for %d pods to come up after seeing only %d pods after %v seconds", name, replicas, len(pods.Items), time.Since(t).Seconds())
name, replicas, len(pods.Items), time.Since(t).Seconds()))
} }
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
pods, err = c.Pods(ns).List(label) pods, err = c.Pods(ns).List(label)
@ -150,8 +149,8 @@ func ServeImageOrFail(c *client.Client, test string, image string) {
break break
} }
if time.Since(t) >= hostIPTimeout { if time.Since(t) >= hostIPTimeout {
Fail(fmt.Sprintf("Controller %s: Gave up waiting for hostIP of replica %d after %v seconds", Failf("Controller %s: Gave up waiting for hostIP of replica %d after %v seconds",
name, i, time.Since(t).Seconds())) name, i, time.Since(t).Seconds())
} }
Logf("Controller %s: Retrying to get the hostIP of replica %d", name, i+1) Logf("Controller %s: Retrying to get the hostIP of replica %d", name, i+1)
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
@ -168,20 +167,20 @@ func ServeImageOrFail(c *client.Client, test string, image string) {
for i, pod := range pods.Items { for i, pod := range pods.Items {
resp, err := http.Get(fmt.Sprintf("http://%s:8080", pod.Status.HostIP)) resp, err := http.Get(fmt.Sprintf("http://%s:8080", pod.Status.HostIP))
if err != nil { if err != nil {
Fail(fmt.Sprintf("Controller %s: Failed to GET from replica %d: %v", name, i+1, err)) Failf("Controller %s: Failed to GET from replica %d: %v", name, i+1, err)
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
Fail(fmt.Sprintf("Controller %s: Expected OK status code for replica %d but got %d", name, i+1, resp.StatusCode)) Failf("Controller %s: Expected OK status code for replica %d but got %d", name, i+1, resp.StatusCode)
} }
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
Fail(fmt.Sprintf("Controller %s: Failed to read the body of the GET response from replica %d: %v", Failf("Controller %s: Failed to read the body of the GET response from replica %d: %v",
name, i+1, err)) name, i+1, err)
} }
// The body should be the pod name. // The body should be the pod name.
if string(body) != pod.Name { if string(body) != pod.Name {
Fail(fmt.Sprintf("Controller %s: Replica %d expected response %s but got %s", name, i+1, pod.Name, string(body))) Failf("Controller %s: Replica %d expected response %s but got %s", name, i+1, pod.Name, string(body))
} }
Logf("Controller %s: Got expected result from replica %d: %s", name, i+1, string(body)) Logf("Controller %s: Got expected result from replica %d: %s", name, i+1, string(body))
} }

View File

@ -44,6 +44,10 @@ func Logf(format string, a ...interface{}) {
fmt.Fprintf(GinkgoWriter, "INFO: "+format+"\n", a...) fmt.Fprintf(GinkgoWriter, "INFO: "+format+"\n", a...)
} }
func Failf(format string, a ...interface{}) {
Fail(fmt.Sprintf(format, a...))
}
func waitForPodRunning(c *client.Client, id string, tryFor time.Duration) error { func waitForPodRunning(c *client.Client, id string, tryFor time.Duration) error {
trySecs := int(tryFor.Seconds()) trySecs := int(tryFor.Seconds())
for i := 0; i <= trySecs; i += 5 { for i := 0; i <= trySecs; i += 5 {