From: Lukasz Wojciechowski Date: Thu, 30 Nov 2017 12:29:14 +0000 (+0100) Subject: Add NewJobManager function X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6735064416662aff11a1ff738f1110d62c3dd391;p=tools%2Fweles.git Add NewJobManager function NewJobManager function creates new instance of Controller with all internal submodules. The created structure is returned as JobManager interface. This is the only valid method for creation whole Controller module in Weles and should be used to create Weles service. Change-Id: I8ff2051a23f714a99fc2642c94e34d247ec164d7 Signed-off-by: Lukasz Wojciechowski --- diff --git a/controller/controller.go b/controller/controller.go index a1e5c23..59d39ba 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -24,6 +24,9 @@ package controller import ( "sync" + "time" + + "git.tizen.org/tools/boruta" "git.tizen.org/tools/weles" ) @@ -53,8 +56,23 @@ type Controller struct { looper sync.WaitGroup } +// NewJobManager creates and initializes a new instance of Controller with +// internal submodules and returns JobManager interface. +// It is the only valid way to get JobManager interface. +func NewJobManager(arm weles.ArtifactManager, yap weles.Parser, bor boruta.Requests, + borutaRefreshPeriod time.Duration, djm weles.DryadJobManager) weles.JobManager { + + js := NewJobsController() + pa := NewParser(js, arm, yap) + do := NewDownloader(js, arm) + bo := NewBoruter(js, bor, borutaRefreshPeriod) + dr := NewDryader(js, djm) + + return NewController(js, pa, do, bo, dr) +} + // NewController creates and initializes a new instance of Controller. -// It is the only valid way of Controller struct creation. +// It requires internal Controller's submodules. func NewController(js JobsController, pa Parser, do Downloader, bo Boruter, dr Dryader) *Controller { c := &Controller{ jobs: js, diff --git a/controller/controller_test.go b/controller/controller_test.go index 55f28bd..b792a95 100644 --- a/controller/controller_test.go +++ b/controller/controller_test.go @@ -19,16 +19,36 @@ package controller import ( "errors" "sync" + "time" "git.tizen.org/tools/weles" cmock "git.tizen.org/tools/weles/controller/mock" "git.tizen.org/tools/weles/controller/notifier" + mock "git.tizen.org/tools/weles/mock" gomock "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" ) +var _ = Describe("JobManager", func() { + It("should create a new object", func() { + ctrl := gomock.NewController(GinkgoT()) + + arm := mock.NewMockArtifactManager(ctrl) + yap := mock.NewMockParser(ctrl) + bor := cmock.NewMockRequests(ctrl) + djm := mock.NewMockDryadJobManager(ctrl) + + bor.EXPECT().ListRequests(nil).AnyTimes() + + jm := NewJobManager(arm, yap, bor, time.Second, djm) + Expect(jm).NotTo(BeNil()) + + ctrl.Finish() + }) +}) + var _ = Describe("Controller", func() { var ( jc *cmock.MockJobsController