Compare commits

...
Sign in to create a new pull request.

4 commits

Author SHA1 Message Date
6640c5a816 📝 Update Git Flow Workflow guidelines in AGENTS.md 2025-11-12 08:39:19 -06:00
49e470b10d 📝 Add agent guidelines and conventions 2025-11-11 12:01:26 -06:00
0c42f256ea Replace assert with be in testing 2025-09-26 22:03:43 -05:00
993eb239d1 🔀 Merge tag 'v0.5.2' into develop
 Add testable examples
2025-04-21 14:44:26 -05:00
4 changed files with 69 additions and 37 deletions

46
AGENTS.md Normal file
View file

@ -0,0 +1,46 @@
# Agent Guidelines for ezcache
This document outlines the conventions and commands for agents operating within the `ezcache` Go project.
## Build/Lint/Test Commands
- **Build:** `go build ./...`
- **Lint:** `task lint`
- **Test All:** `task test`
- **Test Single File:** `go test -run <TestName> <path/to/file_test.go>` (e.g., `go test -run TestNewHappy ./ezcache_test.go`)
- **Format:** `task fmt`
## Code Style Guidelines
- **Module**: `codeberg.org/danjones000/ezcache`
- **Go version**: 1.23.7
- **Imports:** Group standard library imports separately from third-party imports.
- **Formatting:** Adhere to `go fmt` standards.
- **Naming Conventions:**
- Variables: `camelCase`
- Functions/Methods: `CamelCase` (exported), `camelCase` (unexported)
- Packages: `lowercase`
- **Error Handling:** Return errors explicitly. Check errors immediately after a function call that returns an error.
- **Types:** Use generics where appropriate, as seen in `ezcache.go`.
- **Concurrency:** Use `sync.RWMutex` for concurrent map access, as demonstrated in `ezcache.go`.
- **Linter Rules:** Refer to `.golangci.yaml` for detailed linting rules.
- **Testing**: Use `github.com/nalgeon/be`
## Git Commit Guidelines
- **Format**: Prepend commit messages with a gitmoji emoji (see https://gitmoji.dev)
- **Style**: Write detailed commit messages that explain what changed and why
- **Examples**: `✨ Add JSON export functionality for log entries`, `🐛 Fix date parsing for RFC3339 timestamps`, `📝 Update README with configuration examples`
## Git Flow Workflow
- **Main branches**: `stable` (production-ready), `develop` (integration branch)
- **Development**: Always commit new features/fixes to `develop` branch or appropriate feature branches
- **Branch prefixes**:
- `feat/feature-name` - New features, merge to `develop` when complete
- `bug/bug-name` - Bug fixes (non-urgent), merge to `develop` when complete
- `rel/version` - Release preparation branches, merge to `stable` and then **also** merge `stable` back to `develop`
- `hot/version` - Hotfixes for production issues follow same merge rules as releases
- **Version tags**: Prefix all version tags with `v` (e.g., `v1.0.2`, `v0.0.6`)
- **Releases**: Update CHANGELOG.md with a summary of changes for each new version
- **Never commit directly to** `stable` branch (only merge from `rel/` or `hot/` branches)
- After merging to `stable`, always merge it back to `develop`
- **Before starting work**: Ensure you're on `develop` branch or create an appropriate feature branch from it

View file

@ -7,7 +7,7 @@ import (
"time"
"codeberg.org/danjones000/ezcache"
"github.com/stretchr/testify/assert"
"github.com/nalgeon/be"
)
var fetcher ezcache.Fetcher[uint8, string] = func(key uint8) (string, error) { return fmt.Sprintf("%d", key), nil }
@ -15,15 +15,15 @@ var fetcher ezcache.Fetcher[uint8, string] = func(key uint8) (string, error) { r
func TestNewHappy(t *testing.T) {
cache, err := ezcache.New(fetcher, 1)
assert.NoError(t, err)
assert.NotNil(t, cache)
be.Err(t, err, nil)
be.True(t, cache != nil)
}
func TestNewNilFetcher(t *testing.T) {
cache, err := ezcache.New[uint8, string](nil, 1)
assert.ErrorIs(t, err, ezcache.ErrInvalidFetcher)
assert.Nil(t, cache)
be.Err(t, err, ezcache.ErrInvalidFetcher)
be.True(t, cache == nil)
}
func TestNewBadExpiry(tt *testing.T) {
@ -38,8 +38,8 @@ func TestNewBadExpiry(tt *testing.T) {
tt.Run(tc.name, func(t *testing.T) {
cache, err := ezcache.New(fetcher, tc.exp)
assert.ErrorIs(t, err, ezcache.ErrInvalidExpiry)
assert.Nil(t, cache)
be.Err(t, err, ezcache.ErrInvalidExpiry)
be.True(t, cache == nil)
})
}
}
@ -49,15 +49,15 @@ func TestGetHappy(t *testing.T) {
cache, _ := ezcache.New(func(key uint8) (string, error) { hit = true; return fetcher(key) }, 5*time.Second)
val, err := cache.Get(4)
assert.NoError(t, err)
assert.Equal(t, "4", val)
assert.True(t, hit)
be.Err(t, err, nil)
be.Equal(t, val, "4")
be.True(t, hit)
hit = false
val, err = cache.Get(4)
assert.NoError(t, err)
assert.Equal(t, "4", val)
assert.False(t, hit)
be.Err(t, err, nil)
be.Equal(t, val, "4")
be.True(t, !hit)
}
func TestGetExpire(t *testing.T) {
@ -65,16 +65,16 @@ func TestGetExpire(t *testing.T) {
cache, _ := ezcache.New(func(key uint8) (string, error) { hit = true; return fetcher(key) }, 1)
val, err := cache.Get(4)
assert.NoError(t, err)
assert.Equal(t, "4", val)
assert.True(t, hit)
be.Err(t, err, nil)
be.Equal(t, val, "4")
be.True(t, hit)
hit = false
time.Sleep(2 * time.Nanosecond)
val, err = cache.Get(4)
assert.NoError(t, err)
assert.Equal(t, "4", val)
assert.True(t, hit)
be.Err(t, err, nil)
be.Equal(t, val, "4")
be.True(t, hit)
}
func TestGetError(t *testing.T) {
@ -82,5 +82,5 @@ func TestGetError(t *testing.T) {
cache, _ := ezcache.New(func(k uint8) (byte, error) { return 0, fmt.Errorf("Nope for %d", k) }, 1)
_, err := cache.Get(4)
assert.ErrorContains(t, err, "Nope for 4")
be.Err(t, err, "Nope for 4")
}

8
go.mod
View file

@ -2,10 +2,4 @@ module codeberg.org/danjones000/ezcache
go 1.23.7
require github.com/stretchr/testify v1.10.0
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
require github.com/nalgeon/be v0.3.0

12
go.sum
View file

@ -1,10 +1,2 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
github.com/nalgeon/be v0.3.0 h1:QsPANqEtcOD5qT2S3KAtIkDBBn8SXUf/Lb5Bi/z4UqM=
github.com/nalgeon/be v0.3.0/go.mod h1:PMwMuBLopwKJkSHnr2qHyLcZYUTqNejN7A8RAqNWO3E=