Skip to content

Commit

Permalink
ci: apply testifylint (#824)
Browse files Browse the repository at this point in the history
Fix testify linter issues:
- Nil(t, err)    => NoError(t, err)
- NotNil(t, err) => Error(t, err)
- Equal(t, actual, expected) => Equal(t, expected, actual)
- Equal(t, true, whatever) => True(t, whatever)
- True(t, errors.Is(err, ErrSentinel)) => ErrorsIs(t, err, ErrSentinel)
  • Loading branch information
ccoVeille authored Jul 9, 2024
1 parent f43d53c commit 28f1710
Show file tree
Hide file tree
Showing 45 changed files with 259 additions and 259 deletions.
2 changes: 1 addition & 1 deletion examples/grpc-server/grpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestServer_SayHello(t *testing.T) {
req := &HelloRequest{Name: tc.input}
resp, err := s.SayHello(context.Background(), req)

assert.Nil(t, err, "TEST[%d], Failed.\n", i)
assert.NoError(t, err, "TEST[%d], Failed.\n", i)

assert.Equal(t, tc.resp, resp.Message, "TEST[%d], Failed.\n", i)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/grpc-server/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ func TestGRPCServer(t *testing.T) {
// case of empty request
resp, err := client.SayHello(context.Background(), nil)
assert.Equal(t, "Hello World!", resp.Message)
assert.Nil(t, err)
assert.NoError(t, err)

// Test context cancellation
ctx, cancel := context.WithCancel(context.Background())
cancel()
_, err = client.SayHello(ctx, &grpcExample.HelloRequest{Name: "Test"})
assert.Equal(t, err.Error(), "rpc error: code = Canceled desc = context canceled")
assert.Equal(t, "rpc error: code = Canceled desc = context canceled", err.Error())

}

Expand Down
6 changes: 3 additions & 3 deletions examples/http-server-using-redis/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestHTTPServerUsingRedis(t *testing.T) {
c := http.Client{}
resp, err := c.Do(req)

assert.Nil(t, err, "TEST[%d], Failed.\n%s", i, tc.desc)
assert.NoError(t, err, "TEST[%d], Failed.\n%s", i, tc.desc)

assert.Equal(t, tc.statusCode, resp.StatusCode, "TEST[%d], Failed.\n%s", i, tc.desc)
}
Expand All @@ -73,7 +73,7 @@ func TestRedisSetHandler(t *testing.T) {
resp, err := RedisSetHandler(ctx)

assert.Nil(t, resp)
assert.NotNil(t, err)
assert.Error(t, err)
}

func TestRedisPipelineHandler(t *testing.T) {
Expand All @@ -98,5 +98,5 @@ func TestRedisPipelineHandler(t *testing.T) {
resp, err := RedisPipelineHandler(ctx)

assert.Nil(t, resp)
assert.NotNil(t, err)
assert.Error(t, err)
}
12 changes: 6 additions & 6 deletions examples/http-server/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ func TestIntegration_SimpleAPIServer(t *testing.T) {

b, err := io.ReadAll(resp.Body)

assert.Nil(t, err, "TEST[%d], Failed.\n%s", i, tc.desc)
assert.NoError(t, err, "TEST[%d], Failed.\n%s", i, tc.desc)

_ = json.Unmarshal(b, &data)

assert.Equal(t, tc.body, data.Data, "TEST[%d], Failed.\n%s", i, tc.desc)

assert.Nil(t, err, "TEST[%d], Failed.\n%s", i, tc.desc)
assert.NoError(t, err, "TEST[%d], Failed.\n%s", i, tc.desc)

assert.Equal(t, http.StatusOK, resp.StatusCode, "TEST[%d], Failed.\n%s", i, tc.desc)

Expand Down Expand Up @@ -104,13 +104,13 @@ func TestIntegration_SimpleAPIServer_Errors(t *testing.T) {

b, err := io.ReadAll(resp.Body)

assert.Nil(t, err, "TEST[%d], Failed.\n%s", i, tc.desc)
assert.NoError(t, err, "TEST[%d], Failed.\n%s", i, tc.desc)

_ = json.Unmarshal(b, &data)

assert.Equal(t, tc.body, data.Error, "TEST[%d], Failed.\n%s", i, tc.desc)

assert.Nil(t, err, "TEST[%d], Failed.\n%s", i, tc.desc)
assert.NoError(t, err, "TEST[%d], Failed.\n%s", i, tc.desc)

assert.Equal(t, tc.statusCode, resp.StatusCode, "TEST[%d], Failed.\n%s", i, tc.desc)

Expand All @@ -135,7 +135,7 @@ func TestIntegration_SimpleAPIServer_Health(t *testing.T) {
c := http.Client{}
resp, err := c.Do(req)

assert.Nil(t, err, "TEST[%d], Failed.\n%s", i, tc.desc)
assert.NoError(t, err, "TEST[%d], Failed.\n%s", i, tc.desc)

assert.Equal(t, tc.statusCode, resp.StatusCode, "TEST[%d], Failed.\n%s", i, tc.desc)
}
Expand All @@ -157,5 +157,5 @@ func TestRedisHandler(t *testing.T) {
resp, err := RedisHandler(ctx)

assert.Nil(t, resp)
assert.NotNil(t, err)
assert.Error(t, err)
}
2 changes: 1 addition & 1 deletion examples/sample-cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestCMDRunWithNoArg(t *testing.T) {
expErr := "No Command Found!\n"
output := testutil.StderrOutputForFunc(main)

assert.Equal(t, output, expErr, "TEST Failed.\n")
assert.Equal(t, expErr, output, "TEST Failed.\n")
}

func TestCMDRunWithProperArg(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion examples/using-add-rest-handlers/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestIntegration_AddRESTHandlers(t *testing.T) {
c := http.Client{}
resp, err := c.Do(req)

assert.Nil(t, err, "TEST[%d], Failed.\n%s", i, tc.desc)
assert.NoError(t, err, "TEST[%d], Failed.\n%s", i, tc.desc)

assert.Equal(t, tc.statusCode, resp.StatusCode, "TEST[%d], Failed.\n%s", i, tc.desc)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestCreateTableUser(t *testing.T) {
// Execute the migration
err = createTableUser().UP(datasource)

assert.Equal(t, err, tc.expectedError, "TEST[%d] Failed.\n%s", i, tc.desc)
assert.Equal(t, tc.expectedError, err, "TEST[%d] Failed.\n%s", i, tc.desc)
assert.NoError(t, mock.ExpectationsWereMet())
}
}
8 changes: 4 additions & 4 deletions examples/using-http-service/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ func Test_main(t *testing.T) {
req, _ := http.NewRequest(http.MethodGet, host+tc.path, nil)
resp, err := c.Do(req)

assert.Nil(t, err, "TEST[%d], Failed.\n%s", i, tc.desc)
assert.NoError(t, err, "TEST[%d], Failed.\n%s", i, tc.desc)

bodyBytes, err := io.ReadAll(resp.Body)

assert.Nil(t, err, "TEST[%d], Failed.\n%s", i, tc.desc)
assert.NoError(t, err, "TEST[%d], Failed.\n%s", i, tc.desc)

assert.Equal(t, tc.expectedRes, string(bodyBytes), "TEST[%d], Failed.\n%s", i, tc.desc)

Expand All @@ -79,7 +79,7 @@ func TestHTTPHandlerURLError(t *testing.T) {
resp, err := Handler(ctx)

assert.Nil(t, resp)
assert.NotNil(t, err)
assert.Error(t, err)
}

func TestHTTPHandlerResponseUnmarshalError(t *testing.T) {
Expand All @@ -104,5 +104,5 @@ func TestHTTPHandlerResponseUnmarshalError(t *testing.T) {
resp, err := Handler(ctx)

assert.Nil(t, resp)
assert.NotNil(t, err)
assert.Error(t, err)
}
2 changes: 1 addition & 1 deletion examples/using-migrations/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestExampleMigration(t *testing.T) {
c := http.Client{}
resp, err := c.Do(req)

assert.Nil(t, err, "TEST[%d], Failed.\n%s", i, tc.desc)
assert.NoError(t, err, "TEST[%d], Failed.\n%s", i, tc.desc)

assert.Equal(t, tc.statusCode, resp.StatusCode, "TEST[%d], Failed.\n%s", i, tc.desc)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestCreateTableEmployee(t *testing.T) {
// Execute the migration
err = createTableEmployee().UP(datasource)

assert.Equal(t, err, tc.expectedError, "TEST[%d] failed! Desc : %v", i, tc.name)
assert.Equal(t, tc.expectedError, err, "TEST[%d] failed! Desc : %v", i, tc.name)

assert.NoError(t, mock.ExpectationsWereMet())
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/gofr/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func Test_Run_SuccessCommandWithMultipleParameters(t *testing.T) {

c.addRoute("log",
func(c *Context) (interface{}, error) {
assert.Equal(t, c.Request.Param("param"), "value")
assert.Equal(t, c.Request.Param("b"), "true")
assert.Equal(t, "value", c.Request.Param("param"))
assert.Equal(t, "true", c.Request.Param("b"))
c.Logger.Info("handler called")

return nil, nil
Expand Down Expand Up @@ -147,7 +147,7 @@ func Test_Run_ErrorParamNotReadWithoutHyphen(t *testing.T) {

c.addRoute("log",
func(c *Context) (interface{}, error) {
assert.Equal(t, c.Request.Param("hello"), "")
assert.Equal(t, "", c.Request.Param("hello"))
c.Logger.Info("handler called")

return nil, nil
Expand Down Expand Up @@ -342,5 +342,5 @@ func Test_Run_handler_help(t *testing.T) {
})

// check that only help for the hello subcommand is printed
assert.Equal(t, out, "this a helper string for hello sub command\n")
assert.Equal(t, "this a helper string for hello sub command\n", out)
}
2 changes: 1 addition & 1 deletion pkg/gofr/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ func Test_newContextSuccess(t *testing.T) {
err = ctx.Bind(&body)

assert.Equal(t, map[string]string{"key": "value"}, body, "TEST Failed \n unable to read body")
assert.Nil(t, err, "TEST Failed \n unable to read body")
assert.NoError(t, err, "TEST Failed \n unable to read body")
}
6 changes: 3 additions & 3 deletions pkg/gofr/cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestCron_parseSchedule_Success(t *testing.T) {
for _, tc := range testCases {
j, err := parseSchedule(tc.schedule)

assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, *tc.expJob, *j)
}
}
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestCron_getDefaultJobField(t *testing.T) {
for _, tc := range testCases {
out := getDefaultJobField(tc.min, tc.max, tc.incr)

assert.Equal(t, tc.expOutCount, len(out))
assert.Len(t, out, tc.expOutCount)
}
}

Expand Down Expand Up @@ -311,5 +311,5 @@ func Test_noopRequest(t *testing.T) {
assert.Equal(t, "", noop.Param(""))
assert.Equal(t, "", noop.PathParam(""))
assert.Equal(t, "gofr", noop.HostName())
assert.Equal(t, nil, noop.Bind(nil))
assert.NoError(t, noop.Bind(nil))
}
4 changes: 2 additions & 2 deletions pkg/gofr/crud_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func Test_GetAllHandler(t *testing.T) {
if tc.expectedErr != nil {
assert.Equal(t, tc.expectedErr.Error(), err.Error(), "TEST[%d], Failed.\n%s", i, tc.desc)
} else {
assert.Nil(t, err, "TEST[%d], Failed.\n%s", i, tc.desc)
assert.NoError(t, err, "TEST[%d], Failed.\n%s", i, tc.desc)
}
})
}
Expand Down Expand Up @@ -426,7 +426,7 @@ func Test_GetHandler(t *testing.T) {
if tc.expectedErr != nil {
assert.Equal(t, tc.expectedErr.Error(), err.Error(), "Failed.\n%s", tc.desc)
} else {
assert.Nil(t, err, "Failed.\n%s", tc.desc)
assert.NoError(t, err, "Failed.\n%s", tc.desc)
}
})
}
Expand Down
28 changes: 14 additions & 14 deletions pkg/gofr/datasource/file/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ func Test_LocalFileSystemDirectoryCreation(t *testing.T) {
err := fileStore.Mkdir(dirName, os.ModePerm)
defer os.RemoveAll(dirName)

assert.Nil(t, err)
assert.NoError(t, err)

fInfo, err := os.Stat(dirName)

assert.Nil(t, err)
assert.Equal(t, true, fInfo.IsDir())
assert.NoError(t, err)
assert.True(t, fInfo.IsDir())
}

func Test_LocalFileOpenError(t *testing.T) {
Expand Down Expand Up @@ -69,15 +69,15 @@ func Test_CreateReadDeleteFile(t *testing.T) {
_ = fileStore.Remove(name)
}(fileStore, fileName)

assert.Nil(t, err)
assert.NoError(t, err)

tempFile, _ := fileStore.Open("temp.txt")

reader := make([]byte, 30)

_, err = tempFile.Read(reader)

assert.Nil(t, err)
assert.NoError(t, err)
assert.Contains(t, string(reader), "some content")
}

Expand All @@ -90,14 +90,14 @@ func Test_CreateMoveDeleteFile(t *testing.T) {

_, err := fileStore.Create(fileName)

assert.Nil(t, err)
assert.NoError(t, err)

err = fileStore.Rename("temp.txt", "temp.text")
defer func(fileStore datasource.FileSystem, name string) {
_ = fileStore.Remove(name)
}(fileStore, "temp.text")

assert.Nil(t, err)
assert.NoError(t, err)
}

func Test_CreateUpdateReadFile(t *testing.T) {
Expand All @@ -115,7 +115,7 @@ func Test_CreateUpdateReadFile(t *testing.T) {
_ = fileStore.Remove(name)
}(fileStore, fileName)

assert.Nil(t, err)
assert.NoError(t, err)

openedFile, _ := fileStore.OpenFile(fileName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.ModePerm)
_, _ = openedFile.WriteAt([]byte("some new content"), 0)
Expand All @@ -126,7 +126,7 @@ func Test_CreateUpdateReadFile(t *testing.T) {
_, err = openedFile.Read(reader)
openedFile.Close()

assert.Nil(t, err)
assert.NoError(t, err)
assert.Contains(t, string(reader), "some new content")
}

Expand All @@ -149,7 +149,7 @@ func Test_CreateAndDeleteMultipleDirectories(t *testing.T) {

err := fileStore.RemoveAll("temp")

assert.Nil(t, err)
assert.NoError(t, err)
}

func Test_ReadFromCSV(t *testing.T) {
Expand Down Expand Up @@ -190,7 +190,7 @@ Michael Brown,40,michaelb@example.com`

assert.Equal(t, csvValue[i], content)

assert.Nil(t, err)
assert.NoError(t, err)

i++
}
Expand Down Expand Up @@ -219,7 +219,7 @@ func Test_ReadFromCSVScanError(t *testing.T) {

err := reader.Scan(content)

assert.NotNil(t, err)
assert.Error(t, err)
assert.Equal(t, "", content)
}
}
Expand Down Expand Up @@ -259,7 +259,7 @@ func Test_ReadFromJSONArray(t *testing.T) {
assert.Equal(t, jsonValue[i].Name, u.Name)
assert.Equal(t, jsonValue[i].Age, u.Age)

assert.Nil(t, err)
assert.NoError(t, err)

i++
}
Expand Down Expand Up @@ -296,7 +296,7 @@ func Test_ReadFromJSONObject(t *testing.T) {
assert.Equal(t, "Sam", u.Name)
assert.Equal(t, 123, u.Age)

assert.Nil(t, err)
assert.NoError(t, err)
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/gofr/datasource/mongo/mongo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func Test_InsertCommands(t *testing.T) {
resp, err := cl.InsertMany(context.Background(), mt.Coll.Name(), []interface{}{doc, doc})

assert.NotNil(t, resp)
assert.Nil(t, err)
assert.NoError(t, err)
})

mt.Run("insertManyError", func(mt *mtest.T) {
Expand All @@ -104,7 +104,7 @@ func Test_InsertCommands(t *testing.T) {
resp, err := cl.InsertMany(context.Background(), mt.Coll.Name(), []interface{}{doc, doc})

assert.Nil(t, resp)
assert.NotNil(t, err)
assert.Error(t, err)
})
}

Expand All @@ -127,7 +127,7 @@ func Test_CreateCollection(t *testing.T) {

err := cl.CreateCollection(context.Background(), mt.Coll.Name())

assert.Nil(t, err)
assert.NoError(t, err)
})
}

Expand Down
Loading

0 comments on commit 28f1710

Please sign in to comment.