5538: update the test case for "error" to use better stub parameters with nil status...
authorradhika <radhika@curoverse.com>
Mon, 9 Nov 2015 18:49:31 +0000 (13:49 -0500)
committerradhika <radhika@curoverse.com>
Mon, 9 Nov 2015 18:49:31 +0000 (13:49 -0500)
sdk/go/arvadosclient/arvadosclient_test.go

index f5ce338af19f303f4d080e7f0e242398be9d8a7b..045acf81e7c9d50ee904d3b19fe9301c90e382bb 100644 (file)
@@ -7,7 +7,6 @@ import (
        "net"
        "net/http"
        "os"
-       "strings"
        "testing"
        "time"
 )
@@ -314,13 +313,13 @@ func (s *MockArvadosServerSuite) TestWithRetries(c *C) {
                {
                        "get", 0, 401, []int{500, 401, 200}, []string{``, ``, `{"ok":"ok"}`},
                },
-               // Use expected = 0 to simulate error during request processing
+               // Use nil responseBody to simulate error during request processing
                // Even though retryable, the simulated error applies during reties also, and hence "get" also eventually fails in this test.
                {
-                       "get", 0, 0, []int{500, 500, 500}, []string{``, ``, ``},
+                       "get", 0, -1, nil, nil,
                },
                {
-                       "create", 0, 0, []int{500, 500, 500}, []string{``, ``, ``},
+                       "create", 0, -1, nil, nil,
                },
        } {
                api, err := RunFakeArvadosServer(&stub)
@@ -336,9 +335,9 @@ func (s *MockArvadosServerSuite) TestWithRetries(c *C) {
                        Client:      &http.Client{Transport: &http.Transport{}},
                        Retries:     2}
 
-               // We use expected = 0 to look for errors during request processing
+               // We use nil responseBody to look for errors during request processing
                // Simulate an error using https (but the arv.Client transport used does not support it)
-               if stub.expected == 0 {
+               if stub.responseBody == nil {
                        arv.Scheme = "https"
                }
 
@@ -364,10 +363,10 @@ func (s *MockArvadosServerSuite) TestWithRetries(c *C) {
                } else {
                        c.Check(err, NotNil)
 
-                       if stub.expected == 0 { // test uses 0 to look for errors during request processing
-                               c.Check(strings.Contains(err.Error(), fmt.Sprintf("%s", "tls: oversized record received")), Equals, true)
+                       if stub.responseBody == nil { // test uses empty responseBody to look for errors during request processing
+                               c.Assert(err, ErrorMatches, "* oversized record received.*")
                        } else {
-                               c.Check(strings.Contains(err.Error(), fmt.Sprintf("%s%d", "arvados API server error: ", stub.expected)), Equals, true)
+                               c.Assert(err, ErrorMatches, fmt.Sprintf("%s%d.*", "arvados API server error: ", stub.expected))
                                c.Assert(err.(APIServerError).HttpStatusCode, Equals, stub.expected)
                        }
                }