1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

GO言語でリダイレクトのテスト

Last updated at Posted at 2020-04-22

リダイレクトのテスト

書くほどのことでもないですが、リダイレクトのテストの記事がなかったので、書いてみました

func TestAuthLogin_Success(t *testing.T) {
	router := newAuthTestHandler()

	req, _ := http.NewRequest("POST", "/auth/login", nil)
	rr := httptest.NewRecorder()

	router.ServeHTTP(rr, req)
	assert.Equal(t, http.StatusFound, rr.Code) // ステータスコードの検証
	assert.Equal(t, "/", rr.HeaderMap.Get("Location")) //リダイレクト先の検証
}

下の2行でステータスとリダイレクト先の検証を行なっています。
以上です!

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?