Skip to content

Commit

Permalink
Update variable names (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbpann authored Jun 8, 2024
1 parent 9346d14 commit 0c32adc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 65 deletions.
76 changes: 29 additions & 47 deletions bucharest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,29 +85,20 @@ func TestNewContextWithOptionsWithAllAddtionalOptions(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, env)

// prepare Gorm
gorm := &gorm.DB{}

// Prepare Logrus
logrus := &logrus.Logger{}

// Prepare Redis
redis_ := &redis.Client{}

// Prepare sql
sql_ := &sql.DB{}

// Prepare sqlx
sqlx_ := &sqlx.DB{}
redis := &redis.Client{}
sql := &sql.DB{}
sqlx := &sqlx.DB{}

ctx := NewContextWithOptions(&ContextOptions{
Parent: context.Background(),
ENV: env,
GORM: gorm,
Logrus: logrus,
Redis: redis_,
SQL: sql_,
SQLX: sqlx_,
Redis: redis,
SQL: sql,
SQLX: sqlx,
})
if ctx == nil {
t.Fatalf("NewContext returned nil")
Expand All @@ -126,9 +117,9 @@ func TestNewContextWithOptionsWithAllAddtionalOptions(t *testing.T) {
assert.NoError(t, err)
assert.Same(t, gorm, ctx.GORM())
assert.Same(t, logrus, ctx.Log())
assert.Same(t, redis_, ctx.Redis())
assert.Same(t, sql_, ctx.SQL())
assert.Same(t, sqlx_, ctx.SQLX())
assert.Same(t, redis, ctx.Redis())
assert.Same(t, sql, ctx.SQL())
assert.Same(t, sqlx, ctx.SQLX())
}

func TestUpdateContext(t *testing.T) {
Expand Down Expand Up @@ -188,45 +179,36 @@ func TestUpdateContext(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, newENV)

// prepare Gorm
gorm_ := &gorm.DB{}

// Prepare Logrus
logrus_ := &logrus.Logger{}

// Prepare Redis
redis_ := &redis.Client{}

// Prepare sql
sql_ := &sql.DB{}

// Prepare sqlx
sqlx_ := &sqlx.DB{}
gorm := &gorm.DB{}
logrus := &logrus.Logger{}
redis := &redis.Client{}
sql := &sql.DB{}
sqlx := &sqlx.DB{}

assert.NotSame(t, newENV, ctx.ENV())
err = os.Remove(envTempPath)
assert.NoError(t, err)
assert.NotSame(t, gorm_, ctx.GORM())
assert.NotSame(t, logrus_, ctx.Log())
assert.NotSame(t, redis_, ctx.Redis())
assert.NotSame(t, sql_, ctx.SQL())
assert.NotSame(t, sqlx_, ctx.SQLX())
assert.NotSame(t, gorm, ctx.GORM())
assert.NotSame(t, logrus, ctx.Log())
assert.NotSame(t, redis, ctx.Redis())
assert.NotSame(t, sql, ctx.SQL())
assert.NotSame(t, sqlx, ctx.SQLX())

ctx.Update(&ContextOptions{
ENV: newENV,
GORM: gorm_,
Logrus: logrus_,
Redis: redis_,
SQL: sql_,
SQLX: sqlx_,
GORM: gorm,
Logrus: logrus,
Redis: redis,
SQL: sql,
SQLX: sqlx,
})

assert.Same(t, newENV, ctx.ENV())
assert.NoError(t, err)
assert.Same(t, gorm_, ctx.GORM())
assert.Same(t, logrus_, ctx.Log())
assert.Same(t, redis_, ctx.Redis())
assert.Same(t, sql_, ctx.SQL())
assert.Same(t, sqlx_, ctx.SQLX())
assert.Same(t, gorm, ctx.GORM())
assert.Same(t, logrus, ctx.Log())
assert.Same(t, redis, ctx.Redis())
assert.Same(t, sql, ctx.SQL())
assert.Same(t, sqlx, ctx.SQLX())

}
14 changes: 7 additions & 7 deletions error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ func (je *jsonError) Error() string {
}

func TestNewBadRequestError(t *testing.T) {
test_err := errors.New("fooooooooooo")
httpError := NewBadRequestError(test_err)
testErr := errors.New("fooooooooooo")
httpError := NewBadRequestError(testErr)
assert.NotEmpty(t, httpError)
assert.True(t, errors.Is(httpError.OriginalError(), test_err))
assert.True(t, errors.Is(httpError.OriginalError(), testErr))
}

func TestNewBadRequestErrorWithJSON(t *testing.T) {
test_err := &jsonError{
testErr := &jsonError{
"foo": "bar",
}
httpError := NewBadRequestError(test_err)
httpError := NewBadRequestError(testErr)
assert.NotEmpty(t, httpError)
assert.ErrorIs(t, httpError.OriginalError(), test_err)
assert.ErrorIs(t, httpError.OriginalError(), testErr)
serializable := httpError.GetJSON()
mapper := make(map[string]interface{})
err := utils.JSONMapper(serializable, &mapper)
assert.NoError(t, err)
jerr := &jsonError{}
err = utils.JSONMapper(mapper["message"], jerr)
assert.NoError(t, err)
assert.Equal(t, jerr, test_err)
assert.Equal(t, jerr, testErr)
}

func TestNewBadRequestErrorWithFromValidateError(t *testing.T) {
Expand Down
22 changes: 11 additions & 11 deletions gin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ func getCallingPath(method string, handler gin.HandlerFunc, middlewares ...gin.H
}
}
var err error
avaiable_port := fmt.Sprint(DEFAULT_TEST_PORT)
avaiablePort := fmt.Sprint(DEFAULT_TEST_PORT)
DEFAULT_TEST_PORT++
go func() { err = g.Run(fmt.Sprintf(":%s", avaiable_port)) }()
return fmt.Sprintf("http://0.0.0.0:%s/%s", avaiable_port, path), err
go func() { err = g.Run(fmt.Sprintf(":%s", avaiablePort)) }()
return fmt.Sprintf("http://0.0.0.0:%s/%s", avaiablePort, path), err
}

func getCallingPathWithParamterAndQuery(handler gin.HandlerFunc, param string, query map[string]string, middlewares ...gin.HandlerFunc) (string, error) {
Expand All @@ -73,10 +73,10 @@ func getCallingPathWithParamterAndQuery(handler gin.HandlerFunc, param string, q
}
g.GET(endpoint, handler)
var err error
avaiable_port := fmt.Sprint(DEFAULT_TEST_PORT)
avaiablePort := fmt.Sprint(DEFAULT_TEST_PORT)
DEFAULT_TEST_PORT++
go func() { err = g.Run(fmt.Sprintf(":%s", avaiable_port)) }()
url := fmt.Sprintf("http://0.0.0.0:%s/%s/%s", avaiable_port, path, param)
go func() { err = g.Run(fmt.Sprintf(":%s", avaiablePort)) }()
url := fmt.Sprintf("http://0.0.0.0:%s/%s/%s", avaiablePort, path, param)
if param == "" {
url = strings.TrimSuffix(url, "/")
}
Expand Down Expand Up @@ -180,8 +180,8 @@ func TestHandleFullPath(t *testing.T) {
var path string
handler := func(ctx HTTPContext) HTTPError {
split := strings.Split(path, "/")
handler_path := split[len(split)-1]
assert.Equal(t, fmt.Sprintf("/%s", handler_path), ctx.FullPath())
handlerPath := split[len(split)-1]
assert.Equal(t, fmt.Sprintf("/%s", handlerPath), ctx.FullPath())
ctx.Status(http.StatusNoContent)
return nil
}
Expand Down Expand Up @@ -209,9 +209,9 @@ func TestIP(t *testing.T) {
var path string
handler := func(ctx HTTPContext) HTTPError {
assert.Equal(t, ctx.Gin().ClientIP(), ctx.ClientIP())
remote_ip := ctx.RemoteIP()
expected_remote_ip := ctx.Gin().RemoteIP()
assert.Equal(t, remote_ip, expected_remote_ip)
remoteIp := ctx.RemoteIP()
expectedRemoteIp := ctx.Gin().RemoteIP()
assert.Equal(t, remoteIp, expectedRemoteIp)
ctx.Status(http.StatusNoContent)
return nil
}
Expand Down

0 comments on commit 0c32adc

Please sign in to comment.