Fix UA mock id persistance bug

master
Caj Larsson 3 years ago
parent 199d4ed6f3
commit 0a569805ea

@ -38,7 +38,7 @@ func (r SQLiteUserAgentRepository) migrate() error {
return err
}
func (r SQLiteUserAgentRepository) Create(useragent domain.UserAgent) (*domain.UserAgent, error) {
func (r *SQLiteUserAgentRepository) Create(useragent domain.UserAgent) (*domain.UserAgent, error) {
var record, err = fromEntity(useragent)
if err != nil {

@ -10,7 +10,7 @@ import (
var file_ref1 = domain.FileReference { "path1", "ua1" }
//var file_ref2 = domain.FileReference { "path1", "ua2" }
var file_ref2 = domain.FileReference { "path1", "ua2" }
var file_ref3 = domain.FileReference { "path2", "ua1" }
@ -61,7 +61,6 @@ func TestFileIsReadBack(t *testing.T) {
_ = s.SaveFile(file_ref1, infile, int64(infile.Len()))
outbogfile, _ := s.OpenOutFile(file_ref1)
outfile := bytes.NewBufferString("")
@ -71,3 +70,25 @@ func TestFileIsReadBack(t *testing.T) {
t.Errorf("file corrupted")
}
}
func TestUAIsolation(t *testing.T) {
file_repo := mock.NewMockFileRepository()
ua_repo := mock.NewMockUserAgentRepository()
s := domain.NewBogFileService(ua_repo, file_repo, 1024, time.Hour)
ua1_file := bytes.NewBufferString("My bog data ua1")
ua2_file := bytes.NewBufferString("My bog data ua2")
_ = s.SaveFile(file_ref1, ua1_file, int64(ua1_file.Len()))
_ = s.SaveFile(file_ref2, ua2_file, int64(ua2_file.Len()))
outbogfile, _ := s.OpenOutFile(file_ref1)
outfile := bytes.NewBufferString("")
_, _ = outfile.ReadFrom(outbogfile)
if outfile.String() != "My bog data ua1" {
t.Errorf("file corrupted")
}
}

@ -12,7 +12,7 @@ type MockUserAgentRepository struct {
NextId int64
}
func NewMockUserAgentRepository() domain.UserAgentRepository{
func NewMockUserAgentRepository() *MockUserAgentRepository {
r := new(MockUserAgentRepository)
r.NextId = 0
r.IdIdx = make(map[int64]*domain.UserAgent)
@ -20,7 +20,7 @@ func NewMockUserAgentRepository() domain.UserAgentRepository{
return r
}
func (r MockUserAgentRepository) Create(useragent domain.UserAgent) (*domain.UserAgent, error) {
func (r *MockUserAgentRepository) Create(useragent domain.UserAgent) (*domain.UserAgent, error) {
r.NextId += 1
useragent.ID = r.NextId
@ -30,7 +30,7 @@ func (r MockUserAgentRepository) Create(useragent domain.UserAgent) (*domain.Use
}
func (r MockUserAgentRepository) All() ([]domain.UserAgent, error) {
func (r *MockUserAgentRepository) All() ([]domain.UserAgent, error) {
v := make([]domain.UserAgent, 0, len(r.IdIdx))
for _, value := range r.IdIdx {
@ -40,7 +40,7 @@ func (r MockUserAgentRepository) All() ([]domain.UserAgent, error) {
}
func (r MockUserAgentRepository) GetByName(name string) (*domain.UserAgent, error) {
func (r *MockUserAgentRepository) GetByName(name string) (*domain.UserAgent, error) {
useragent, exists := r.NameIdx[name]
if exists {
return useragent, nil
@ -49,7 +49,7 @@ func (r MockUserAgentRepository) GetByName(name string) (*domain.UserAgent, erro
}
func (r MockUserAgentRepository) Update(id int64, useragent domain.UserAgent) (*domain.UserAgent, error) {
func (r *MockUserAgentRepository) Update(id int64, useragent domain.UserAgent) (*domain.UserAgent, error) {
original := *r.IdIdx[id]
useragent.ID = id
r.IdIdx[id] = &useragent
@ -58,7 +58,7 @@ func (r MockUserAgentRepository) Update(id int64, useragent domain.UserAgent) (*
}
func (r MockUserAgentRepository) Delete(id int64) error {
func (r *MockUserAgentRepository) Delete(id int64) error {
original := *r.IdIdx[id]
delete(r.NameIdx, original.Name)
delete(r.IdIdx, original.ID)

Loading…
Cancel
Save