-
Notifications
You must be signed in to change notification settings - Fork 0
V0.5.1 #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
irammini
wants to merge
9
commits into
main
Choose a base branch
from
0.5.1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
V0.5.1 #4
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
44f4a2b
Add unit tests for critical packages (handlers, processor, cache, rat…
irammini faa0233
Add integration tests and update CI
irammini 25c977a
Fix errors
irammini 4bbb1f4
feat: add comprehensive unit tests for core packages
irammini 014140b
perf: clean comments
irammini f2785a2
add P into `.gitignore`
irammini 6cd8532
fix: compilation error in processor_test.go by skipping unsupported P…
irammini 3a37734
fix: integration test binary names and `.env` generation
irammini ba814b5
fix: integration test image generation
irammini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| name: Mirror to Codeberg | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| schedule: | ||
| # Runs at 00:00 UTC every day | ||
| - cron: '0 0 * * *' | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| mirror_to_codeberg: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v6.0.2 | ||
| with: | ||
| # Fetch all history for all branches and tags | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Mirror to Codeberg | ||
| run: | | ||
| REMOTE_URL="https://${{ secrets.CODEBERG_USERNAME }}:${{ secrets.CODEBERG_TOKEN }}@codeberg.org/${{ secrets.CODEBERG_ORG }}/${{ github.event.repository.name }}.git" | ||
|
|
||
| git remote add codeberg "$REMOTE_URL" | ||
| git push --mirror codeberg | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,7 @@ import ( | |
| ) | ||
|
|
||
| var ( | ||
| Version = "0.5.0" | ||
| Version = "0.5.1" | ||
| ) | ||
|
|
||
| func main() { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| package cache | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
| "time" | ||
| ) | ||
|
|
||
| // MockCacheProvider | ||
| type MockCacheProvider struct { | ||
| GetFunc func(ctx context.Context, key string) ([]byte, bool) | ||
| SetFunc func(ctx context.Context, key string, value []byte, ttl time.Duration) error | ||
| DeleteFunc func(ctx context.Context, key string) error | ||
| HealthFunc func(ctx context.Context) error | ||
| } | ||
|
|
||
| func (m *MockCacheProvider) Get(ctx context.Context, key string) ([]byte, bool) { | ||
| if m.GetFunc != nil { | ||
| return m.GetFunc(ctx, key) | ||
| } | ||
| return nil, false | ||
| } | ||
|
|
||
| func (m *MockCacheProvider) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error { | ||
| if m.SetFunc != nil { | ||
| return m.SetFunc(ctx, key, value, ttl) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (m *MockCacheProvider) Delete(ctx context.Context, key string) error { | ||
| if m.DeleteFunc != nil { | ||
| return m.DeleteFunc(ctx, key) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (m *MockCacheProvider) Health(ctx context.Context) error { | ||
| if m.HealthFunc != nil { | ||
| return m.HealthFunc(ctx) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func TestTieredCache_Get_HitL1(t *testing.T) { | ||
| ctx := context.Background() | ||
| key := "test-key" | ||
| val := []byte("value") | ||
|
|
||
| l1 := &MockCacheProvider{ | ||
| GetFunc: func(ctx context.Context, k string) ([]byte, bool) { | ||
| if k == key { | ||
| return val, true | ||
| } | ||
| return nil, false | ||
| }, | ||
| } | ||
| l2 := &MockCacheProvider{ | ||
| GetFunc: func(ctx context.Context, k string) ([]byte, bool) { | ||
| t.Error("L2 should not be called") | ||
| return nil, false | ||
| }, | ||
| } | ||
|
|
||
| c := NewTieredCache(l1, l2) | ||
|
|
||
| got, found := c.Get(ctx, key) | ||
| if !found { | ||
| t.Error("Expected found") | ||
| } | ||
| if string(got) != string(val) { | ||
| t.Errorf("Expected %s, got %s", val, got) | ||
| } | ||
| } | ||
|
|
||
| func TestTieredCache_Get_HitL2(t *testing.T) { | ||
| ctx := context.Background() | ||
| key := "test-key" | ||
| val := []byte("value") | ||
|
|
||
| l1SetCalled := false | ||
| l1 := &MockCacheProvider{ | ||
| GetFunc: func(ctx context.Context, k string) ([]byte, bool) { | ||
| return nil, false | ||
| }, | ||
| SetFunc: func(ctx context.Context, k string, v []byte, ttl time.Duration) error { | ||
| if k == key && string(v) == string(val) { | ||
| l1SetCalled = true | ||
| } | ||
| return nil | ||
| }, | ||
| } | ||
| l2 := &MockCacheProvider{ | ||
| GetFunc: func(ctx context.Context, k string) ([]byte, bool) { | ||
| if k == key { | ||
| return val, true | ||
| } | ||
| return nil, false | ||
| }, | ||
| } | ||
|
|
||
| c := NewTieredCache(l1, l2) | ||
|
|
||
| got, found := c.Get(ctx, key) | ||
| if !found { | ||
| t.Error("Expected found") | ||
| } | ||
| if string(got) != string(val) { | ||
| t.Errorf("Expected %s, got %s", val, got) | ||
| } | ||
| if !l1SetCalled { | ||
| t.Error("Expected L1 Set to be called") | ||
| } | ||
| } | ||
|
|
||
| func TestTieredCache_Get_MissAll(t *testing.T) { | ||
| ctx := context.Background() | ||
| key := "test-key" | ||
|
|
||
| l1 := &MockCacheProvider{ | ||
| GetFunc: func(ctx context.Context, k string) ([]byte, bool) { | ||
| return nil, false | ||
| }, | ||
| } | ||
| l2 := &MockCacheProvider{ | ||
| GetFunc: func(ctx context.Context, k string) ([]byte, bool) { | ||
| return nil, false | ||
| }, | ||
| } | ||
|
|
||
| c := NewTieredCache(l1, l2) | ||
|
|
||
| _, found := c.Get(ctx, key) | ||
| if found { | ||
| t.Error("Expected not found") | ||
| } | ||
| } | ||
|
|
||
| func TestTieredCache_Promote_L2_to_L1(t *testing.T) { | ||
| ctx := context.Background() | ||
| key := "promo-key" | ||
| val := []byte("promo-value") | ||
|
|
||
| l1SetCalled := false | ||
| l1 := &MockCacheProvider{ | ||
| GetFunc: func(ctx context.Context, k string) ([]byte, bool) { | ||
| return nil, false // Miss | ||
| }, | ||
| SetFunc: func(ctx context.Context, k string, v []byte, ttl time.Duration) error { | ||
| if k != key { | ||
| t.Errorf("L1 Set called with wrong key: %s", k) | ||
| } | ||
| if string(v) != string(val) { | ||
| t.Errorf("L1 Set called with wrong value: %s", v) | ||
| } | ||
| l1SetCalled = true | ||
| return nil | ||
| }, | ||
| } | ||
| l2 := &MockCacheProvider{ | ||
| GetFunc: func(ctx context.Context, k string) ([]byte, bool) { | ||
| if k == key { | ||
| return val, true // Hit | ||
| } | ||
| return nil, false | ||
| }, | ||
| } | ||
|
|
||
| c := NewTieredCache(l1, l2) | ||
|
|
||
| got, found := c.Get(ctx, key) | ||
| if !found { | ||
| t.Error("Expected found") | ||
| } | ||
| if string(got) != string(val) { | ||
| t.Errorf("Expected %s, got %s", val, got) | ||
| } | ||
|
|
||
| if !l1SetCalled { | ||
| t.Error("Expected L1 Set to be called to promote value from L2") | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package config | ||
|
|
||
| import ( | ||
| "os" | ||
| "testing" | ||
| "time" | ||
| ) | ||
|
|
||
| func TestLoadConfig_AllowedCIDRs(t *testing.T) { | ||
| // Setup env | ||
| os.Setenv("ALLOWED_CIDRS", "192.168.1.0/24,10.0.0.1/32,invalid-ip") | ||
| defer os.Unsetenv("ALLOWED_CIDRS") | ||
|
|
||
| cfg := LoadConfig() | ||
|
|
||
| if len(cfg.AllowedCIDRs) != 3 { | ||
| t.Errorf("Expected 3 raw CIDR strings, got %d", len(cfg.AllowedCIDRs)) | ||
| } | ||
|
|
||
| // Check AllowedCIDRNets | ||
| if len(cfg.AllowedCIDRNets) != 2 { | ||
| t.Errorf("Expected 2 valid IPNets, got %d", len(cfg.AllowedCIDRNets)) | ||
| } | ||
|
|
||
| // Verify the parsed nets | ||
| // 192.168.1.0/24 | ||
| if cfg.AllowedCIDRNets[0].String() != "192.168.1.0/24" { | ||
| t.Errorf("Expected first CIDR to be 192.168.1.0/24, got %s", cfg.AllowedCIDRNets[0].String()) | ||
| } | ||
| // 10.0.0.1/32 | ||
| if cfg.AllowedCIDRNets[1].String() != "10.0.0.1/32" { | ||
| t.Errorf("Expected second CIDR to be 10.0.0.1/32, got %s", cfg.AllowedCIDRNets[1].String()) | ||
| } | ||
| } | ||
|
|
||
| func TestLoadConfig_Defaults(t *testing.T) { | ||
| // Unset relevant env vars to test defaults | ||
| vars := []string{"RATE_LIMIT", "CACHE_TTL_HOURS", "S3_FORCE_PATH_STYLE"} | ||
| for _, v := range vars { | ||
| // Store old value to restore | ||
| oldVal, exists := os.LookupEnv(v) | ||
| if exists { | ||
| os.Unsetenv(v) | ||
| defer os.Setenv(v, oldVal) | ||
| } else { | ||
| // Ensure it stays unset? | ||
| // Defer nothing if it didn't exist | ||
| } | ||
| } | ||
|
|
||
| cfg := LoadConfig() | ||
|
|
||
| if cfg.RateLimit != 10 { | ||
| t.Errorf("Expected default RateLimit 10, got %d", cfg.RateLimit) | ||
| } | ||
|
|
||
| expectedTTL := 24 * time.Hour | ||
| if cfg.CacheTTL != expectedTTL { | ||
| t.Errorf("Expected default CacheTTL %v, got %v", expectedTTL, cfg.CacheTTL) | ||
| } | ||
|
|
||
| if cfg.S3ForcePathStyle != false { | ||
| t.Errorf("Expected default S3ForcePathStyle false, got %v", cfg.S3ForcePathStyle) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.