From 282622208aafff2ae0ab386b83519ac3167c96be Mon Sep 17 00:00:00 2001 From: baskara Date: Wed, 18 Sep 2019 13:36:42 +0700 Subject: [PATCH] Add new default params property in manipulator --- pkg/service/dependencies.go | 2 +- pkg/service/manipulator.go | 10 +++++++--- pkg/service/manipulator_test.go | 10 +++++----- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/pkg/service/dependencies.go b/pkg/service/dependencies.go index 6e9dfda..ca1a6c7 100644 --- a/pkg/service/dependencies.go +++ b/pkg/service/dependencies.go @@ -25,7 +25,7 @@ type Dependencies struct { // Currently, it supports only one Manipulator func NewDependencies() *Dependencies { s := config.DataSource() - deps := &Dependencies{Manipulator: NewManipulator(native.NewBildProcessor())} + deps := &Dependencies{Manipulator: NewManipulator(native.NewBildProcessor(), []string{})} if regex.WebFolderMatcher.MatchString(s.Kind) { deps.Storage = NewWebFolderStorage(s.Value.(config.WebFolder), s.HystrixCommand) } else if regex.S3Matcher.MatchString(s.Kind) { diff --git a/pkg/service/manipulator.go b/pkg/service/manipulator.go index fc5b183..ba91fdd 100644 --- a/pkg/service/manipulator.go +++ b/pkg/service/manipulator.go @@ -46,7 +46,8 @@ type Manipulator interface { } type manipulator struct { - processor processor.Processor + processor processor.Processor + defaultParams []string } // Process takes ProcessSpec as an argument and returns []byte, error @@ -172,6 +173,9 @@ func trackDuration(name string, start time.Time, spec processSpec) *metrics.Upda } // NewManipulator takes in a Processor interface and returns a new Manipulator -func NewManipulator(processor processor.Processor) Manipulator { - return &manipulator{processor: processor} +func NewManipulator(processor processor.Processor, defaultParams []string) Manipulator { + return &manipulator{ + processor: processor, + defaultParams: defaultParams, + } } diff --git a/pkg/service/manipulator_test.go b/pkg/service/manipulator_test.go index 486141d..90516a2 100644 --- a/pkg/service/manipulator_test.go +++ b/pkg/service/manipulator_test.go @@ -15,7 +15,7 @@ import ( ) func TestNewManipulator(t *testing.T) { - m := NewManipulator(native.NewBildProcessor()) + m := NewManipulator(native.NewBildProcessor(), []string{}) assert.NotNil(t, m) } @@ -23,7 +23,7 @@ func TestNewManipulator(t *testing.T) { func TestManipulator_Process_ReturnsImageAsPNGIfCallerDoesNOTSupportWebP(t *testing.T) { // Use real processor to ensure that right encoder is being used p := native.NewBildProcessor() - m := NewManipulator(p) + m := NewManipulator(p, []string{}) img, _ := ioutil.ReadFile("../processor/native/_testdata/test.webp") expectedImg, _ := ioutil.ReadFile("../processor/native/_testdata/test_webp_to_png.png") @@ -41,7 +41,7 @@ func TestManipulator_Process_ReturnsImageAsPNGIfCallerDoesNOTSupportWebP(t *test func TestManipulator_Process_ReturnsImageAsWebPIfCallerSupportsWebP(t *testing.T) { // Use real processor to ensure that right encoder is being used p := native.NewBildProcessor() - m := NewManipulator(p) + m := NewManipulator(p, []string{}) img, _ := ioutil.ReadFile("../processor/native/_testdata/test.png") expectedImg, _ := ioutil.ReadFile("../processor/native/_testdata/test_png_to_webp.webp") @@ -58,7 +58,7 @@ func TestManipulator_Process_ReturnsImageAsWebPIfCallerSupportsWebP(t *testing.T func TestManipulator_Process(t *testing.T) { mp := &mockProcessor{} - m := NewManipulator(mp) + m := NewManipulator(mp, []string{}) params := make(map[string]string) input := []byte("inputData") @@ -71,7 +71,7 @@ func TestManipulator_Process(t *testing.T) { // Create new struct for asserting expectations mp = &mockProcessor{} - m = NewManipulator(mp) + m = NewManipulator(mp, []string{}) mp.On("Decode", input).Return(decoded, "png", nil) mp.On("Encode", decoded, "png").Return(input, nil) mp.On("Crop", decoded, 100, 100, processor.CropCenter).Return(decoded, nil)