From dd136858f1ea40ad3c94191d647487fa4f31926c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 18 Oct 2024 20:33:49 +0200 Subject: Adding upstream version 9.0.0. Signed-off-by: Daniel Baumann --- modules/queue/mock/inmemorymockredis.go | 133 +++++++++++ modules/queue/mock/redisuniversalclient.go | 343 +++++++++++++++++++++++++++++ 2 files changed, 476 insertions(+) create mode 100644 modules/queue/mock/inmemorymockredis.go create mode 100644 modules/queue/mock/redisuniversalclient.go (limited to 'modules/queue/mock') diff --git a/modules/queue/mock/inmemorymockredis.go b/modules/queue/mock/inmemorymockredis.go new file mode 100644 index 0000000..de8bd8a --- /dev/null +++ b/modules/queue/mock/inmemorymockredis.go @@ -0,0 +1,133 @@ +package mock + +import ( + "context" + "errors" + + redis "github.com/redis/go-redis/v9" +) + +// InMemoryMockRedis is a very primitive in-memory redis-like feature. The main +// purpose of this struct is to give some backend to mocked unit tests. +type InMemoryMockRedis struct { + queues map[string][][]byte +} + +func NewInMemoryMockRedis() InMemoryMockRedis { + return InMemoryMockRedis{ + queues: map[string][][]byte{}, + } +} + +func (r *InMemoryMockRedis) LLen(ctx context.Context, key string) *redis.IntCmd { + cmd := redis.NewIntCmd(ctx) + cmd.SetVal(int64(len(r.queues[key]))) + return cmd +} + +func (r *InMemoryMockRedis) SAdd(ctx context.Context, key string, content []byte) *redis.IntCmd { + cmd := redis.NewIntCmd(ctx) + + for _, value := range r.queues[key] { + if string(value) == string(content) { + cmd.SetVal(0) + + return cmd + } + } + + r.queues[key] = append(r.queues[key], content) + + cmd.SetVal(1) + + return cmd +} + +func (r *InMemoryMockRedis) RPush(ctx context.Context, key string, content []byte) *redis.IntCmd { + cmd := redis.NewIntCmd(ctx) + + r.queues[key] = append(r.queues[key], content) + + cmd.SetVal(1) + + return cmd +} + +func (r *InMemoryMockRedis) LPop(ctx context.Context, key string) *redis.StringCmd { + cmd := redis.NewStringCmd(ctx) + + queue, found := r.queues[key] + if !found { + cmd.SetErr(errors.New("queue not found")) + + return cmd + } + + if len(queue) < 1 { + cmd.SetErr(errors.New("queue is empty")) + + return cmd + } + + value, rest := queue[0], queue[1:] + + r.queues[key] = rest + + cmd.SetVal(string(value)) + + return cmd +} + +func (r *InMemoryMockRedis) SRem(ctx context.Context, key string, content []byte) *redis.IntCmd { + cmd := redis.NewIntCmd(ctx) + + queue, found := r.queues[key] + if !found { + cmd.SetErr(errors.New("queue not found")) + + return cmd + } + + if len(queue) < 1 { + cmd.SetErr(errors.New("queue is empty")) + + return cmd + } + + newList := [][]byte{} + + for _, value := range queue { + if string(value) != string(content) { + newList = append(newList, value) + } + } + + r.queues[key] = newList + + cmd.SetVal(1) + + return cmd +} + +func (r *InMemoryMockRedis) SIsMember(ctx context.Context, key string, content []byte) *redis.BoolCmd { + cmd := redis.NewBoolCmd(ctx) + + queue, found := r.queues[key] + if !found { + cmd.SetErr(errors.New("queue not found")) + + return cmd + } + + for _, value := range queue { + if string(value) == string(content) { + cmd.SetVal(true) + + return cmd + } + } + + cmd.SetVal(false) + + return cmd +} diff --git a/modules/queue/mock/redisuniversalclient.go b/modules/queue/mock/redisuniversalclient.go new file mode 100644 index 0000000..36e4b7c --- /dev/null +++ b/modules/queue/mock/redisuniversalclient.go @@ -0,0 +1,343 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: code.gitea.io/gitea/modules/nosql (interfaces: RedisClient) +// +// Generated by this command: +// +// mockgen -package mock -destination ./modules/queue/mock/redisuniversalclient.go code.gitea.io/gitea/modules/nosql RedisClient +// + +// Package mock is a generated GoMock package. +package mock + +import ( + context "context" + reflect "reflect" + time "time" + + redis "github.com/redis/go-redis/v9" + gomock "go.uber.org/mock/gomock" +) + +// MockRedisClient is a mock of RedisClient interface. +type MockRedisClient struct { + ctrl *gomock.Controller + recorder *MockRedisClientMockRecorder +} + +// MockRedisClientMockRecorder is the mock recorder for MockRedisClient. +type MockRedisClientMockRecorder struct { + mock *MockRedisClient +} + +// NewMockRedisClient creates a new mock instance. +func NewMockRedisClient(ctrl *gomock.Controller) *MockRedisClient { + mock := &MockRedisClient{ctrl: ctrl} + mock.recorder = &MockRedisClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockRedisClient) EXPECT() *MockRedisClientMockRecorder { + return m.recorder +} + +// Close mocks base method. +func (m *MockRedisClient) Close() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Close") + ret0, _ := ret[0].(error) + return ret0 +} + +// Close indicates an expected call of Close. +func (mr *MockRedisClientMockRecorder) Close() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockRedisClient)(nil).Close)) +} + +// DBSize mocks base method. +func (m *MockRedisClient) DBSize(arg0 context.Context) *redis.IntCmd { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DBSize", arg0) + ret0, _ := ret[0].(*redis.IntCmd) + return ret0 +} + +// DBSize indicates an expected call of DBSize. +func (mr *MockRedisClientMockRecorder) DBSize(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DBSize", reflect.TypeOf((*MockRedisClient)(nil).DBSize), arg0) +} + +// Decr mocks base method. +func (m *MockRedisClient) Decr(arg0 context.Context, arg1 string) *redis.IntCmd { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Decr", arg0, arg1) + ret0, _ := ret[0].(*redis.IntCmd) + return ret0 +} + +// Decr indicates an expected call of Decr. +func (mr *MockRedisClientMockRecorder) Decr(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Decr", reflect.TypeOf((*MockRedisClient)(nil).Decr), arg0, arg1) +} + +// Del mocks base method. +func (m *MockRedisClient) Del(arg0 context.Context, arg1 ...string) *redis.IntCmd { + m.ctrl.T.Helper() + varargs := []any{arg0} + for _, a := range arg1 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Del", varargs...) + ret0, _ := ret[0].(*redis.IntCmd) + return ret0 +} + +// Del indicates an expected call of Del. +func (mr *MockRedisClientMockRecorder) Del(arg0 any, arg1 ...any) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0}, arg1...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Del", reflect.TypeOf((*MockRedisClient)(nil).Del), varargs...) +} + +// Exists mocks base method. +func (m *MockRedisClient) Exists(arg0 context.Context, arg1 ...string) *redis.IntCmd { + m.ctrl.T.Helper() + varargs := []any{arg0} + for _, a := range arg1 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Exists", varargs...) + ret0, _ := ret[0].(*redis.IntCmd) + return ret0 +} + +// Exists indicates an expected call of Exists. +func (mr *MockRedisClientMockRecorder) Exists(arg0 any, arg1 ...any) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0}, arg1...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Exists", reflect.TypeOf((*MockRedisClient)(nil).Exists), varargs...) +} + +// FlushDB mocks base method. +func (m *MockRedisClient) FlushDB(arg0 context.Context) *redis.StatusCmd { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "FlushDB", arg0) + ret0, _ := ret[0].(*redis.StatusCmd) + return ret0 +} + +// FlushDB indicates an expected call of FlushDB. +func (mr *MockRedisClientMockRecorder) FlushDB(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FlushDB", reflect.TypeOf((*MockRedisClient)(nil).FlushDB), arg0) +} + +// Get mocks base method. +func (m *MockRedisClient) Get(arg0 context.Context, arg1 string) *redis.StringCmd { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", arg0, arg1) + ret0, _ := ret[0].(*redis.StringCmd) + return ret0 +} + +// Get indicates an expected call of Get. +func (mr *MockRedisClientMockRecorder) Get(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockRedisClient)(nil).Get), arg0, arg1) +} + +// HDel mocks base method. +func (m *MockRedisClient) HDel(arg0 context.Context, arg1 string, arg2 ...string) *redis.IntCmd { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "HDel", varargs...) + ret0, _ := ret[0].(*redis.IntCmd) + return ret0 +} + +// HDel indicates an expected call of HDel. +func (mr *MockRedisClientMockRecorder) HDel(arg0, arg1 any, arg2 ...any) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HDel", reflect.TypeOf((*MockRedisClient)(nil).HDel), varargs...) +} + +// HKeys mocks base method. +func (m *MockRedisClient) HKeys(arg0 context.Context, arg1 string) *redis.StringSliceCmd { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "HKeys", arg0, arg1) + ret0, _ := ret[0].(*redis.StringSliceCmd) + return ret0 +} + +// HKeys indicates an expected call of HKeys. +func (mr *MockRedisClientMockRecorder) HKeys(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HKeys", reflect.TypeOf((*MockRedisClient)(nil).HKeys), arg0, arg1) +} + +// HSet mocks base method. +func (m *MockRedisClient) HSet(arg0 context.Context, arg1 string, arg2 ...any) *redis.IntCmd { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "HSet", varargs...) + ret0, _ := ret[0].(*redis.IntCmd) + return ret0 +} + +// HSet indicates an expected call of HSet. +func (mr *MockRedisClientMockRecorder) HSet(arg0, arg1 any, arg2 ...any) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HSet", reflect.TypeOf((*MockRedisClient)(nil).HSet), varargs...) +} + +// Incr mocks base method. +func (m *MockRedisClient) Incr(arg0 context.Context, arg1 string) *redis.IntCmd { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Incr", arg0, arg1) + ret0, _ := ret[0].(*redis.IntCmd) + return ret0 +} + +// Incr indicates an expected call of Incr. +func (mr *MockRedisClientMockRecorder) Incr(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Incr", reflect.TypeOf((*MockRedisClient)(nil).Incr), arg0, arg1) +} + +// LLen mocks base method. +func (m *MockRedisClient) LLen(arg0 context.Context, arg1 string) *redis.IntCmd { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LLen", arg0, arg1) + ret0, _ := ret[0].(*redis.IntCmd) + return ret0 +} + +// LLen indicates an expected call of LLen. +func (mr *MockRedisClientMockRecorder) LLen(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LLen", reflect.TypeOf((*MockRedisClient)(nil).LLen), arg0, arg1) +} + +// LPop mocks base method. +func (m *MockRedisClient) LPop(arg0 context.Context, arg1 string) *redis.StringCmd { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LPop", arg0, arg1) + ret0, _ := ret[0].(*redis.StringCmd) + return ret0 +} + +// LPop indicates an expected call of LPop. +func (mr *MockRedisClientMockRecorder) LPop(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LPop", reflect.TypeOf((*MockRedisClient)(nil).LPop), arg0, arg1) +} + +// Ping mocks base method. +func (m *MockRedisClient) Ping(arg0 context.Context) *redis.StatusCmd { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Ping", arg0) + ret0, _ := ret[0].(*redis.StatusCmd) + return ret0 +} + +// Ping indicates an expected call of Ping. +func (mr *MockRedisClientMockRecorder) Ping(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ping", reflect.TypeOf((*MockRedisClient)(nil).Ping), arg0) +} + +// RPush mocks base method. +func (m *MockRedisClient) RPush(arg0 context.Context, arg1 string, arg2 ...any) *redis.IntCmd { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "RPush", varargs...) + ret0, _ := ret[0].(*redis.IntCmd) + return ret0 +} + +// RPush indicates an expected call of RPush. +func (mr *MockRedisClientMockRecorder) RPush(arg0, arg1 any, arg2 ...any) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RPush", reflect.TypeOf((*MockRedisClient)(nil).RPush), varargs...) +} + +// SAdd mocks base method. +func (m *MockRedisClient) SAdd(arg0 context.Context, arg1 string, arg2 ...any) *redis.IntCmd { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "SAdd", varargs...) + ret0, _ := ret[0].(*redis.IntCmd) + return ret0 +} + +// SAdd indicates an expected call of SAdd. +func (mr *MockRedisClientMockRecorder) SAdd(arg0, arg1 any, arg2 ...any) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SAdd", reflect.TypeOf((*MockRedisClient)(nil).SAdd), varargs...) +} + +// SIsMember mocks base method. +func (m *MockRedisClient) SIsMember(arg0 context.Context, arg1 string, arg2 any) *redis.BoolCmd { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SIsMember", arg0, arg1, arg2) + ret0, _ := ret[0].(*redis.BoolCmd) + return ret0 +} + +// SIsMember indicates an expected call of SIsMember. +func (mr *MockRedisClientMockRecorder) SIsMember(arg0, arg1, arg2 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SIsMember", reflect.TypeOf((*MockRedisClient)(nil).SIsMember), arg0, arg1, arg2) +} + +// SRem mocks base method. +func (m *MockRedisClient) SRem(arg0 context.Context, arg1 string, arg2 ...any) *redis.IntCmd { + m.ctrl.T.Helper() + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "SRem", varargs...) + ret0, _ := ret[0].(*redis.IntCmd) + return ret0 +} + +// SRem indicates an expected call of SRem. +func (mr *MockRedisClientMockRecorder) SRem(arg0, arg1 any, arg2 ...any) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0, arg1}, arg2...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SRem", reflect.TypeOf((*MockRedisClient)(nil).SRem), varargs...) +} + +// Set mocks base method. +func (m *MockRedisClient) Set(arg0 context.Context, arg1 string, arg2 any, arg3 time.Duration) *redis.StatusCmd { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Set", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(*redis.StatusCmd) + return ret0 +} + +// Set indicates an expected call of Set. +func (mr *MockRedisClientMockRecorder) Set(arg0, arg1, arg2, arg3 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Set", reflect.TypeOf((*MockRedisClient)(nil).Set), arg0, arg1, arg2, arg3) +} -- cgit v1.2.3