<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] ## demo 使用 httptest.NewRecorder 來測試 HTTP Handler 而不需要真正進行 HTTP 監聽 可以使用 errorReader 來提高測試覆蓋率 ``` ype errorReader struct{} func (errorReader) Read(p []byte) (n int, err error) { return 0, errors.New("mock body error") } func TestLoginHandler(t *testing.T) { testCases := []struct { Name string Code int Body interface{} }{ {"ok", 200, `{"code":"a@example.com", "password":"password"}`}, {"read body error", 500, new(errorReader)}, {"invalid format", 400, `{"code":1, "password":"password"}`}, {"invalid code", 400, `{"code":"a@example.com1", "password":"password"}`}, {"invalid password", 400, `{"code":"a@example.com", "password":"password1"}`}, } for _, tc := range testCases { t.Run(tc.Name, func(t *testing.T) { var body io.Reader if stringBody, ok := tc.Body.(string); ok { body = strings.NewReader(stringBody) } else { body = tc.Body.(io.Reader) } req := httptest.NewRequest("POST", "http://example.com/foo", body) w := httptest.NewRecorder() LoginHandler(w, req) resp := w.Result() if resp.StatusCode != tc.Code { t.Errorf("response code is invalid, expect=%d but got=%d", tc.Code, resp.StatusCode) } }) } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看