More test structure and first domain service test

master
Caj Larsson 3 years ago
parent 923f1b0ca6
commit b0d4820659

@ -1,3 +0,0 @@
package domain
//import "testing"

@ -0,0 +1,30 @@
package test
import (
"testing"
"caj-larsson/bog/domain"
"caj-larsson/bog/test/mock"
)
var file_ref1 = domain.FileReference { "path1", "ua1" }
//var file_ref2 = domain.FileReference { "path1", "ua2" }
//var file_ref3 = domain.FileReference { "path2", "ua1" }
func TestFileService(t *testing.T) {
file_repo := mock.NewMockFileRepository()
ua_repo := mock.NewMockUserAgentRepository()
service := domain.NewBogFileService(ua_repo, file_repo)
outfile, err := service.OpenOutFile(file_ref1)
if outfile != nil && err != domain.ErrNotExists {
t.Errorf("File shall not exist by default")
}
}

@ -1,4 +1,4 @@
package test package mock
import ( import (
"time" "time"

@ -1,4 +1,4 @@
package test package mock
import ( import (
"testing" "testing"

@ -1,4 +1,4 @@
package test package mock
import ( import (
// "time" // "time"
@ -12,6 +12,13 @@ type MockUserAgentRepository struct {
NextId int64 NextId int64
} }
func NewMockUserAgentRepository() domain.UserAgentRepository{
r := new(MockUserAgentRepository)
r.NextId = 0
r.IdIdx = make(map[int64]*domain.UserAgent)
r.NameIdx = make(map[string]*domain.UserAgent)
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 r.NextId += 1

@ -1,4 +1,4 @@
package test package mock
import ( import (
"testing" "testing"
@ -7,10 +7,7 @@ import (
) )
func TestMockUserAgentRepo(t *testing.T) { func TestMockUserAgentRepo(t *testing.T) {
r := new(MockUserAgentRepository) r := NewMockUserAgentRepository()
r.NextId = 0
r.IdIdx = make(map[int64]*domain.UserAgent)
r.NameIdx = make(map[string]*domain.UserAgent)
all, err := r.All() all, err := r.All()

Loading…
Cancel
Save