diff --git a/domain/services_test.go b/domain/services_test.go deleted file mode 100644 index 18f8fa6..0000000 --- a/domain/services_test.go +++ /dev/null @@ -1,3 +0,0 @@ -package domain - -//import "testing" diff --git a/test/domain/services_test.go b/test/domain/services_test.go new file mode 100644 index 0000000..5394f98 --- /dev/null +++ b/test/domain/services_test.go @@ -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") + } + + + + +} diff --git a/test/mock/file.go b/test/mock/file.go index 8856703..b65da96 100644 --- a/test/mock/file.go +++ b/test/mock/file.go @@ -1,4 +1,4 @@ -package test +package mock import ( "time" diff --git a/test/mock/file_test.go b/test/mock/file_test.go index 2118ba0..7426641 100644 --- a/test/mock/file_test.go +++ b/test/mock/file_test.go @@ -1,4 +1,4 @@ -package test +package mock import ( "testing" diff --git a/test/mock/user_agent.go b/test/mock/user_agent.go index d8bd294..3020a49 100644 --- a/test/mock/user_agent.go +++ b/test/mock/user_agent.go @@ -1,4 +1,4 @@ -package test +package mock import ( // "time" @@ -12,6 +12,13 @@ type MockUserAgentRepository struct { 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) { r.NextId += 1 diff --git a/test/mock/user_agent_test.go b/test/mock/user_agent_test.go index ed58c99..7357626 100644 --- a/test/mock/user_agent_test.go +++ b/test/mock/user_agent_test.go @@ -1,4 +1,4 @@ -package test +package mock import ( "testing" @@ -7,10 +7,7 @@ import ( ) func TestMockUserAgentRepo(t *testing.T) { - r := new(MockUserAgentRepository) - r.NextId = 0 - r.IdIdx = make(map[int64]*domain.UserAgent) - r.NameIdx = make(map[string]*domain.UserAgent) + r := NewMockUserAgentRepository() all, err := r.All()