Skip to content

Commit

Permalink
Add new default params property in manipulator
Browse files Browse the repository at this point in the history
  • Loading branch information
baskarap committed Sep 18, 2019
1 parent 31f9474 commit 2826222
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/service/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 7 additions & 3 deletions pkg/service/manipulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
}
10 changes: 5 additions & 5 deletions pkg/service/manipulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import (
)

func TestNewManipulator(t *testing.T) {
m := NewManipulator(native.NewBildProcessor())
m := NewManipulator(native.NewBildProcessor(), []string{})
assert.NotNil(t, m)
}

// Integration test to verify the flow of WebP image is requested without having support of WebP on client's side
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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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)
Expand Down

0 comments on commit 2826222

Please sign in to comment.