92 lines
2.3 KiB
Go
92 lines
2.3 KiB
Go
package test
|
|
|
|
import (
|
|
"RenewCMS/internal/domain/article"
|
|
"RenewCMS/internal/domain/language"
|
|
"RenewCMS/internal/domain/localization"
|
|
"RenewCMS/internal/domain/site"
|
|
"RenewCMS/internal/domain/transaction"
|
|
"context"
|
|
"sync/atomic"
|
|
)
|
|
|
|
type mockStartingLanguages struct {
|
|
site.Repository
|
|
confirmed map[uint32]string
|
|
locked []uint32
|
|
failWith error
|
|
removed map[uint32]bool
|
|
}
|
|
|
|
var _ localization.Repository = &mockStartingLanguages{}
|
|
|
|
func (m *mockStartingLanguages) LockSite(siteID uint32) error {
|
|
m.locked = append(m.locked, siteID)
|
|
if m.failWith != nil {
|
|
return m.failWith
|
|
}
|
|
if m.removed[siteID] {
|
|
return site.ErrSiteNotFound
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (m *mockStartingLanguages) Rows(siteID uint32) ([]localization.Row, error) {
|
|
tag, confirmed := m.confirmed[siteID]
|
|
if !confirmed || tag == language.Unassigned {
|
|
return nil, nil
|
|
}
|
|
return []localization.Row{{Tag: tag, IsDefault: true, Enabled: true, Confirmed: true}}, nil
|
|
}
|
|
|
|
func (m *mockStartingLanguages) ConfirmedSites() (map[uint32]bool, error) {
|
|
return map[uint32]bool{}, nil
|
|
}
|
|
|
|
func (m *mockStartingLanguages) VersionCounts(siteID uint32) (map[string]localization.VersionCount, error) {
|
|
return map[string]localization.VersionCount{}, nil
|
|
}
|
|
|
|
func (m *mockStartingLanguages) Replace(siteID uint32, rows []localization.Row) error {
|
|
return nil
|
|
}
|
|
|
|
func (m *mockStartingLanguages) ConfirmSetup(siteID uint32, tag string) error {
|
|
return nil
|
|
}
|
|
|
|
type removableSites struct {
|
|
*mockSiteRepo
|
|
removed map[uint32]bool
|
|
}
|
|
|
|
func (r removableSites) LockSite(siteID uint32) error {
|
|
if r.removed[siteID] {
|
|
return site.ErrSiteNotFound
|
|
}
|
|
return r.mockSiteRepo.LockSite(siteID)
|
|
}
|
|
|
|
type mockCreateTransactor struct {
|
|
articles article.Repository
|
|
languages *mockStartingLanguages
|
|
runs int
|
|
}
|
|
|
|
var _ transaction.Transactor = &mockCreateTransactor{}
|
|
|
|
func (m *mockCreateTransactor) Run(ctx context.Context, work func(transaction.Repositories) error) error {
|
|
m.runs++
|
|
return work(transaction.Repositories{Articles: m.articles, Sites: m.languages, Localization: m.languages})
|
|
}
|
|
|
|
func passthroughCreateTransactor(articles article.Repository) *mockCreateTransactor {
|
|
return &mockCreateTransactor{articles: articles, languages: &mockStartingLanguages{confirmed: map[uint32]string{}}}
|
|
}
|
|
|
|
var fixtureStoryCounter atomic.Uint32
|
|
|
|
func fixtureStory() uint32 {
|
|
return 1000 + fixtureStoryCounter.Add(1)
|
|
}
|