Procházet zdrojové kódy

refactor(worker): added Type() method to provider

bigeagle před 9 roky
rodič
revize
ccc31d9289

+ 4 - 0
worker/cmd_provider.go

@@ -44,6 +44,10 @@ func newCmdProvider(c cmdConfig) (*cmdProvider, error) {
 	return provider, nil
 }
 
+func (p *cmdProvider) Type() providerEnum {
+	return provCommand
+}
+
 func (p *cmdProvider) Upstream() string {
 	return p.upstreamURL
 }

+ 2 - 2
worker/provider.go

@@ -10,8 +10,6 @@ import (
 
 // mirror provider is the wrapper of mirror jobs
 
-type providerType uint8
-
 const (
 	_WorkingDirKey = "working_dir"
 	_LogDirKey     = "log_dir"
@@ -24,6 +22,8 @@ type mirrorProvider interface {
 	Name() string
 	Upstream() string
 
+	Type() providerEnum
+
 	// run mirror job in background
 	Run() error
 	// run mirror job in background

+ 3 - 0
worker/provider_test.go

@@ -33,6 +33,7 @@ func TestRsyncProvider(t *testing.T) {
 		provider, err := newRsyncProvider(c)
 		So(err, ShouldBeNil)
 
+		So(provider.Type(), ShouldEqual, provRsync)
 		So(provider.Name(), ShouldEqual, c.name)
 		So(provider.WorkingDir(), ShouldEqual, c.workingDir)
 		So(provider.LogDir(), ShouldEqual, c.logDir)
@@ -126,6 +127,7 @@ func TestCmdProvider(t *testing.T) {
 		provider, err := newCmdProvider(c)
 		So(err, ShouldBeNil)
 
+		So(provider.Type(), ShouldEqual, provCommand)
 		So(provider.Name(), ShouldEqual, c.name)
 		So(provider.WorkingDir(), ShouldEqual, c.workingDir)
 		So(provider.LogDir(), ShouldEqual, c.logDir)
@@ -218,6 +220,7 @@ func TestTwoStageRsyncProvider(t *testing.T) {
 		provider, err := newTwoStageRsyncProvider(c)
 		So(err, ShouldBeNil)
 
+		So(provider.Type(), ShouldEqual, provTwoStageRsync)
 		So(provider.Name(), ShouldEqual, c.name)
 		So(provider.WorkingDir(), ShouldEqual, c.workingDir)
 		So(provider.LogDir(), ShouldEqual, c.logDir)

+ 4 - 0
worker/rsync_provider.go

@@ -63,6 +63,10 @@ func newRsyncProvider(c rsyncConfig) (*rsyncProvider, error) {
 	return provider, nil
 }
 
+func (p *rsyncProvider) Type() providerEnum {
+	return provRsync
+}
+
 func (p *rsyncProvider) Upstream() string {
 	return p.upstreamURL
 }

+ 4 - 0
worker/two_stage_rsync_provider.go

@@ -70,6 +70,10 @@ func newTwoStageRsyncProvider(c twoStageRsyncConfig) (*twoStageRsyncProvider, er
 	return provider, nil
 }
 
+func (p *twoStageRsyncProvider) Type() providerEnum {
+	return provTwoStageRsync
+}
+
 func (p *twoStageRsyncProvider) Upstream() string {
 	return p.upstreamURL
 }