Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
## Project Overview

Goravel Example (`github.com/goravel/example`) is the framework example package. It demonstrates how to use the Goravel framework to build a web application, including core architecture, common commands, and code rules.

## Code Rules

- Use `any` instead of `interface{}`.
- Never edit `mocks/` directly; run `go tool mockery` to regenerate.
- Follow standard Go formatting/naming; add comments where logic isn't self-evident. Go version is in go.mod.

### Tests

- Prefer `go test <pkg>` or `-run <TestName>` over `go test ./...` (slow).
- Use table-driven tests covering happy path, failure, and edge cases.
- Skip trivial getters/setters unless they contain non-trivial logic.
- Use `testify/assert` with `assert.*(t, *)` or `require.*(t, *)` directly, not `assert.New(t)`.
- Use `testify/suite` for related test groups, and use `s.*(*, *)` when asserting.
- Use the testify `EXPECT` method for mocks; avoid `mock.Anything`.
- Use `assert.AnError` if needed, and `assert.Equal` for error assertions.
- Assert full maps/structs/slices/arrays, not individual fields.
- Prefer direct value assertions over `mock.MatchedBy`; use it only for dynamically-generated args.
- Every mock must use `.Once()` or `.Times()`, only use `.Maybe()` when necessary; avoid no-op expectations.
- Name tests `Test<FunctionName>_[Optional]`; use table style or sub-tests for multiple cases.
- Don't use `assert.*` with `if` statements; use `assert.*` directly for clarity and better failure messages.
- Use `t.Run()` for sub-tests when testing multiple cases for the same function, and use table-driven tests for multiple cases with similar setup/assertions. Avoid writing separate test functions for each case when they share common logic.
- The basic table-driven test pattern is:

```go
func TestFunction(t *testing.T) {
// The name should start with `mock` to indicate it's a mocked function.
var (
ctx context.Context
mockFunc *mocks.MockedInterface
)

beforeEach := func() {
mockFunc = mocks.NewMockedInterface(t)
}

tests := []struct {
name string
input any
setup func()
expect any
expectError error
}{
{
name: "should do something",
input: someInput,
setup: func() {
mockFunc.EXPECT().SomeMethod(someArgs).Return(someResult, nil).Once()
},
expect: someResult,
expectError: nil,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
beforeEach()
tt.setup()

result, err := FunctionUnderTest(tt.input)
assert.Equal(t, tt.expect, result)
assert.Equal(t, tt.expectError, err)
})
}
}
```
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type M20250330911908AddColumnsToUsersTable struct{}

// Signature The unique signature for the migration.
func (r *M20250330911908AddColumnsToUsersTable) Signature() string {
return "20250331111908_add_columns_to_users_table"
return "20250330911908_add_columns_to_users_table"
}

