Skip to content

Commit

Permalink
resolve nil errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kkumar-gcc committed Sep 12, 2024
1 parent 45b921e commit 07dd54a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
7 changes: 6 additions & 1 deletion testing/docker/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ func (receiver *Database) Build() error {
return fmt.Errorf("connect to %s failed", receiver.driver.Name().String())
}

receiver.app.MakeArtisan().Call("migrate")
artisan := receiver.app.MakeArtisan()
if artisan == nil {
return errors.New("artisan instance is not available")
}

artisan.Call("migrate")
receiver.app.Singleton(frameworkdatabase.BindingOrm, func(app foundation.Application) (any, error) {
config := app.MakeConfig()
defaultConnection := config.GetString("database.default")
Expand Down
20 changes: 15 additions & 5 deletions validation/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ func TestOne(t *testing.T) {
assert.NotNil(t, validator, test.describe)

if test.expectRes != "" {
assert.Equal(t, test.expectRes, validator.Errors().One(), test.describe)
errors := validator.Errors()
assert.NotNil(t, errors)
assert.Equal(t, test.expectRes, errors.One(), test.describe)
}
}
}
Expand Down Expand Up @@ -119,10 +121,14 @@ func TestGet(t *testing.T) {
)
assert.Nil(t, err, test.describe)
if len(test.expectA) > 0 {
assert.Equal(t, test.expectA, validator.Errors().Get("a"), test.describe)
errors := validator.Errors()
assert.NotNil(t, errors)
assert.Equal(t, test.expectA, errors.Get("a"), test.describe)
}
if len(test.expectB) > 0 {
assert.Equal(t, test.expectB, validator.Errors().Get("b"), test.describe)
errors := validator.Errors()
assert.NotNil(t, errors)
assert.Equal(t, test.expectB, errors.Get("b"), test.describe)
}
}
}
Expand Down Expand Up @@ -164,7 +170,9 @@ func TestAll(t *testing.T) {
)
assert.Nil(t, err, test.describe)
if len(test.expectRes) > 0 {
assert.Equal(t, test.expectRes, validator.Errors().All(), test.describe)
errors := validator.Errors()
assert.NotNil(t, errors)
assert.Equal(t, test.expectRes, errors.All(), test.describe)
}
}
}
Expand Down Expand Up @@ -202,7 +210,9 @@ func TestHas(t *testing.T) {
)
assert.Nil(t, err, test.describe)
if test.expectRes {
assert.Equal(t, test.expectRes, validator.Errors().Has("a"), test.describe)
errors := validator.Errors()
assert.NotNil(t, errors)
assert.Equal(t, test.expectRes, errors.Has("a"), test.describe)
}
}
}

0 comments on commit 07dd54a

Please sign in to comment.