Skip to content

Commit

Permalink
feat: [#441] Optimize the HTTP testing process [#1] (#704)
Browse files Browse the repository at this point in the history
* implement http testing

* optimize code

* chore: update mocks

* fix code review

* chore: update mocks

* optimize cookies expiration logic

* add test cases for test_response

* fix:lint

* use response recorder

* update go mod

* change cookie value type to string

* chore: update mocks

* remove mutex

* update test response

* add more test cases for test response

* driver specific http testing process

* directly use r.t

* use Test method for testing

* update cookie assertion logic

* .

* add isCookieExpired Method

* optimize cookie expiration logic

---------

Co-authored-by: kkumar-gcc <kkumar-gcc@users.noreply.github.com>
  • Loading branch information
kkumar-gcc and kkumar-gcc authored Nov 1, 2024
1 parent 1404bff commit 8b33e6b
Show file tree
Hide file tree
Showing 13 changed files with 2,432 additions and 5 deletions.
10 changes: 10 additions & 0 deletions contracts/testing/test_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package testing

type TestRequest interface {
WithHeaders(headers map[string]string) TestRequest
WithHeader(key, value string) TestRequest
WithoutHeader(key string) TestRequest
WithCookies(cookies map[string]string) TestRequest
WithCookie(key, value string) TestRequest
Get(uri string) (TestResponse, error)
}
35 changes: 35 additions & 0 deletions contracts/testing/test_response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package testing

type TestResponse interface {
AssertStatus(status int) TestResponse
AssertOk() TestResponse
AssertCreated() TestResponse
AssertAccepted() TestResponse
AssertNoContent(status ...int) TestResponse
AssertMovedPermanently() TestResponse
AssertFound() TestResponse
AssertNotModified() TestResponse
AssertPartialContent() TestResponse
AssertTemporaryRedirect() TestResponse
AssertBadRequest() TestResponse
AssertUnauthorized() TestResponse
AssertPaymentRequired() TestResponse
AssertForbidden() TestResponse
AssertNotFound() TestResponse
AssertMethodNotAllowed() TestResponse
AssertNotAcceptable() TestResponse
AssertConflict() TestResponse
AssertRequestTimeout() TestResponse
AssertGone() TestResponse
AssertUnsupportedMediaType() TestResponse
AssertUnprocessableEntity() TestResponse
AssertTooManyRequests() TestResponse
AssertInternalServerError() TestResponse
AssertServiceUnavailable() TestResponse
AssertHeader(headerName, value string) TestResponse
AssertHeaderMissing(headerName string) TestResponse
AssertCookie(name, value string) TestResponse
AssertCookieExpired(name string) TestResponse
AssertCookieNotExpired(name string) TestResponse
AssertCookieMissing(name string) TestResponse
}
2 changes: 1 addition & 1 deletion database/factory/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/brianvoe/gofakeit/v6"
"github.com/brianvoe/gofakeit/v7"
"github.com/stretchr/testify/suite"
gormio "gorm.io/gorm"

Expand Down
1 change: 1 addition & 0 deletions errors/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var (
ScheduleFacadeNotSet = New("schedule facade is not initialized")
StorageFacadeNotSet = New("storage facade is not initialized")
InvalidHttpContext = New("invalid http context")
RouteFacadeNotSet = New("route facade is not initialized")

AuthEmptySecret = New("authentication secret is missing or required")
AuthInvalidClaims = New("authentication token contains invalid claims")
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ go 1.22.0
require (
github.com/RichardKnop/machinery/v2 v2.0.13
github.com/brianvoe/gofakeit/v7 v7.1.1
github.com/brianvoe/gofakeit/v7 v7.1.1
github.com/charmbracelet/huh v0.6.0
github.com/charmbracelet/huh/spinner v0.0.0-20241028115900-20a4d21717a8
github.com/charmbracelet/lipgloss v0.13.1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/gabriel-vasile/mimetype v1.4.6
github.com/glebarez/go-sqlite v1.22.0
github.com/glebarez/sqlite v1.11.0
github.com/go-sql-driver/mysql v1.8.1
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/golang-migrate/migrate/v4 v4.18.1
github.com/golang-module/carbon/v2 v2.4.1
Expand Down Expand Up @@ -80,6 +78,7 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/go-redsync/redsync/v4 v4.8.1 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
Expand Down
3 changes: 1 addition & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ github.com/aws/aws-sdk-go v1.49.6/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3Tju
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
github.com/brianvoe/gofakeit/v6 v6.28.0 h1:Xib46XXuQfmlLS2EXRuJpqcw8St6qSZz75OUo0tgAW4=
github.com/brianvoe/gofakeit/v6 v6.28.0/go.mod h1:Xj58BMSnFqcn/fAQeSK+/PLtC5kSb7FJIq4JyGa8vEs=
github.com/brianvoe/gofakeit/v7 v7.1.1 h1:/DEG+f/mFtqqNjhZ0AXA0aDzrnfE85AcAKVE+mMdxAQ=
github.com/brianvoe/gofakeit/v7 v7.1.1/go.mod h1:QXuPeBw164PJCzCUZVmgpgHJ3Llj49jSLVkKPMtxtxA=
github.com/bsm/ginkgo/v2 v2.5.0/go.mod h1:AiKlXPm7ItEHNc/2+OkrNG4E0ITzojb9/xWzvQ9XZ9w=
github.com/bsm/ginkgo/v2 v2.7.0/go.mod h1:AiKlXPm7ItEHNc/2+OkrNG4E0ITzojb9/xWzvQ9XZ9w=
Expand Down
Loading

0 comments on commit 8b33e6b

Please sign in to comment.