From 5aba242993ec391b2ab2b94d91de6fcde6b17055 Mon Sep 17 00:00:00 2001
From: Paras-Wednesday
Date: Thu, 26 Sep 2024 20:33:32 +0530
Subject: [PATCH] fix: linter errors
---
README.MD | 105 ++++++++++------------
pkg/utl/rediscache/redis_test.go | 13 ++-
pkg/utl/rediscache/service_test.go | 75 ++++++++--------
pkg/utl/resultwrapper/error.go | 6 +-
pkg/utl/resultwrapper/error_test.go | 24 ++---
pkg/utl/zaplog/zaplog_test.go | 2 +-
resolver/auth_mutations.resolvers_test.go | 40 ++++-----
7 files changed, 127 insertions(+), 138 deletions(-)
diff --git a/README.MD b/README.MD
index 74607454..a844c2a5 100644
--- a/README.MD
+++ b/README.MD
@@ -13,7 +13,6 @@ An enterprise go template application showcasing - Testing strategies, middlewar
___
-
Expert teams of digital product strategists, developers, and designers.
@@ -28,23 +27,17 @@ An enterprise go template application showcasing - Testing strategies, middlewar
-
- ___
+ ---
We’re always looking for people who value their work, so come and join
us. We are hiring!
-
---
-
-
-
-
The Go Template is a template/starter go project.
## Out of the box support for
@@ -72,24 +65,24 @@ to configure the following:
3. Install the sqlboiler, sql-migrate and gqlgen using
+```bash
+go get -v github.com/rubenv/sql-migrate/... \
+github.com/volatiletech/sqlboiler \
+github.com/99designs/gqlgen
```
- go get -v github.com/rubenv/sql-migrate/... \
- github.com/volatiletech/sqlboiler \
- github.com/99designs/gqlgen
- ```
For Go 1.16 or above, you need to install sqlboiler using
- ```
- go install github.com/volatiletech/sqlboiler/v4@latest
- go install github.com/volatiletech/sqlboiler/v4/drivers/sqlboiler-psql@latest
- ```
+```bash
+go install github.com/volatiletech/sqlboiler/v4@latest
+go install github.com/volatiletech/sqlboiler/v4/drivers/sqlboiler-psql@latest
+```
For Go 1.18 and above install the sql-migrate using
- ```
- go install github.com/rubenv/sql-migrate/...@latest
- ```
+```bash
+go install github.com/rubenv/sql-migrate/...@latest
+```
4. To run all the migrations using the script setup-local.sh as follows `make setup-local`.
@@ -101,20 +94,20 @@ For Go 1.18 and above install the sql-migrate using
go run cmd/server/main.go
```
-**NOTE:** Please do not delete ```.env.base``` file of the project and rebuild the using docker-compose everytime you
+**NOTE:** Please do not delete `.env.base` file of the project and rebuild the using docker-compose everytime you
make changes to it
# Setting up database (postgres)
- Requirement [postgresql](https://www.postgresql.org/)
-Steps to set up database with ```username``` and ```role``` using terminal
+Steps to set up database with `username` and `role` using terminal
-- Enter postgres terminal ```psql postgres```
-- Create new database ```CREATE DATABASE go_template;```
-- Create a new role with password ```CREATE ROLE go_template_role WITH LOGIN PASSWORD 'go_template_role456';```
+- Enter postgres terminal `psql postgres`
+- Create new database `CREATE DATABASE go_template;`
+- Create a new role with password `CREATE ROLE go_template_role WITH LOGIN PASSWORD 'go_template_role456';`
-**NOTE:** Replace these credentials in ```.env``` file of the project
+**NOTE:** Replace these credentials in `.env` file of the project
# Using Docker
@@ -132,27 +125,27 @@ Set up signoz locally by following the steps [here](https://signoz.io/docs/insta
# Running migrations
-Migrations are present in ```internal/migrations``` package. Run below command to run all migrations at once:
+Migrations are present in `internal/migrations` package. Run below command to run all migrations at once:
-```
+```bash
sql-migrate up -env postgres
```
To drop migration use following
-```
+```bash
sql-migrate down -env postgres -limit=0
```
To check status of migration use following
-```
+```bash
sql-migrate new -env postgres
```
To add new migration use following, it creates a new empty migration template with pattern `-.sql`
-```
+```bash
sql-migrate new -env postgres
```
@@ -203,7 +196,7 @@ go-template/
│ └──line-formatter.sh # auto format to adhere to the lll.line-length criteria
└──schema/ # this directory will have all the .graphql files which make the graphql api
└──.env.local # a sample .env file for reference
-└──.env.base # a base .env file should be included in all environments
+└──.env.base # a base .env file should be included in all environments
└──.pre-commit-config.yaml # config to run pre-commit utility
└──docker-compose.*.yml # docker-compose file corresponding to the state of project (local, prod, test)
└──docker-compose.yml # docker-compose file which serves as a base to other docker-compose files
@@ -220,7 +213,7 @@ go-template/
generate your database models
-```
+```bash
sqlboiler psql --no-hooks
```
@@ -228,8 +221,9 @@ sqlboiler psql --no-hooks
For seeding Your database models use
-```
-go run cmd/seeder/exec/seed.go
+```bash
+go run cmd/seeder/main.go ## to build the execs for seeding
+go run cmd/seeder/exec/seed.go ## to seed
```
Note: We have Seeder directory because we are using it while building docker image for application
@@ -238,19 +232,19 @@ Note: We have Seeder directory because we are using it while building docker ima
generate the graphql models from the database schema
-```
+```bash
gqlgen generate
```
## API (for graphQL to operate)
-- Graphql endpoint ```POST``` request ```/graphql```
+- Graphql endpoint `POST` request `/graphql`
-- Playground endpoint for schema ```/playground```
+- Playground endpoint for schema `/playground`
Take a look at the following file
- - [pkg/api/api.go](pkg/api/api.go)
+ - [pkg/api/api.go](pkg/api/api.go)
## Schema
@@ -258,13 +252,13 @@ gqlgen generate
Take a look at the following folder
- - [schema](./schema/)
+ - [schema](./schema/)
## Resolver
- Queries and mutation are autogenerated using gqlgen and are to be extended. Take a look at the following files
- - [resolver](./resolver)
+ - [resolver](./resolver)
## Infrastructure
@@ -279,7 +273,7 @@ gqlgen generate
Application name should container only lowercase letters. No hyphens and underscores or any other special characters.
-```
+```bash
make setup-ecs name=gotemplate env=dev
```
@@ -287,31 +281,28 @@ Please change the ENV_INJECTION variable as true in .env.base file to true, so i
Also add the environment variables to the task,add this block of yml code in ${service name}/manifest.yaml:
-```
-
-variables:
- ENVIRONMENT_NAME: develop
+```yaml
+variables:
+ ENVIRONMENT_NAME: develop
- #to inject our .env file from aws s3 inside the container
+ #to inject our .env file from aws s3 inside the container
taskdef_overrides:
- path: ContainerDefinitions[0].EnvironmentFiles[0]
value:
- type: 's3'
- value: 'arn:aws:s3:::gotemplate-dev-bucket/develop/.env'
-
+ type: "s3"
+ value: "arn:aws:s3:::gotemplate-dev-bucket/develop/.env"
```
Make sure that the manifest.yml has http.path: '/'
-```
+```yaml
http:
# Requests to this path will be forwarded to your service.
# To match all requests you can use the "/" path.
- path: '/'
+ path: "/"
# You can specify a custom health check path. The default is "/".
# healthcheck: '/'
-
```
Also make sure the execution role has an appropriate policy attached to it so it can access our .env file inside the s3
@@ -319,13 +310,13 @@ bucket, and inject it as environment variables.
### To deploy
-```
+```bash
make deploy-ecs name=gotemplate env=dev
```
### Update infrastructure
-```
+```bash
make update-ecs name=gotemplate env=dev
```
@@ -333,7 +324,7 @@ make update-ecs name=gotemplate env=dev
Get test coverage using
-```
+```bash
go test -cover
```
@@ -341,13 +332,13 @@ go test -cover
Install Mockgen Using
-```
+```bash
go install github.com/gleisonmv/mockgen@latest
```
Sample command to generate mocks
-```
+```bash
mockgen --build_flags=--mod=mod github.com/go-playground/validator FieldError
```
diff --git a/pkg/utl/rediscache/redis_test.go b/pkg/utl/rediscache/redis_test.go
index fb8ee8f0..93975fd7 100644
--- a/pkg/utl/rediscache/redis_test.go
+++ b/pkg/utl/rediscache/redis_test.go
@@ -7,7 +7,6 @@ import (
"testing"
. "github.com/agiledragon/gomonkey/v2"
- "github.com/gomodule/redigo/redis"
redigo "github.com/gomodule/redigo/redis"
redigomock "github.com/rafaeljusto/redigomock/v3"
)
@@ -38,11 +37,11 @@ func Test_redisDial(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.wantErr {
- ApplyFunc(redigo.Dial, func(string, string, ...redis.DialOption) (redis.Conn, error) {
+ ApplyFunc(redigo.Dial, func(string, string, ...redigo.DialOption) (redigo.Conn, error) {
return nil, fmt.Errorf("some error")
})
} else {
- ApplyFunc(redigo.Dial, func(string, string, ...redis.DialOption) (redis.Conn, error) {
+ ApplyFunc(redigo.Dial, func(string, string, ...redigo.DialOption) (redigo.Conn, error) {
return redigoConn, nil
})
}
@@ -92,7 +91,7 @@ func TestSetKeyValue(t *testing.T) {
wantErr: true,
},
}
- ApplyFunc(redigo.Dial, func(string, string, ...redis.DialOption) (redis.Conn, error) {
+ ApplyFunc(redigo.Dial, func(string, string, ...redigo.DialOption) (redigo.Conn, error) {
return redigoConn, nil
})
for _, tt := range tests {
@@ -100,13 +99,13 @@ func TestSetKeyValue(t *testing.T) {
var patches *Patches
b, _ := json.Marshal(tt.args.data)
if tt.name == FailedCase {
- patches = ApplyFunc(redigo.Dial, func(string, string, ...redis.DialOption) (redis.Conn, error) {
+ patches = ApplyFunc(redigo.Dial, func(string, string, ...redigo.DialOption) (redigo.Conn, error) {
return nil, fmt.Errorf("some error")
})
}
if tt.name == ErrorMarshal {
patchJson := ApplyFunc(json.Marshal, func(v any) ([]byte, error) {
- return nil, fmt.Errorf(ErrMsgMarshal)
+ return nil, fmt.Errorf("%s", ErrMsgMarshal)
})
defer patchJson.Reset()
}
@@ -150,7 +149,7 @@ func TestGetKeyValue(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
var patches *Patches
if tt.wantErr {
- patches = ApplyFunc(redigo.Dial, func(string, string, ...redis.DialOption) (redis.Conn, error) {
+ patches = ApplyFunc(redigo.Dial, func(string, string, ...redigo.DialOption) (redigo.Conn, error) {
return nil, fmt.Errorf("some error")
})
}
diff --git a/pkg/utl/rediscache/service_test.go b/pkg/utl/rediscache/service_test.go
index 79f7b9b5..ea3caedf 100644
--- a/pkg/utl/rediscache/service_test.go
+++ b/pkg/utl/rediscache/service_test.go
@@ -18,7 +18,6 @@ import (
"github.com/DATA-DOG/go-sqlmock"
"github.com/agiledragon/gomonkey/v2"
. "github.com/agiledragon/gomonkey/v2"
- "github.com/gomodule/redigo/redis"
redigo "github.com/gomodule/redigo/redis"
redigomock "github.com/rafaeljusto/redigomock/v3"
)
@@ -85,7 +84,7 @@ type userTestCaseArgs struct {
wantErr bool
errMsg error
- init func(sqlmock.Sqlmock, argsGetUser) *Patches
+ init func(sqlmock.Sqlmock, argsGetUser) *gomonkey.Patches
}
func getUserTestCases() []userTestCaseArgs {
@@ -108,9 +107,9 @@ func errorGetKeyValueCase() userTestCaseArgs {
userID: testutls.MockID,
},
wantErr: true,
- errMsg: fmt.Errorf(ErrMsgGetKeyValue),
- init: func(mock sqlmock.Sqlmock, args argsGetUser) *Patches {
- conn.Command("GET", fmt.Sprintf("user%d", args.userID)).ExpectError(fmt.Errorf(ErrMsgGetKeyValue))
+ errMsg: fmt.Errorf("%s", ErrMsgGetKeyValue),
+ init: func(mock sqlmock.Sqlmock, args argsGetUser) *gomonkey.Patches {
+ conn.Command("GET", fmt.Sprintf("user%d", args.userID)).ExpectError(fmt.Errorf("%s", ErrMsgGetKeyValue))
return nil
},
}
@@ -122,8 +121,8 @@ func errorUnmarshalCase() userTestCaseArgs {
userID: testutls.MockID,
},
wantErr: true,
- init: func(s sqlmock.Sqlmock, user argsGetUser) *Patches {
- patchJson := ApplyFunc(json.Marshal, func(v any) ([]byte, error) {
+ init: func(s sqlmock.Sqlmock, user argsGetUser) *gomonkey.Patches {
+ patchJson := gomonkey.ApplyFunc(json.Marshal, func(v any) ([]byte, error) {
return []byte{}, fmt.Errorf("json error")
})
return patchJson
@@ -136,7 +135,7 @@ func errorSetKeyValueCase() userTestCaseArgs {
args: argsGetUser{
userID: testutls.MockID,
},
- init: func(mock sqlmock.Sqlmock, args argsGetUser) *Patches {
+ init: func(mock sqlmock.Sqlmock, args argsGetUser) *gomonkey.Patches {
conn.Command("GET", fmt.Sprintf("user%d", args.userID)).Expect(nil)
b, _ := json.Marshal(testutls.MockUser())
conn.Command("SET", fmt.Sprintf("user%d", args.userID), string(b)).ExpectError(fmt.Errorf("this is an error"))
@@ -156,7 +155,7 @@ func errorSetKeyValueCase() userTestCaseArgs {
return nil
},
wantErr: true,
- errMsg: fmt.Errorf(ErrMsgSetKeyValue),
+ errMsg: fmt.Errorf("%s", ErrMsgSetKeyValue),
}
}
func errorDaosCase() userTestCaseArgs {
@@ -165,7 +164,7 @@ func errorDaosCase() userTestCaseArgs {
args: argsGetUser{
userID: testutls.MockID,
},
- init: func(mock sqlmock.Sqlmock, args argsGetUser) *Patches {
+ init: func(mock sqlmock.Sqlmock, args argsGetUser) *gomonkey.Patches {
conn.Command("GET", fmt.Sprintf("user%d", args.userID)).Expect(nil)
dbQueries := []testutls.QueryData{
{
@@ -182,7 +181,7 @@ func errorDaosCase() userTestCaseArgs {
return nil
},
wantErr: true,
- errMsg: fmt.Errorf(ErrMsgSetKeyValue),
+ errMsg: fmt.Errorf("%s", ErrMsgSetKeyValue),
}
}
func getSuccessCase() userTestCaseArgs {
@@ -192,7 +191,7 @@ func getSuccessCase() userTestCaseArgs {
userID: testutls.MockID,
want: testutls.MockUser(),
},
- init: func(mock sqlmock.Sqlmock, args argsGetUser) *Patches {
+ init: func(mock sqlmock.Sqlmock, args argsGetUser) *gomonkey.Patches {
b, _ := json.Marshal(args.want)
conn.Command("GET", fmt.Sprintf("user%d", args.userID)).Expect(b)
return nil
@@ -206,7 +205,7 @@ func successCacheMissCase() userTestCaseArgs {
userID: testutls.MockID,
want: testutls.MockUser(),
},
- init: func(mock sqlmock.Sqlmock, args argsGetUser) *Patches {
+ init: func(mock sqlmock.Sqlmock, args argsGetUser) *gomonkey.Patches {
conn.Command("GET", fmt.Sprintf("user%d", args.userID)).Expect(nil)
b, _ := json.Marshal(args.want)
conn.Command("SET", fmt.Sprintf("user%d", args.userID), string(b)).Expect(nil)
@@ -233,7 +232,7 @@ func errorFromCacheUserValueCase() userTestCaseArgs {
args: argsGetUser{
userID: testutls.MockID,
},
- init: func(s sqlmock.Sqlmock, args argsGetUser) *Patches {
+ init: func(s sqlmock.Sqlmock, args argsGetUser) *gomonkey.Patches {
conn.Command("GET", fmt.Sprintf("user%d", args.userID)).
ExpectError(fmt.Errorf("error while getting from cache"))
return nil
@@ -243,7 +242,7 @@ func errorFromCacheUserValueCase() userTestCaseArgs {
func TestGetUser(t *testing.T) {
tests := getUserTestCases()
- redisDialPatch := ApplyFunc(redisDial, func() (redis.Conn, error) {
+ redisDialPatch := ApplyFunc(redisDial, func() (redigo.Conn, error) {
return conn, nil
})
defer redisDialPatch.Reset()
@@ -294,7 +293,7 @@ type roleTestArgs struct {
wantErr bool
errMsg error
- init func(sqlmock.Sqlmock, getRoleArgs) *Patches
+ init func(sqlmock.Sqlmock, getRoleArgs) *gomonkey.Patches
}
func getRoleTestCase(
@@ -302,7 +301,7 @@ func getRoleTestCase(
args getRoleArgs,
wantErr bool,
errMsg error,
- init func(sqlmock.Sqlmock, getRoleArgs) *Patches) roleTestArgs {
+ init func(sqlmock.Sqlmock, getRoleArgs) *gomonkey.Patches) roleTestArgs {
return roleTestArgs{
name: name,
args: args,
@@ -316,7 +315,7 @@ func setupErrorCase(
name string,
roleID int,
errMsg error,
- init func(sqlmock.Sqlmock, getRoleArgs) *Patches) roleTestArgs {
+ init func(sqlmock.Sqlmock, getRoleArgs) *gomonkey.Patches) roleTestArgs {
return roleTestArgs{
name: name,
args: getRoleArgs{
@@ -335,7 +334,7 @@ func loadGetRoleSuccessCase() roleTestArgs {
},
false,
nil,
- func(mock sqlmock.Sqlmock, args getRoleArgs) *Patches {
+ func(mock sqlmock.Sqlmock, args getRoleArgs) *gomonkey.Patches {
b, _ := json.Marshal(args.want)
conn.Command("GET", fmt.Sprintf("role%d", args.roleID)).Expect(b)
return nil
@@ -352,7 +351,7 @@ func loadGetRoleCacheMissSuccessCase() roleTestArgs {
},
false,
nil,
- func(mock sqlmock.Sqlmock, args getRoleArgs) *Patches {
+ func(mock sqlmock.Sqlmock, args getRoleArgs) *gomonkey.Patches {
conn.Command("GET", fmt.Sprintf("role%d", args.roleID)).Expect(nil)
b, _ := json.Marshal(args.want)
conn.Command("SET", fmt.Sprintf("role%d", args.roleID), string(b)).Expect(nil)
@@ -376,23 +375,23 @@ func loadGetRoleCacheMissSuccessCase() roleTestArgs {
func getGetRoleTestCases() []roleTestArgs {
tests := []roleTestArgs{
setupErrorCase(ErrorGetKeyValue, testutls.MockID, errors.New(ErrMsgGetKeyValue),
- func(mock sqlmock.Sqlmock, args getRoleArgs) *Patches {
- conn.Command("GET", fmt.Sprintf("role%d", args.roleID)).ExpectError(fmt.Errorf(ErrMsgGetKeyValue))
+ func(mock sqlmock.Sqlmock, args getRoleArgs) *gomonkey.Patches {
+ conn.Command("GET", fmt.Sprintf("role%d", args.roleID)).ExpectError(fmt.Errorf("%s", ErrMsgGetKeyValue))
return nil
}),
setupErrorCase(ErrorUnmarshal, testutls.MockID, errors.New(ErrMsgUnmarshal),
- func(mock sqlmock.Sqlmock, args getRoleArgs) *Patches {
+ func(mock sqlmock.Sqlmock, args getRoleArgs) *gomonkey.Patches {
return ApplyFunc(json.Unmarshal, func(data []byte, v any) error {
- return fmt.Errorf(ErrMsgUnmarshal)
+ return fmt.Errorf("%s", ErrMsgUnmarshal)
})
}),
setupErrorCase(ErrorSetKeyValue, testutls.MockID, errors.New(ErrMsgSetKeyValue),
- func(mock sqlmock.Sqlmock, args getRoleArgs) *Patches {
+ func(mock sqlmock.Sqlmock, args getRoleArgs) *gomonkey.Patches {
conn.Command("GET", fmt.Sprintf("role%d", args.roleID)).Expect(nil)
return nil
}),
setupErrorCase(ErrorFindRoleById, testutls.MockID, errors.New(ErrMsgFindRoleById),
- func(mock sqlmock.Sqlmock, args getRoleArgs) *Patches {
+ func(mock sqlmock.Sqlmock, args getRoleArgs) *gomonkey.Patches {
conn.Command("GET", fmt.Sprintf("role%d", args.roleID)).ExpectError(fmt.Errorf("there was an error"))
return nil
}),
@@ -406,7 +405,7 @@ func TestGetRole(t *testing.T) {
tests := getGetRoleTestCases()
mock, cleanup, _ := testutls.SetupMockDB(t)
defer cleanup()
- redisDialPatches := ApplyFunc(redisDial, func() (redis.Conn, error) {
+ redisDialPatches := ApplyFunc(redisDial, func() (redigo.Conn, error) {
return conn, nil
})
defer redisDialPatches.Reset()
@@ -452,17 +451,17 @@ func TestIncVisits(t *testing.T) {
path: "test",
},
wantErr: true,
- errMsg: fmt.Errorf(ErrMsgFromRedisDial),
+ errMsg: fmt.Errorf("%s", ErrMsgFromRedisDial),
},
}
- ApplyFunc(redisDial, func() (redis.Conn, error) {
+ ApplyFunc(redisDial, func() (redigo.Conn, error) {
return conn, nil
})
for _, tt := range tests {
if tt.name == ErrorRedisDial {
patch := gomonkey.ApplyFunc(redisDial, func() (redigo.Conn, error) {
- return nil, fmt.Errorf(ErrMsgFromRedisDial)
+ return nil, fmt.Errorf("%s", ErrMsgFromRedisDial)
})
defer patch.Reset()
}
@@ -491,7 +490,7 @@ type startVisitTestArgs struct {
wantErr bool
errMsg error
- init func(startVisitArgs) *Patches
+ init func(startVisitArgs) *gomonkey.Patches
}
func TestStartVisits(t *testing.T) {
@@ -519,12 +518,12 @@ func getTestCases() []startVisitTestArgs {
path: "test",
},
wantErr: true,
- errMsg: fmt.Errorf(ErrMsgFromConnDo),
- init: func(args startVisitArgs) *Patches {
+ errMsg: fmt.Errorf("%s", ErrMsgFromConnDo),
+ init: func(args startVisitArgs) *gomonkey.Patches {
conn.Command("SETEX", args.path, int(math.Ceil(time.Second.Seconds())), 1).Expect(args.want)
return gomonkey.ApplyMethodFunc(redigomock.NewConn(), "Do",
func(commandName string, args ...interface{}) (reply interface{}, err error) {
- return nil, fmt.Errorf(ErrMsgFromConnDo)
+ return nil, fmt.Errorf("%s", ErrMsgFromConnDo)
})
},
},
@@ -534,7 +533,7 @@ func getTestCases() []startVisitTestArgs {
path: "test",
want: 10,
},
- init: func(args startVisitArgs) *Patches {
+ init: func(args startVisitArgs) *gomonkey.Patches {
return gomonkey.ApplyFunc(redisDial, func() (redigo.Conn, error) {
return conn, nil
})
@@ -546,11 +545,11 @@ func getTestCases() []startVisitTestArgs {
path: "test",
},
wantErr: true,
- errMsg: fmt.Errorf(ErrMsgFromRedisDial),
- init: func(args startVisitArgs) *Patches {
+ errMsg: fmt.Errorf("%s", ErrMsgFromRedisDial),
+ init: func(args startVisitArgs) *gomonkey.Patches {
conn.Command("SETEX", args.path, int(math.Ceil(time.Second.Seconds())), 1).Expect(args.want)
return gomonkey.ApplyFunc(redisDial, func() (redigo.Conn, error) {
- return nil, fmt.Errorf(ErrMsgFromRedisDial)
+ return nil, fmt.Errorf("%s", ErrMsgFromRedisDial)
})
},
},
diff --git a/pkg/utl/resultwrapper/error.go b/pkg/utl/resultwrapper/error.go
index 75af043f..6ece2f5f 100644
--- a/pkg/utl/resultwrapper/error.go
+++ b/pkg/utl/resultwrapper/error.go
@@ -78,7 +78,7 @@ func WrapperFromMessage(errorCode int, c echo.Context, err string) error {
if e1 != nil {
return e1
}
- return fmt.Errorf(errMessage)
+ return fmt.Errorf("%s", errMessage)
}
// InternalServerError ...
@@ -152,7 +152,7 @@ func ServiceUnavailable(c echo.Context, err error) error {
func HandleGraphQLError(errMsg string) graphql2.ResponseHandler {
return func(ctx context.Context) *graphql2.Response {
return &graphql2.Response{
- Errors: gqlerror.List{gqlerror.Errorf(errMsg)},
+ Errors: gqlerror.List{gqlerror.Errorf("%s", errMsg)},
}
}
}
@@ -196,5 +196,5 @@ func ResolverWrapperFromMessage(errorCode int, err string) error {
if e1 != nil {
return e1
}
- return fmt.Errorf(errMessage)
+ return fmt.Errorf("%s", errMessage)
}
diff --git a/pkg/utl/resultwrapper/error_test.go b/pkg/utl/resultwrapper/error_test.go
index f707b3cd..2a1cfb3f 100644
--- a/pkg/utl/resultwrapper/error_test.go
+++ b/pkg/utl/resultwrapper/error_test.go
@@ -121,7 +121,7 @@ func TestResultWrapper(t *testing.T) {
name: ErrorCase,
args: args{
errorCode: 400,
- err: fmt.Errorf(ErrMsgJSON),
+ err: fmt.Errorf("%s", ErrMsgJSON),
},
wantErr: true,
},
@@ -132,7 +132,7 @@ func TestResultWrapper(t *testing.T) {
ctx := e.NewContext(req, w)
if tt.name == ErrorCase {
patch := gomonkey.ApplyMethodFunc(ctx, "JSON", func(code int, i interface{}) error {
- return fmt.Errorf(ErrMsgJSON)
+ return fmt.Errorf("%s", ErrMsgJSON)
})
defer patch.Reset()
}
@@ -162,7 +162,7 @@ func TestInternalServerError(t *testing.T) {
name: SuccessCase,
err: ErrMsg,
args: args{
- err: fmt.Errorf(ErrMsg),
+ err: fmt.Errorf("%s", ErrMsg),
c: getContext()},
wantErr: true,
},
@@ -198,7 +198,7 @@ func TestInternalServerErrorFromMessage(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := resultwrapper.InternalServerErrorFromMessage(tt.args.c, tt.args.err)
- assert.Equal(t, err, fmt.Errorf(tt.args.err))
+ assert.Equal(t, err, fmt.Errorf("%s", tt.args.err))
assert.Equal(t, http.StatusInternalServerError, tt.args.c.Response().Status)
})
}
@@ -220,7 +220,7 @@ func TestBadRequest(t *testing.T) {
name: SuccessCase,
err: errorStr,
args: args{
- err: fmt.Errorf(errorStr),
+ err: fmt.Errorf("%s", errorStr),
c: getContext()},
wantErr: true,
},
@@ -256,7 +256,7 @@ func TestBadRequestFromMessage(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := resultwrapper.BadRequestFromMessage(tt.args.c, tt.args.err)
- assert.Equal(t, err, fmt.Errorf(tt.args.err))
+ assert.Equal(t, err, fmt.Errorf("%s", tt.args.err))
assert.Equal(t, http.StatusBadRequest, tt.args.c.Response().Status)
})
}
@@ -278,7 +278,7 @@ func TestConflict(t *testing.T) {
name: SuccessCase,
err: errorStr,
args: args{
- err: fmt.Errorf(errorStr),
+ err: fmt.Errorf("%s", errorStr),
c: getContext()},
wantErr: true,
},
@@ -314,7 +314,7 @@ func TestConflictFromMessage(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := resultwrapper.ConflictFromMessage(tt.args.c, tt.args.err)
- assert.Equal(t, err, fmt.Errorf(tt.args.err))
+ assert.Equal(t, err, fmt.Errorf("%s", tt.args.err))
assert.Equal(t, http.StatusConflict, tt.args.c.Response().Status)
})
}
@@ -336,7 +336,7 @@ func TestTooManyRequests(t *testing.T) {
name: SuccessCase,
err: errorStr,
args: args{
- err: fmt.Errorf(errorStr),
+ err: fmt.Errorf("%s", errorStr),
c: getContext()},
wantErr: true,
},
@@ -366,7 +366,7 @@ func TestUnauthorized(t *testing.T) {
name: SuccessCase,
err: errorStr,
args: args{
- err: fmt.Errorf(errorStr),
+ err: fmt.Errorf("%s", errorStr),
c: getContext()},
wantErr: true,
},
@@ -402,7 +402,7 @@ func TestUnauthorizedFromMessage(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := resultwrapper.UnauthorizedFromMessage(tt.args.c, tt.args.err)
- assert.Equal(t, err, fmt.Errorf(tt.args.err))
+ assert.Equal(t, err, fmt.Errorf("%s", tt.args.err))
assert.Equal(t, http.StatusUnauthorized, tt.args.c.Response().Status)
})
}
@@ -591,7 +591,7 @@ func TestResolverSQLError(t *testing.T) {
if tt.dontAddDetail {
errorMessage = tt.errMsg
}
- assert.Equal(t, fmt.Errorf(errorMessage), err)
+ assert.Equal(t, fmt.Errorf("%s", errorMessage), err)
})
}
}
diff --git a/pkg/utl/zaplog/zaplog_test.go b/pkg/utl/zaplog/zaplog_test.go
index fa6e5b97..06f9a591 100644
--- a/pkg/utl/zaplog/zaplog_test.go
+++ b/pkg/utl/zaplog/zaplog_test.go
@@ -131,7 +131,7 @@ func TestInitLogger(t *testing.T) {
patchProduction := gomonkey.ApplyFunc(zap.NewProduction, func(options ...zap.Option) (*zap.Logger, error) {
if tt.panicErr {
- return &mockZapLog, fmt.Errorf(ErrMsgProduction)
+ return &mockZapLog, fmt.Errorf("%s", ErrMsgProduction)
} else {
return &mockZapLog, nil
}
diff --git a/resolver/auth_mutations.resolvers_test.go b/resolver/auth_mutations.resolvers_test.go
index 158db45d..dcd0af79 100644
--- a/resolver/auth_mutations.resolvers_test.go
+++ b/resolver/auth_mutations.resolvers_test.go
@@ -83,11 +83,11 @@ func errorFindingUserCase() loginType {
Password: TestPassword,
},
wantErr: true,
- err: fmt.Errorf(ErrorMsgFindingUser),
+ err: fmt.Errorf("%s", ErrorMsgFindingUser),
init: func() *gomonkey.Patches {
return gomonkey.ApplyFunc(daos.FindUserByUserName,
func(username string, ctx context.Context) (*models.User, error) {
- return nil, fmt.Errorf(ErrorMsgFindingUser)
+ return nil, fmt.Errorf("%s", ErrorMsgFindingUser)
})
},
}
@@ -100,7 +100,7 @@ func errorPasswordValidationCase() loginType {
Password: TestPassword,
},
wantErr: true,
- err: fmt.Errorf(ErrorMsgPasswordValidation),
+ err: fmt.Errorf("%s", ErrorMsgPasswordValidation),
init: func() *gomonkey.Patches {
tg := jwt.Service{}
sec := secure.Service{}
@@ -117,7 +117,7 @@ func errorPasswordValidationCase() loginType {
user.Active = null.BoolFrom(false)
return user, nil
}).ApplyFunc(tg.GenerateToken, func(u *models.User) (string, error) {
- return "", fmt.Errorf(ErrorMsgPasswordValidation)
+ return "", fmt.Errorf("%s", ErrorMsgPasswordValidation)
})
},
}
@@ -164,7 +164,7 @@ func errorFromConfigCase() loginType {
Password: OldPassword,
},
wantErr: true,
- err: fmt.Errorf(ErrorMsgFromConfig),
+ err: fmt.Errorf("%s", ErrorMsgFromConfig),
init: func() *gomonkey.Patches {
return gomonkey.ApplyFunc(daos.FindUserByUserName,
func(username string, ctx context.Context) (*models.User, error) {
@@ -188,7 +188,7 @@ func errorWhileGeneratingToken() loginType {
Password: OldPassword,
},
wantErr: true,
- err: fmt.Errorf(ErrorMsgFromJwt),
+ err: fmt.Errorf("%s", ErrorMsgFromJwt),
init: func() *gomonkey.Patches {
tg := jwt.Service{}
sec := secure.Service{}
@@ -208,13 +208,13 @@ func errorWhileGeneratingToken() loginType {
}).ApplyMethod(reflect.TypeOf(sec), "HashMatchesPassword", func(sec secure.Service, hash string, password string) bool {
return true
}).ApplyFunc(service.JWT, func(cfg *config.Configuration) (jwt.Service, error) {
- return tg, fmt.Errorf(ErrorMsgFromJwt)
+ return tg, fmt.Errorf("%s", ErrorMsgFromJwt)
})
},
}
}
func errorUpdateUserCase() loginType {
- err := fmt.Errorf(ErrorMsgfromUpdateUser)
+ err := fmt.Errorf("%s", ErrorMsgfromUpdateUser)
return loginType{
name: ErrorUpdateUser,
req: loginArgs{
@@ -403,7 +403,7 @@ func changePasswordErrorFindingUserCase() changePasswordType {
init: func() *gomonkey.Patches {
return gomonkey.ApplyFunc(daos.FindUserByID,
func(userID int, ctx context.Context) (*models.User, error) {
- return nil, fmt.Errorf(ErrorMsgFindingUser)
+ return nil, fmt.Errorf("%s", ErrorMsgFindingUser)
})
},
}
@@ -421,7 +421,7 @@ func changePasswordErrorPasswordValidationcase() changePasswordType {
sec := secure.Service{}
return gomonkey.ApplyFunc(daos.FindUserByID,
func(userID int, ctx context.Context) (*models.User, error) {
- return nil, fmt.Errorf(ErrorMsgFindingUser)
+ return nil, fmt.Errorf("%s", ErrorMsgFindingUser)
}).ApplyMethod(reflect.TypeOf(sec), "HashMatchesPassword",
func(sec secure.Service, hash string, password string) bool {
return false
@@ -472,10 +472,10 @@ func changePasswordErrorUpdateUserCase() changePasswordType {
user := testutls.MockUser()
user.Password = null.StringFrom(OldPasswordHash)
user.Active = null.BoolFrom(false)
- return user, fmt.Errorf(ErrorInsecurePassword)
+ return user, fmt.Errorf("%s", ErrorInsecurePassword)
}).ApplyFunc(daos.UpdateUser,
func(user models.User, ctx context.Context) (*models.User, error) {
- return nil, fmt.Errorf(ErrorUpdateUser)
+ return nil, fmt.Errorf("%s", ErrorUpdateUser)
})
},
}
@@ -592,7 +592,7 @@ func refreshTokenInvalidCase() refereshTokenType {
name: ErrorInvalidToken,
req: TestToken,
wantErr: true,
- err: fmt.Errorf(ErrorMsginvalidToken),
+ err: fmt.Errorf("%s", ErrorMsginvalidToken),
init: func() *gomonkey.Patches {
tg := jwt.Service{}
return gomonkey.ApplyFunc(config.Load, func() (*config.Configuration, error) {
@@ -601,7 +601,7 @@ func refreshTokenInvalidCase() refereshTokenType {
return tg, nil
}).ApplyMethod(reflect.TypeOf(tg), "GenerateToken",
func(jwt.Service, *models.User) (string, error) {
- return "", fmt.Errorf(ErrorMsginvalidToken)
+ return "", fmt.Errorf("%s", ErrorMsginvalidToken)
}).ApplyFunc(daos.FindUserByToken, func(token string, ctx context.Context) (*models.User, error) {
return testutls.MockUser(), nil
})
@@ -613,10 +613,10 @@ func refreshTokenErrorFromConfigCase() refereshTokenType {
name: ErrorFromConfig,
req: ReqToken,
wantErr: true,
- err: fmt.Errorf(ErrorMsgFromConfig),
+ err: fmt.Errorf("%s", ErrorMsgFromConfig),
init: func() *gomonkey.Patches {
return gomonkey.ApplyFunc(config.Load, func() (*config.Configuration, error) {
- return nil, fmt.Errorf(ErrorFromConfig)
+ return nil, fmt.Errorf("%s", ErrorFromConfig)
}).ApplyFunc(daos.FindUserByToken, func(token string, ctx context.Context) (*models.User, error) {
return testutls.MockUser(), nil
})
@@ -629,13 +629,13 @@ func refereshTokenerrorWhileGeneratingToken() refereshTokenType {
name: ErrorFromJwt,
req: ReqToken,
wantErr: true,
- err: fmt.Errorf(ErrorMsgFromJwt),
+ err: fmt.Errorf("%s", ErrorMsgFromJwt),
init: func() *gomonkey.Patches {
tg := jwt.Service{}
return gomonkey.ApplyFunc(config.Load, func() (*config.Configuration, error) {
return nil, nil
}).ApplyFunc(service.JWT, func(cfg *config.Configuration) (jwt.Service, error) {
- return tg, fmt.Errorf(ErrorMsgFromJwt)
+ return tg, fmt.Errorf("%s", ErrorMsgFromJwt)
}).ApplyFunc(daos.FindUserByToken, func(token string, ctx context.Context) (*models.User, error) {
return testutls.MockUser(), nil
})
@@ -648,7 +648,7 @@ func refereshTokenErrorFromGenerateTokenCase() refereshTokenType {
name: ErrorFromGenerateToken,
req: ReqToken,
wantErr: true,
- err: fmt.Errorf(ErrorFromGenerateToken),
+ err: fmt.Errorf("%s", ErrorFromGenerateToken),
init: func() *gomonkey.Patches {
tg := jwt.Service{}
return gomonkey.ApplyFunc(config.Load, func() (*config.Configuration, error) {
@@ -657,7 +657,7 @@ func refereshTokenErrorFromGenerateTokenCase() refereshTokenType {
return tg, nil
}).ApplyMethod(reflect.TypeOf(tg), "GenerateToken",
func(jwt.Service, *models.User) (string, error) {
- return "", fmt.Errorf(ErrorFromGenerateToken)
+ return "", fmt.Errorf("%s", ErrorFromGenerateToken)
}).ApplyFunc(daos.FindUserByToken, func(token string, ctx context.Context) (*models.User, error) {
return testutls.MockUser(), nil
})