Skip to content

Commit

Permalink
refactor opts (#12)
Browse files Browse the repository at this point in the history
Change-Id: I524db06a724a788cbf954a6178ce3c482f98b21c
  • Loading branch information
ycydsxy authored May 19, 2021
1 parent b4d3335 commit d3630c0
Show file tree
Hide file tree
Showing 22 changed files with 627 additions and 513 deletions.
6 changes: 3 additions & 3 deletions assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type taskAssembler interface {
}

type taskAssemblerImp struct {
config *TaskConfig
*options
}

func (s *taskAssemblerImp) AssembleTask(ctxIn context.Context, taskDef *TaskDefinition, arg interface{}) (*Task, error) {
Expand All @@ -39,7 +39,7 @@ func (s *taskAssemblerImp) AssembleTask(ctxIn context.Context, taskDef *TaskDefi
task.Argument = argBytes
}
if ctxIn != nil {
ctxBytes, err := taskDef.ctxMarshaler(s.config).MarshalCtx(ctxIn)
ctxBytes, err := taskDef.ctxMarshaler(s.ctxMarshaler).MarshalCtx(ctxIn)
if err != nil {
return nil, fmt.Errorf("get ctxBytes failed, err: %w", err)
}
Expand All @@ -50,7 +50,7 @@ func (s *taskAssemblerImp) AssembleTask(ctxIn context.Context, taskDef *TaskDefi
}

func (s *taskAssemblerImp) DisassembleTask(taskDef *TaskDefinition, task *Task) (context.Context, interface{}, error) {
ctxIn, err := taskDef.ctxMarshaler(s.config).UnmarshalCtx(task.Context)
ctxIn, err := taskDef.ctxMarshaler(s.ctxMarshaler).UnmarshalCtx(task.Context)
if err != nil {
return nil, nil, fmt.Errorf("unmarshal task context error: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions assembler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (e *testErrCtxMarshaler) UnmarshalCtx(bytes []byte) (context.Context, error

func Test_taskAssemblerImp_AssembleTask(t *testing.T) {
convey.Convey("Test_taskAssemblerImp_AssembleTask", t, func() {
tass := taskAssemblerImp{config: &TaskConfig{CtxMarshaler: &defaultCtxMarshaler{}}}
tass := taskAssemblerImp{options: &options{ctxMarshaler: &defaultCtxMarshaler{}}}
convey.Convey("normal", func() {
convey.Convey("nil arg type", func() {
task, err := tass.AssembleTask(context.TODO(), &TaskDefinition{}, nil)
Expand Down Expand Up @@ -59,7 +59,7 @@ func Test_taskAssemblerImp_AssembleTask(t *testing.T) {

func Test_taskAssemblerImp_DisassembleTask(t *testing.T) {
convey.Convey("Test_taskAssemblerImp_DisassembleTask", t, func() {
tass := taskAssemblerImp{config: &TaskConfig{CtxMarshaler: &defaultCtxMarshaler{}}}
tass := taskAssemblerImp{options: &options{ctxMarshaler: &defaultCtxMarshaler{}}}
convey.Convey("normal", func() {
convey.Convey("nil arg type", func() {
taskDef := &TaskDefinition{}
Expand Down
238 changes: 0 additions & 238 deletions config.go

This file was deleted.

52 changes: 0 additions & 52 deletions config_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions dal.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ type taskDAL interface {
}

type taskDALImp struct {
config *TaskConfig
*options
}

func (s *taskDALImp) tabledDB(tx *gorm.DB) *gorm.DB {
return tx.Table(s.config.Table)
return tx.Table(s.table)
}

func (s *taskDALImp) Create(tx *gorm.DB, task *Task) error {
Expand Down
8 changes: 4 additions & 4 deletions dal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func Test_taskDALImp_GetInitialized(t *testing.T) {
convey.Convey("Test_taskDALImp_GetInitialized", t, func() {
db := testDB("Test_taskDALImp_GetInitialized")
convey.Convey("normal", func() {
tdal := taskDALImp{config: &TaskConfig{DB: db, Table: "tasks"}}
tdal := taskDALImp{options: &options{db: db, table: "tasks"}}
convey.Convey("only has sensitive keys", func() {
convey.Convey("normal time", func() {
_ = tdal.Create(db, &Task{TaskKey: "t1", TaskStatus: TaskStatusInitialized, CreatedAt: time.Now(), UpdatedAt: time.Now()})
Expand All @@ -28,7 +28,7 @@ func Test_taskDALImp_GetInitialized(t *testing.T) {
})
})
convey.Convey("error", func() {
tdal := taskDALImp{config: &TaskConfig{DB: db, Table: "not exist"}}
tdal := taskDALImp{options: &options{db: db, table: "not exist"}}
_, err := tdal.GetInitialized(db, nil, time.Second, nil)
convey.So(err, convey.ShouldNotBeNil)
})
Expand All @@ -39,7 +39,7 @@ func Test_taskDALImp_Get(t *testing.T) {
convey.Convey("Test_taskDALImp_Get", t, func() {
convey.Convey("error", func() {
db := testDB("Test_taskDALImp_Get")
tdal := taskDALImp{config: &TaskConfig{DB: db, Table: "not exist"}}
tdal := taskDALImp{options: &options{db: db, table: "not exist"}}
_, err := tdal.Get(db, 1)
convey.So(err, convey.ShouldNotBeNil)
})
Expand All @@ -50,7 +50,7 @@ func Test_taskDALImp_GetForUpdate(t *testing.T) {
convey.Convey("Test_taskDALImp_GetForUpdate", t, func() {
convey.Convey("error", func() {
db := testDB("Test_taskDALImp_GetForUpdate")
tdal := taskDALImp{config: &TaskConfig{DB: db, Table: "not exist"}}
tdal := taskDALImp{options: &options{db: db, table: "not exist"}}
_, err := tdal.GetForUpdate(db, 1)
convey.So(err, convey.ShouldNotBeNil)
})
Expand Down
Loading

0 comments on commit d3630c0

Please sign in to comment.