mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-31 01:17:56 +00:00
add cache mock for organization
This commit is contained in:
@@ -27,22 +27,22 @@ type Organization struct {
|
||||
Domains []*OrganizationDomain `json:"domains,omitempty" db:"-"` // domains need to be handled separately
|
||||
}
|
||||
|
||||
type orgCacheIndex uint8
|
||||
type OrgCacheIndex uint8
|
||||
|
||||
const (
|
||||
orgCacheIndexUndefined orgCacheIndex = iota
|
||||
orgCacheIndexUndefined OrgCacheIndex = iota
|
||||
orgCacheIndexID
|
||||
)
|
||||
|
||||
// Keys implements the [cache.Entry].
|
||||
func (o *Organization) Keys(index orgCacheIndex) (key []string) {
|
||||
func (o *Organization) Keys(index OrgCacheIndex) (key []string) {
|
||||
if index == orgCacheIndexID {
|
||||
return []string{o.ID}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ cache.Entry[orgCacheIndex, string] = (*Organization)(nil)
|
||||
var _ cache.Entry[OrgCacheIndex, string] = (*Organization)(nil)
|
||||
|
||||
// OrgIdentifierCondition is used to help specify a single Organization,
|
||||
// it will either be used as the organization ID or organization name,
|
||||
|
||||
@@ -12,7 +12,7 @@ func TestOrganization_Keys(t *testing.T) {
|
||||
tt := []struct {
|
||||
name string
|
||||
org *Organization
|
||||
index orgCacheIndex
|
||||
index OrgCacheIndex
|
||||
wantKeys []string
|
||||
}{
|
||||
{
|
||||
|
||||
50
backend/v3/storage/cache/cachemock/organization.go
vendored
Normal file
50
backend/v3/storage/cache/cachemock/organization.go
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
package cachemock
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zitadel/zitadel/backend/v3/domain"
|
||||
"github.com/zitadel/zitadel/backend/v3/storage/cache"
|
||||
)
|
||||
|
||||
type OrganizationCacheMock struct {
|
||||
c map[string]*domain.Organization
|
||||
}
|
||||
|
||||
func NewOrganizationCacheMock() *OrganizationCacheMock {
|
||||
return &OrganizationCacheMock{
|
||||
c: make(map[string]*domain.Organization),
|
||||
}
|
||||
}
|
||||
|
||||
// Delete implements cache.Cache.
|
||||
func (o *OrganizationCacheMock) Delete(_ context.Context, _ domain.OrgCacheIndex, keys ...string) error {
|
||||
for _, key := range keys {
|
||||
delete(o.c, key)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get implements cache.Cache.
|
||||
func (o *OrganizationCacheMock) Get(_ context.Context, _ domain.OrgCacheIndex, key string) (*domain.Organization, bool) {
|
||||
res, ok := o.c[key]
|
||||
return res, ok
|
||||
}
|
||||
|
||||
// Invalidate implements cache.Cache.
|
||||
func (o *OrganizationCacheMock) Invalidate(ctx context.Context, i domain.OrgCacheIndex, key ...string) error {
|
||||
return o.Delete(ctx, i, key...)
|
||||
}
|
||||
|
||||
// Set implements cache.Cache.
|
||||
func (o *OrganizationCacheMock) Set(_ context.Context, organization *domain.Organization) {
|
||||
o.c[organization.ID] = organization
|
||||
}
|
||||
|
||||
// Truncate implements cache.Cache.
|
||||
func (o *OrganizationCacheMock) Truncate(_ context.Context) error {
|
||||
o.c = make(map[string]*domain.Organization)
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ cache.Cache[domain.OrgCacheIndex, string, *domain.Organization] = (*OrganizationCacheMock)(nil)
|
||||
Reference in New Issue
Block a user