// Up Run the migrations.
Expand All @@ -23,5 +23,7 @@ func (r *M20250330911908AddColumnsToUsersTable) Up() error {

// Down Reverse the migrations.
func (r *M20250330911908AddColumnsToUsersTable) Down() error {
return nil
return facades.Schema().Table("users", func(table schema.Blueprint) {
table.DropColumn("alias", "email")
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,11 @@ func (r *M20250331093125AlertColumnsOfUsersTable) Up() error {

// Down Reverse the migrations.
func (r *M20250331093125AlertColumnsOfUsersTable) Down() error {
if facades.Schema().HasTable("users") {
return facades.Schema().Table("users", func(table schema.Blueprint) {
table.RenameColumn("mail", "email")
})
}

return nil
}
10 changes: 9 additions & 1 deletion database/seeders/database_seeder.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package seeders

import (
"goravel/app/facades"
"goravel/app/models"
)

type DatabaseSeeder struct {
}

Expand All @@ -10,5 +15,8 @@ func (s *DatabaseSeeder) Signature() string {

// Run executes the seeder logic.
func (s *DatabaseSeeder) Run() error {
return nil
return facades.Orm().Query().Create(&models.User{
Name: "migration",
Mail: "migration@goravel.dev",
})
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/goravel/cos v1.17.0
github.com/goravel/example-proto v0.0.1
github.com/goravel/fiber v1.17.1-0.20260319150449-0a18b9c6e22b
github.com/goravel/framework v1.17.2-0.20260322042944-d61a6cc1601e
github.com/goravel/framework v1.17.2-0.20260329143353-aa89cf5921cb
github.com/goravel/gin v1.17.1-0.20260319150458-6d1543fdf889
github.com/goravel/minio v1.17.0
github.com/goravel/mysql v1.17.0
Expand All @@ -31,7 +31,7 @@ require (
github.com/vektah/gqlparser/v2 v2.5.19
go.opentelemetry.io/otel v1.42.0
go.opentelemetry.io/otel/metric v1.42.0
google.golang.org/grpc v1.79.2
google.golang.org/grpc v1.79.3
)

require (
Expand Down Expand Up @@ -240,4 +240,4 @@ require (
gorm.io/plugin/dbresolver v1.6.2 // indirect
)

replace github.com/goravel/framework => github.com/goravel/framework v1.17.2-0.20260322042944-d61a6cc1601e
replace github.com/goravel/framework => github.com/goravel/framework v1.17.2-0.20260329094602-be6d0d1dcf97
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ github.com/goravel/example-proto v0.0.1 h1:ZxETeKREQWjuJ49bX/Hqj1NLR5Vyj489Ks6dR
github.com/goravel/example-proto v0.0.1/go.mod h1:I8IPsHr4Ndf7KxmdsRpBR2LQ0Geo48+pjv9IIWf3mZg=
github.com/goravel/fiber v1.17.1-0.20260319150449-0a18b9c6e22b h1:peMAbfUTyQJCtA4wABmOowETE8N5v6i0GEy3vqVWeCg=
github.com/goravel/fiber v1.17.1-0.20260319150449-0a18b9c6e22b/go.mod h1:vVfU2LnxhCXOE1QH9U0/bFPBfIvbqCD3xyDkSm4wmVM=
github.com/goravel/framework v1.17.2-0.20260322042944-d61a6cc1601e h1:WXtXYc9lWIbpkbnGiPH4GtWopNh5KZaPEk/wipWPvDI=
github.com/goravel/framework v1.17.2-0.20260322042944-d61a6cc1601e/go.mod h1:2/eF2HWF3MFE1AIVnY5e+zebNCsawnMJRT14NzSiq/I=
github.com/goravel/framework v1.17.2-0.20260329094602-be6d0d1dcf97 h1:fD5VV8KfIGduf1bBigFCG3DGgdTUfz1Ek83c7cwcLaA=
github.com/goravel/framework v1.17.2-0.20260329094602-be6d0d1dcf97/go.mod h1:MksvSJ0GQTfVgIIbAqOPs7S3hQGtVCCfWhZSQNVSsBA=
github.com/goravel/gin v1.17.1-0.20260319150458-6d1543fdf889 h1:P1wUP46zVOoD3wXFrydvoBs3q8SfJO7Gk7TU6emKNZE=
github.com/goravel/gin v1.17.1-0.20260319150458-6d1543fdf889/go.mod h1:GsI8Ep1tfePcLHSx0vVtj+k3PLwpn/rUs4tKDFaH7b0=
github.com/goravel/minio v1.17.0 h1:WGiPP/KZl/fuDpT9THRM83wjhLCqe1oIAyNVJvVjhS4=
Expand Down Expand Up @@ -772,8 +772,8 @@ google.golang.org/genproto/googleapis/api v0.0.0-20260209200024-4cfbd4190f57 h1:
google.golang.org/genproto/googleapis/api v0.0.0-20260209200024-4cfbd4190f57/go.mod h1:kSJwQxqmFXeo79zOmbrALdflXQeAYcUbgS7PbpMknCY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171 h1:ggcbiqK8WWh6l1dnltU4BgWGIGo+EVYxCaAPih/zQXQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
google.golang.org/grpc v1.79.2 h1:fRMD94s2tITpyJGtBBn7MkMseNpOZU8ZxgC3MMBaXRU=
google.golang.org/grpc v1.79.2/go.mod h1:KmT0Kjez+0dde/v2j9vzwoAScgEPx/Bw1CYChhHLrHQ=
google.golang.org/grpc v1.79.3 h1:sybAEdRIEtvcD68Gx7dmnwjZKlyfuc61Dyo9pGXXkKE=
google.golang.org/grpc v1.79.3/go.mod h1:KmT0Kjez+0dde/v2j9vzwoAScgEPx/Bw1CYChhHLrHQ=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
4 changes: 3 additions & 1 deletion package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ func TestInstallAndUninstallLocalPackage(t *testing.T) {
assert.True(t, file.Exists(path.Base("packages", "example")))
assert.True(t, file.Exists(path.Base("packages", "example", "setup", "setup.go")))

assert.False(t, facades.Process().Run("go run . artisan package:install goravel/packages/example").Failed())
result := facades.Process().Run("go run . artisan package:install goravel/packages/example")
assert.NoError(t, result.Error())
assert.False(t, result.Failed())
assert.True(t, file.Contain(path.Bootstrap("providers.go"), "&example.ServiceProvider{},"))
assert.True(t, file.Contain(path.Bootstrap("providers.go"), "goravel/packages/example"))

Expand Down
4 changes: 0 additions & 4 deletions tests/feature/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"

contractshttp "github.com/goravel/framework/contracts/http"
"github.com/goravel/framework/support"
"github.com/goravel/framework/support/http"
"github.com/stretchr/testify/suite"

Expand Down Expand Up @@ -103,9 +102,6 @@ func (s *HttpTestSuite) TestInputMapArray() {
}

func (s *HttpTestSuite) TestLang() {
// Change working directory to project root to use current lang files
s.T().Chdir(support.RelativePath)

tests := []struct {
name string
lang string
Expand Down
Loading
Loading