(t *testing.T)
| 121 | } |
| 122 | |
| 123 | func TestStatusCodes(t *testing.T) { |
| 124 | for i := 200; i < 600; i++ { |
| 125 | t.Run(fmt.Sprintf("status: %d", i), func(t *testing.T) { |
| 126 | url := fmt.Sprintf("status-%d", i) |
| 127 | |
| 128 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 129 | _, _ = ioutil.ReadAll(io.Reader(r.Body)) |
| 130 | w.WriteHeader(i) |
| 131 | })) |
| 132 | |
| 133 | defer ts.Close() |
| 134 | |
| 135 | client := newRuntimeAPIClient(serverAddress(ts)) |
| 136 | invoke := &invoke{id: url, client: client, payload: bytes.NewBuffer(nil)} |
| 137 | if i == http.StatusOK { |
| 138 | t.Run("next should not error", func(t *testing.T) { |
| 139 | _, err := client.next(context.Background()) |
| 140 | require.NoError(t, err) |
| 141 | }) |
| 142 | } else { |
| 143 | t.Run("next should error", func(t *testing.T) { |
| 144 | _, err := client.next(context.Background()) |
| 145 | require.Error(t, err) |
| 146 | if i != 301 && i != 302 && i != 303 { |
| 147 | assert.Contains(t, err.Error(), "unexpected status code") |
| 148 | assert.Contains(t, err.Error(), fmt.Sprintf("%d", i)) |
| 149 | } |
| 150 | }) |
| 151 | } |
| 152 | |
| 153 | if i == http.StatusAccepted { |
| 154 | t.Run("success should not error", func(t *testing.T) { |
| 155 | err := invoke.success(nil, "") |
| 156 | require.NoError(t, err) |
| 157 | }) |
| 158 | t.Run("failure should not error", func(t *testing.T) { |
| 159 | err := invoke.failure(nil, "", nil) |
| 160 | require.NoError(t, err) |
| 161 | }) |
| 162 | } else { |
| 163 | t.Run("success should error", func(t *testing.T) { |
| 164 | err := invoke.success(nil, "") |
| 165 | require.Error(t, err) |
| 166 | if i != 301 && i != 302 && i != 303 { |
| 167 | assert.Contains(t, err.Error(), "unexpected status code") |
| 168 | assert.Contains(t, err.Error(), fmt.Sprintf("%d", i)) |
| 169 | } |
| 170 | }) |
| 171 | t.Run("failure should error", func(t *testing.T) { |
| 172 | err := invoke.failure(nil, "", nil) |
| 173 | require.Error(t, err) |
| 174 | if i != 301 && i != 302 && i != 303 { |
| 175 | assert.Contains(t, err.Error(), "unexpected status code") |
| 176 | assert.Contains(t, err.Error(), fmt.Sprintf("%d", i)) |
| 177 | } |
| 178 | }) |
| 179 | } |
| 180 | }) |
nothing calls this directly
no test coverage detected
searching dependent graphs…