mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 18:07:31 +00:00
fixup! fixup! fix(projections): added check to make sure there cannot be 2 projections for the same table
This commit is contained in:
3
internal/query/projection/mock.go
Normal file
3
internal/query/projection/mock.go
Normal file
@@ -0,0 +1,3 @@
|
||||
package projection
|
||||
|
||||
//go:generate mockgen -source projection.go -destination ./projection_mock.go -package projection
|
70
internal/query/projection/projection_test.go
Normal file
70
internal/query/projection/projection_test.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package projection
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/brianvoe/gofakeit/v6"
|
||||
"github.com/stretchr/testify/require"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
func TestStart(t *testing.T) {
|
||||
duplicateName := gofakeit.Name()
|
||||
tests := []struct {
|
||||
name string
|
||||
projections func(t *testing.T) []projection
|
||||
err error
|
||||
}{
|
||||
{
|
||||
name: "happy path",
|
||||
projections: func(t *testing.T) []projection {
|
||||
ctrl := gomock.NewController(t)
|
||||
projections := make([]projection, 5, 5)
|
||||
|
||||
for i := range 5 {
|
||||
mock := NewMockprojection(ctrl)
|
||||
mock.EXPECT().Start(gomock.Any())
|
||||
mock.EXPECT().String().Return(gofakeit.Name())
|
||||
projections[i] = mock
|
||||
}
|
||||
|
||||
return projections
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "same projection used twice error",
|
||||
projections: func(t *testing.T) []projection {
|
||||
projections := make([]projection, 5, 5)
|
||||
|
||||
ctrl := gomock.NewController(t)
|
||||
mock := NewMockprojection(ctrl)
|
||||
mock.EXPECT().String().Return(duplicateName)
|
||||
mock.EXPECT().Start(gomock.Any())
|
||||
projections[0] = mock
|
||||
|
||||
for i := 1; i < 4; i++ {
|
||||
mock := NewMockprojection(ctrl)
|
||||
mock.EXPECT().String().Return(gofakeit.Name())
|
||||
mock.EXPECT().Start(gomock.Any())
|
||||
projections[i] = mock
|
||||
}
|
||||
|
||||
mock = NewMockprojection(ctrl)
|
||||
mock.EXPECT().String().Return(duplicateName)
|
||||
mock.EXPECT().Start(gomock.Any())
|
||||
projections[4] = mock
|
||||
|
||||
return projections
|
||||
},
|
||||
err: fmt.Errorf("projeciton for %s already added", duplicateName),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
projections = tt.projections(t)
|
||||
err := Start(t.Context())
|
||||
require.Equal(t, tt.err, err)
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user