Skip to content

Commit

Permalink
refactor Redigo.Simple according to new structure (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
xh3b4sd authored Oct 16, 2023
1 parent ec5662c commit f92a44c
Show file tree
Hide file tree
Showing 34 changed files with 536 additions and 515 deletions.
6 changes: 3 additions & 3 deletions pkg/fake/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ type Backup struct {
FakeCreate func() error
}

func (b *Backup) Create() error {
if b.FakeCreate != nil {
return b.FakeCreate()
func (f *Backup) Create() error {
if f.FakeCreate != nil {
return f.FakeCreate()
}

return nil
Expand Down
18 changes: 9 additions & 9 deletions pkg/fake/locker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ type Locker struct {
FakeRelease func() error
}

func (l *Locker) Acquire() error {
if l.FakeAcquire != nil {
return l.FakeAcquire()
func (f *Locker) Acquire() error {
if f.FakeAcquire != nil {
return f.FakeAcquire()
}

return nil
}

func (l *Locker) Refresh() error {
if l.FakeRefresh != nil {
return l.FakeRefresh()
func (f *Locker) Refresh() error {
if f.FakeRefresh != nil {
return f.FakeRefresh()
}

return nil
}

func (l *Locker) Release() error {
if l.FakeRelease != nil {
return l.FakeRelease()
func (f *Locker) Release() error {
if f.FakeRelease != nil {
return f.FakeRelease()
}

return nil
Expand Down
12 changes: 6 additions & 6 deletions pkg/fake/pub_sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ type PubSub struct {
FakeSub func(key string) (<-chan string, error)
}

func (p *PubSub) Pub(key string, val string) error {
if p.FakePub != nil {
return p.FakePub(key, val)
func (f *PubSub) Pub(key string, val string) error {
if f.FakePub != nil {
return f.FakePub(key, val)
}

return nil
}

func (p *PubSub) Sub(key string) (<-chan string, error) {
if p.FakeSub != nil {
return p.FakeSub(key)
func (f *PubSub) Sub(key string) (<-chan string, error) {
if f.FakeSub != nil {
return f.FakeSub(key)
}

return nil, nil
Expand Down
7 changes: 4 additions & 3 deletions pkg/fake/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"github.com/xh3b4sd/redigo/pkg/simple"
"github.com/xh3b4sd/redigo/pkg/simple/create"
"github.com/xh3b4sd/redigo/pkg/simple/delete"
"github.com/xh3b4sd/redigo/pkg/simple/exists"
"github.com/xh3b4sd/redigo/pkg/simple/search"
)

type Simple struct {
Expand All @@ -18,7 +20,6 @@ func (s *Simple) Create() simple.Create {
return s.FakeCreate()
}

// TODO refactor all fake methods like this new way
return &create.Fake{}
}

Expand All @@ -35,13 +36,13 @@ func (s *Simple) Exists() simple.Exists {
return s.FakeExists()
}

return &SimpleExists{}
return &exists.Fake{}
}

func (s *Simple) Search() simple.Search {
if s.FakeSearch != nil {
return s.FakeSearch()
}

return &SimpleSearch{}
return &search.Fake{}
}
13 changes: 0 additions & 13 deletions pkg/fake/simple_exists.go

This file was deleted.

13 changes: 0 additions & 13 deletions pkg/fake/simple_search.go

This file was deleted.

4 changes: 3 additions & 1 deletion pkg/fake/sorted.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fake

import (
"github.com/xh3b4sd/redigo/pkg/sorted"
"github.com/xh3b4sd/redigo/pkg/sorted/create"
)

type Sorted struct {
Expand All @@ -15,11 +16,12 @@ type Sorted struct {
}

func (s *Sorted) Create() sorted.Create {
// TODO refactor all fake methods the new way
if s.FakeCreate != nil {
return s.FakeCreate()
}

return &SortedCreate{}
return &create.Fake{}
}

func (s *Sorted) Delete() sorted.Delete {
Expand Down
22 changes: 0 additions & 22 deletions pkg/fake/sorted_create.go

This file was deleted.

30 changes: 15 additions & 15 deletions pkg/fake/sorted_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,41 @@ type SortedDelete struct {
FakeValue func() error
}

func (d *SortedDelete) Clean(key string) error {
if d.FakeClean != nil {
return d.FakeClean()
func (f *SortedDelete) Clean(key string) error {
if f.FakeClean != nil {
return f.FakeClean()
}

return nil
}

func (d *SortedDelete) Index(key string, val ...string) error {
if d.FakeIndex != nil {
return d.FakeIndex()
func (f *SortedDelete) Index(key string, val ...string) error {
if f.FakeIndex != nil {
return f.FakeIndex()
}

return nil
}

func (d *SortedDelete) Limit(key string, lim int) error {
if d.FakeLimit != nil {
return d.FakeLimit()
func (f *SortedDelete) Limit(key string, lim int) error {
if f.FakeLimit != nil {
return f.FakeLimit()
}

return nil
}

func (d *SortedDelete) Score(key string, sco float64) error {
if d.FakeScore != nil {
return d.FakeScore()
func (f *SortedDelete) Score(key string, sco float64) error {
if f.FakeScore != nil {
return f.FakeScore()
}

return nil
}

func (d *SortedDelete) Value(key string, val ...string) error {
if d.FakeValue != nil {
return d.FakeValue()
func (f *SortedDelete) Value(key string, val ...string) error {
if f.FakeValue != nil {
return f.FakeValue()
}

return nil
Expand Down
18 changes: 9 additions & 9 deletions pkg/fake/sorted_exists.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ type SortedExists struct {
FakeValue func() (bool, error)
}

func (e *SortedExists) Index(key string, ind string) (bool, error) {
if e.FakeIndex != nil {
return e.FakeIndex()
func (f *SortedExists) Index(key string, ind string) (bool, error) {
if f.FakeIndex != nil {
return f.FakeIndex()
}

return false, nil
}

func (e *SortedExists) Score(key string, sco float64) (bool, error) {
if e.FakeScore != nil {
return e.FakeScore()
func (f *SortedExists) Score(key string, sco float64) (bool, error) {
if f.FakeScore != nil {
return f.FakeScore()
}

return false, nil
}

func (e *SortedExists) Value(key string, val string) (bool, error) {
if e.FakeValue != nil {
return e.FakeValue()
func (f *SortedExists) Value(key string, val string) (bool, error) {
if f.FakeValue != nil {
return f.FakeValue()
}

return false, nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/fake/sorted_floats.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ type SortedFloats struct {
FakeScore func() (float64, error)
}

func (e *SortedFloats) Score(key string, val string, sco float64) (float64, error) {
if e.FakeScore != nil {
return e.FakeScore()
func (f *SortedFloats) Score(key string, val string, sco float64) (float64, error) {
if f.FakeScore != nil {
return f.FakeScore()
}

return 0, nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/fake/sorted_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ type SortedMetric struct {
FakeCount func() (int64, error)
}

func (s *SortedMetric) Count(key string) (int64, error) {
if s.FakeCount != nil {
return s.FakeCount()
func (f *SortedMetric) Count(key string) (int64, error) {
if f.FakeCount != nil {
return f.FakeCount()
}

return 0, nil
Expand Down
36 changes: 18 additions & 18 deletions pkg/fake/sorted_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,49 @@ type SortedSearch struct {
FakeUnion func() ([]string, error)
}

func (s *SortedSearch) Index(key string, ind string) (string, error) {
if s.FakeIndex != nil {
return s.FakeIndex()
func (f *SortedSearch) Index(key string, ind string) (string, error) {
if f.FakeIndex != nil {
return f.FakeIndex()
}

return "", nil
}

func (s *SortedSearch) Inter(key ...string) ([]string, error) {
if s.FakeInter != nil {
return s.FakeInter()
func (f *SortedSearch) Inter(key ...string) ([]string, error) {
if f.FakeInter != nil {
return f.FakeInter()
}

return nil, nil
}

func (s *SortedSearch) Order(key string, lef int, rig int, sco ...bool) ([]string, error) {
if s.FakeOrder != nil {
return s.FakeOrder()
func (f *SortedSearch) Order(key string, lef int, rig int, sco ...bool) ([]string, error) {
if f.FakeOrder != nil {
return f.FakeOrder()
}

return nil, nil
}

func (s *SortedSearch) Rando(key string, cou ...uint) ([]string, error) {
if s.FakeRando != nil {
return s.FakeRando()
func (f *SortedSearch) Rando(key string, cou ...uint) ([]string, error) {
if f.FakeRando != nil {
return f.FakeRando()
}

return nil, nil
}

func (s *SortedSearch) Score(key string, lef float64, rig float64) ([]string, error) {
if s.FakeScore != nil {
return s.FakeScore()
func (f *SortedSearch) Score(key string, lef float64, rig float64) ([]string, error) {
if f.FakeScore != nil {
return f.FakeScore()
}

return nil, nil
}

func (s *SortedSearch) Union(key ...string) ([]string, error) {
if s.FakeUnion != nil {
return s.FakeUnion()
func (f *SortedSearch) Union(key ...string) ([]string, error) {
if f.FakeUnion != nil {
return f.FakeUnion()
}

return nil, nil
Expand Down
12 changes: 6 additions & 6 deletions pkg/fake/sorted_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ type SortedUpdate struct {
FakeScore func() (bool, error)
}

func (u *SortedUpdate) Index(key string, new string, sco float64, ind ...string) (bool, error) {
if u.FakeIndex != nil {
return u.FakeIndex()
func (f *SortedUpdate) Index(key string, new string, sco float64, ind ...string) (bool, error) {
if f.FakeIndex != nil {
return f.FakeIndex()
}

return false, nil
}

func (u *SortedUpdate) Score(key string, new string, sco float64) (bool, error) {
if u.FakeScore != nil {
return u.FakeScore()
func (f *SortedUpdate) Score(key string, new string, sco float64) (bool, error) {
if f.FakeScore != nil {
return f.FakeScore()
}

return false, nil
Expand Down
Loading

0 comments on commit f92a44c

Please sign in to comment.